Class: RawLine::EventRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/rawline/event_registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(&blk) ⇒ EventRegistry

Returns a new instance of EventRegistry.



3
4
5
6
# File 'lib/rawline/event_registry.rb', line 3

def initialize(&blk)
  @subscribers = Hash.new{ |h,k| h[k.to_sym] = [] }
  blk.call(self) if block_given?
end

Instance Method Details

#subscribe(event_name, *subscribers, &blk) ⇒ Object



8
9
10
11
# File 'lib/rawline/event_registry.rb', line 8

def subscribe(event_name, *subscribers, &blk)
  subscribers << blk if block_given?
  @subscribers[event_name.to_sym].concat(subscribers)
end

#subscribers_for_event(event_name) ⇒ Object



13
14
15
# File 'lib/rawline/event_registry.rb', line 13

def subscribers_for_event(event_name)
  @subscribers[event_name.to_sym]
end