Class: Ghundle::Command::ListInstalled

Inherits:
Common
  • Object
show all
Defined in:
lib/ghundle/command/list_installed.rb

Overview

Lists all hooks installed in the current repo.

Instance Attribute Summary

Attributes inherited from Common

#args

Instance Method Summary collapse

Methods inherited from Common

call, #initialize

Constructor Details

This class inherits a constructor from Ghundle::Command::Common

Instance Method Details

#callObject



9
10
11
# File 'lib/ghundle/command/list_installed.rb', line 9

def call
  puts output.strip
end

#outputObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ghundle/command/list_installed.rb', line 13

def output
  hook_names = Set.new

  Dir['.git/hooks/*'].each do |filename|
    File.open(filename) do |f|
      f.each_line do |line|
        if line =~ /^ghundle run (.*) \$\*/
          hook_names << $1.strip
        end
      end
    end
  end

  hook_names.sort.map do |hook_name|
    source = Source::Local.new(config.hook_path(hook_name))

    if source.exists?
      hook_description(Hook.new(source))
    else
      "Warning: Hook `#{hook_name}` does not exist".foreground(:red)
    end
  end.join("\n")
end