Class: Forger::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/forger/hook.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Hook

Returns a new instance of Hook.



5
6
7
# File 'lib/forger/hook.rb', line 5

def initialize(options={})
  @options = options
end

Class Method Details

.run(name, options = {}) ⇒ Object



29
30
31
# File 'lib/forger/hook.rb', line 29

def self.run(name, options={})
  Hook.new(options).run(name.to_s)
end

Instance Method Details

#hooksObject



17
18
19
20
21
# File 'lib/forger/hook.rb', line 17

def hooks
  hooks_path = "#{Forger.root}/config/hooks.yml"
  data = File.exist?(hooks_path) ? YAML.load_file(hooks_path) : {}
  data ? data : {} # in case the file is empty
end

#run(name) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/forger/hook.rb', line 9

def run(name)
  return if @options[:noop]
  return unless hooks[name]
  command = hooks[name]
  puts "Running hook #{name}: #{command}"
  sh(command)
end

#sh(command) ⇒ Object



23
24
25
26
27
# File 'lib/forger/hook.rb', line 23

def sh(command)
  puts "=> #{command}".color(:green)
  success = system(command)
  abort("Command failed") unless success
end