Module: CampingHooks::ClassMethods
- Defined in:
- lib/tarpaulin/camping/filter.rb
Instance Method Summary collapse
- #get_hooks ⇒ Object
- #hook(hook_pair, &block) ⇒ Object
- #set_hook_key(k) ⇒ Object
- #set_hook_value(k, v) ⇒ Object
Instance Method Details
#get_hooks ⇒ Object
17 18 19 |
# File 'lib/tarpaulin/camping/filter.rb', line 17 def get_hooks @hooks ||= {} end |
#hook(hook_pair, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tarpaulin/camping/filter.rb', line 21 def hook(hook_pair, &block) hook_sym = hook_pair.keys.first hook_actions = hook_pair.values.first instance_eval <<-EOT def #{hook_sym}(actions, &block) actions = [actions] unless actions.respond_to?(:each) actions.each do |action| set_hook_value(:#{hook_sym}, [action, block]) end end EOT send(hook_sym, hook_actions, &block) end |
#set_hook_key(k) ⇒ Object
7 8 9 10 |
# File 'lib/tarpaulin/camping/filter.rb', line 7 def set_hook_key(k) @hooks ||= {} @hooks[k] ||= [] end |
#set_hook_value(k, v) ⇒ Object
12 13 14 15 |
# File 'lib/tarpaulin/camping/filter.rb', line 12 def set_hook_value(k, v) set_hook_key(k) @hooks[k] << v end |