Class: Forger::Hook
- Inherits:
-
Object
- Object
- Forger::Hook
- Defined in:
- lib/forger/hook.rb
Class Method Summary collapse
Instance Method Summary collapse
- #hooks ⇒ Object
-
#initialize(options = {}) ⇒ Hook
constructor
A new instance of Hook.
- #run(name) ⇒ Object
- #sh(command) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Hook
Returns a new instance of Hook.
5 6 7 |
# File 'lib/forger/hook.rb', line 5 def initialize(={}) @options = end |
Class Method Details
Instance Method Details
#hooks ⇒ Object
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 |