Class: Onfire::EventTable
- Inherits:
-
Object
- Object
- Onfire::EventTable
- Defined in:
- lib/onfire/event_table.rb
Overview
Keeps all event handlers attached to one object.
Instance Attribute Summary collapse
-
#source2evt ⇒ Object
Returns the value of attribute source2evt.
Instance Method Summary collapse
- #add_handler(handler, opts) ⇒ Object
-
#all_handlers_for(event_type, source_name) ⇒ Object
Returns all handlers, with :from first, then catch-all.
- #handlers_for(event_type, source_name = nil) ⇒ Object
-
#initialize ⇒ EventTable
constructor
A new instance of EventTable.
Constructor Details
#initialize ⇒ EventTable
Returns a new instance of EventTable.
6 7 8 |
# File 'lib/onfire/event_table.rb', line 6 def initialize @source2evt = {} end |
Instance Attribute Details
#source2evt ⇒ Object
Returns the value of attribute source2evt.
4 5 6 |
# File 'lib/onfire/event_table.rb', line 4 def source2evt @source2evt end |
Instance Method Details
#add_handler(handler, opts) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/onfire/event_table.rb', line 10 def add_handler(handler, opts) event_type = opts[:event_type] source_name = opts[:from] || nil handlers_for(event_type, source_name) << handler end |
#all_handlers_for(event_type, source_name) ⇒ Object
Returns all handlers, with :from first, then catch-all.
23 24 25 |
# File 'lib/onfire/event_table.rb', line 23 def all_handlers_for(event_type, source_name) handlers_for(event_type, source_name) + handlers_for(event_type, nil) end |
#handlers_for(event_type, source_name = nil) ⇒ Object
17 18 19 20 |
# File 'lib/onfire/event_table.rb', line 17 def handlers_for(event_type, source_name=nil) evt_types = source2evt[source_name] ||= {} evt_types[event_type] ||= [] end |