Class: Pageflow::Hooks

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/hooks.rb

Instance Method Summary collapse

Constructor Details

#initializeHooks

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