Module: VagrantGitHooks::Service
- Defined in:
- lib/vagrant-git-hooks/service.rb
Class Method Summary collapse
- .adopt_source(cfg, root, entries) ⇒ Object
-
.entries_from_config(cfg, root) ⇒ Array<Hash>
Builds installable hook entries from direct config and an optional source directory.
-
.install!(root:, cfg:, ui: nil, dry_run: false) ⇒ Hash
Installs or updates hooks for a Git repository.
- .installer_for(root, ui: nil) ⇒ Object
-
.status(root:, cfg:) ⇒ Array<Hash>
Reports hook installation status for configured and previously managed hooks.
-
.uninstall!(root:, ui: nil, dry_run: false) ⇒ Hash
Removes managed hooks and restores backed-up foreign hooks.
Class Method Details
.adopt_source(cfg, root, entries) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vagrant-git-hooks/service.rb', line 28 def adopt_source(cfg, root, entries) # Explicit Vagrantfile hooks win over hooks_source files with the same name. src = cfg.hooks_source.to_s.strip return if src.empty? dir = File.absolute_path?(src) ? src : File.(src, root.to_s) return unless File.directory?(dir) Dir.children(dir).sort.each do |fname| next unless Config::KNOWN_HOOKS.include?(fname) path = File.join(dir, fname) next unless File.file?(path) next if entries.key?(fname) entries[fname] = { name: fname, content: File.read(path) } end end |
.entries_from_config(cfg, root) ⇒ Array<Hash>
Builds installable hook entries from direct config and an optional source directory.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vagrant-git-hooks/service.rb', line 17 def entries_from_config(cfg, root) entries = {} (cfg.hooks || {}).each do |name, cmd| entries[name.to_s] = { name: name.to_s, commands: cmd } end adopt_source(cfg, root, entries) entries.values end |
.install!(root:, cfg:, ui: nil, dry_run: false) ⇒ Hash
Installs or updates hooks for a Git repository.
62 63 64 65 66 67 68 |
# File 'lib/vagrant-git-hooks/service.rb', line 62 def install!(root:, cfg:, ui: nil, dry_run: false) installer_for(root, ui: ui).install( entries_from_config(cfg, root), fail_on_error: cfg.fail_on_error, dry_run: dry_run ) end |
.installer_for(root, ui: nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/vagrant-git-hooks/service.rb', line 47 def installer_for(root, ui: nil) Util::Installer.new( hooks_dir: Util::Git.hooks_dir(root), manifest: Util::Manifest.new(Util::Git.manifest_path(root)), ui: ui ) end |
.status(root:, cfg:) ⇒ Array<Hash>
Reports hook installation status for configured and previously managed hooks.
85 86 87 88 |
# File 'lib/vagrant-git-hooks/service.rb', line 85 def status(root:, cfg:) configured = entries_from_config(cfg, root).map { |e| e[:name].to_s } installer_for(root).status(configured) end |
.uninstall!(root:, ui: nil, dry_run: false) ⇒ Hash
Removes managed hooks and restores backed-up foreign hooks.
76 77 78 |
# File 'lib/vagrant-git-hooks/service.rb', line 76 def uninstall!(root:, ui: nil, dry_run: false) installer_for(root, ui: ui).uninstall(dry_run: dry_run) end |