Class: Pageflow::Hooks
- Inherits:
-
Object
- Object
- Pageflow::Hooks
- Defined in:
- lib/pageflow/hooks.rb
Instance Method Summary collapse
-
#initialize ⇒ Hooks
constructor
A new instance of Hooks.
- #invoke(event, *args) ⇒ Object
- #on(event, subscriber) ⇒ Object
Constructor Details
#initialize ⇒ Hooks
Returns a new instance of Hooks.
3 4 5 6 7 |
# File 'lib/pageflow/hooks.rb', line 3 def initialize @subscribers = Hash.new do |hash, key| hash[key] = [] end end |
Instance Method Details
#invoke(event, *args) ⇒ Object
13 14 15 16 17 |
# File 'lib/pageflow/hooks.rb', line 13 def invoke(event, *args) @subscribers[event].each do |subscriber| subscriber.call(*args) end end |
#on(event, subscriber) ⇒ Object
9 10 11 |
# File 'lib/pageflow/hooks.rb', line 9 def on(event, subscriber) @subscribers[event] << subscriber end |