Class: Rohbau::EventTube::SubscriptionHandler
- Inherits:
-
Object
- Object
- Rohbau::EventTube::SubscriptionHandler
- Defined in:
- lib/rohbau/event_tube.rb
Instance Method Summary collapse
- #add(name, &handler) ⇒ Object
- #handle(name, event) ⇒ Object
-
#initialize ⇒ SubscriptionHandler
constructor
A new instance of SubscriptionHandler.
Constructor Details
#initialize ⇒ SubscriptionHandler
Returns a new instance of SubscriptionHandler.
20 21 22 23 24 |
# File 'lib/rohbau/event_tube.rb', line 20 def initialize @subscriptions = Hash.new do |h, k| h[k] = [] end end |
Instance Method Details
#add(name, &handler) ⇒ Object
26 27 28 29 |
# File 'lib/rohbau/event_tube.rb', line 26 def add(name, &handler) subscriptions[name] << handler true end |
#handle(name, event) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/rohbau/event_tube.rb', line 31 def handle(name, event) subscriptions[name].each do |handler| handler.call(event) end true end |