Class: Aruba::Hooks
- Inherits:
-
Object
- Object
- Aruba::Hooks
- Defined in:
- lib/aruba/hooks.rb
Overview
Aruba Hooks
Instance Method Summary collapse
-
#append(label, block) ⇒ Object
Add new hook.
-
#execute(label, context, *args) ⇒ Object
Run hook.
-
#exist?(label) ⇒ Boolean
Check if hook exist.
-
#initialize ⇒ Hooks
constructor
Create store.
Constructor Details
#initialize ⇒ Hooks
Create store
12 13 14 |
# File 'lib/aruba/hooks.rb', line 12 def initialize @store = {} end |
Instance Method Details
#append(label, block) ⇒ Object
Add new hook
23 24 25 26 27 28 |
# File 'lib/aruba/hooks.rb', line 23 def append(label, block) unless store.key?(label.to_sym) && store[label.to_sym].respond_to?(:<<) store[label.to_sym] = [] end store[label.to_sym] << block end |
#execute(label, context, *args) ⇒ Object
Run hook
40 41 42 43 44 |
# File 'lib/aruba/hooks.rb', line 40 def execute(label, context, *args) Array(store[label.to_sym]).each do |block| context.instance_exec(*args, &block) end end |
#exist?(label) ⇒ Boolean
Check if hook exist
50 51 52 |
# File 'lib/aruba/hooks.rb', line 50 def exist?(label) store.key? label.to_sym end |