Class: Kafo::Hooking
- Inherits:
-
Object
- Object
- Kafo::Hooking
- Defined in:
- lib/kafo/hooking.rb
Instance Attribute Summary collapse
-
#hooks ⇒ Object
Returns the value of attribute hooks.
-
#kafo ⇒ Object
Returns the value of attribute kafo.
Instance Method Summary collapse
- #execute(group) ⇒ Object
-
#initialize ⇒ Hooking
constructor
A new instance of Hooking.
- #logger ⇒ Object
- #register_post(name, &block) ⇒ Object
- #register_pre(name, &block) ⇒ Object
Constructor Details
#initialize ⇒ Hooking
Returns a new instance of Hooking.
6 7 8 |
# File 'lib/kafo/hooking.rb', line 6 def initialize self.hooks = Hash.new { |h, k| h[k] = {} } end |
Instance Attribute Details
#hooks ⇒ Object
Returns the value of attribute hooks.
4 5 6 |
# File 'lib/kafo/hooking.rb', line 4 def hooks @hooks end |
#kafo ⇒ Object
Returns the value of attribute kafo.
4 5 6 |
# File 'lib/kafo/hooking.rb', line 4 def kafo @kafo end |
Instance Method Details
#execute(group) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/kafo/hooking.rb', line 14 def execute(group) logger.info "Executing hooks in group #{group}" self.hooks[group].each_pair do |name, hook| result = hook.call(kafo) logger.debug "Hook #{name} returned #{result.inspect}" end logger.info "All hooks in group #{group} finished" end |
#logger ⇒ Object
10 11 12 |
# File 'lib/kafo/hooking.rb', line 10 def logger KafoConfigure.logger end |
#register_post(name, &block) ⇒ Object
27 28 29 |
# File 'lib/kafo/hooking.rb', line 27 def register_post(name, &block) register(:post, name, &block) end |
#register_pre(name, &block) ⇒ Object
23 24 25 |
# File 'lib/kafo/hooking.rb', line 23 def register_pre(name, &block) register(:pre, name, &block) end |