Module: Hooks
- Included in:
- Rage::Configuration
- Defined in:
- lib/rage/hooks.rb
Instance Method Summary collapse
- #hooks ⇒ Object
- #push_hook(callback, hook_family) ⇒ Object
- #run_hooks_for!(hook_family, context = nil) ⇒ Object
Instance Method Details
#hooks ⇒ Object
4 5 6 |
# File 'lib/rage/hooks.rb', line 4 def hooks @hooks ||= Hash.new { |h, k| h[k] = [] } end |
#push_hook(callback, hook_family) ⇒ Object
8 9 10 |
# File 'lib/rage/hooks.rb', line 8 def push_hook(callback, hook_family) hooks[hook_family] << callback if callback.is_a?(Proc) end |
#run_hooks_for!(hook_family, context = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rage/hooks.rb', line 12 def run_hooks_for!(hook_family, context = nil) hooks[hook_family].each do |callback| if context context.instance_exec(&callback) else callback.call end end @hooks[hook_family] = [] true end |