Class: Lieutenant::EventBus::InMemory
- Inherits:
-
Object
- Object
- Lieutenant::EventBus::InMemory
- Defined in:
- lib/lieutenant/event_bus/in_memory.rb
Overview
Memory implementation of the event bus. Publishes and notifies on the same memory space.
Instance Method Summary collapse
-
#initialize ⇒ InMemory
constructor
A new instance of InMemory.
- #publish(event) ⇒ Object
- #subscribe(*event_classes, &handler) ⇒ Object
Constructor Details
#initialize ⇒ InMemory
7 8 9 |
# File 'lib/lieutenant/event_bus/in_memory.rb', line 7 def initialize @handlers = Hash.new { [] } end |
Instance Method Details
#publish(event) ⇒ Object
17 18 19 20 21 |
# File 'lib/lieutenant/event_bus/in_memory.rb', line 17 def publish(event) block = CALL_HANDLER_WITH_EVENT[event] handlers[:all].each(&block) handlers[event.class].each(&block) end |
#subscribe(*event_classes, &handler) ⇒ Object
11 12 13 14 15 |
# File 'lib/lieutenant/event_bus/in_memory.rb', line 11 def subscribe(*event_classes, &handler) event_classes.each do |event_class| handlers[event_class] = handlers[event_class].push(handler) end end |