Class: Kafo::Hooking

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/hooking.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHooking

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

#hooksObject

Returns the value of attribute hooks.



4
5
6
# File 'lib/kafo/hooking.rb', line 4

def hooks
  @hooks
end

#kafoObject

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

#loggerObject



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