Class: Rohbau::EventTube::SubscriptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rohbau/event_tube.rb

Instance Method Summary collapse

Constructor Details

#initializeSubscriptionHandler

Returns a new instance of SubscriptionHandler.



19
20
21
22
23
# File 'lib/rohbau/event_tube.rb', line 19

def initialize
  @subscriptions = Hash.new do |h,k|
    h[k] = []
  end
end

Instance Method Details

#add(name, &handler) ⇒ Object



25
26
27
28
# File 'lib/rohbau/event_tube.rb', line 25

def add(name, &handler)
  subscriptions[name] << handler
  true
end

#handle(name, event) ⇒ Object



30
31
32
33
34
35
# File 'lib/rohbau/event_tube.rb', line 30

def handle(name, event)
  subscriptions[name].each do |handler|
    handler.call(event)
  end
  true
end