Module: Runbook::Hooks
- Included in:
- Run::ClassMethods, View::ClassMethods
- Defined in:
- lib/runbook/hooks.rb
Defined Under Namespace
Modules: Invoker
Instance Method Summary collapse
- #_hook_index(hook_name) ⇒ Object
- #hooks ⇒ Object
- #hooks_for(type, klass) ⇒ Object
- #register_hook(name, type, klass, before: nil, &block) ⇒ Object
Instance Method Details
#_hook_index(hook_name) ⇒ Object
28 29 30 |
# File 'lib/runbook/hooks.rb', line 28 def _hook_index(hook_name) hooks.index { |hook| hook[:name] == hook_name } || -1 end |
#hooks ⇒ Object
3 4 5 |
# File 'lib/runbook/hooks.rb', line 3 def hooks @hooks ||= [] end |
#hooks_for(type, klass) ⇒ Object
22 23 24 25 26 |
# File 'lib/runbook/hooks.rb', line 22 def hooks_for(type, klass) hooks.select do |hook| hook[:type] == type && klass <= hook[:klass] end end |
#register_hook(name, type, klass, before: nil, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/runbook/hooks.rb', line 7 def register_hook(name, type, klass, before: nil, &block) hook = { name: name, type: type, klass: klass, block: block, } if before hooks.insert(_hook_index(before), hook) else hooks << hook end end |