Class: Lieutenant::EventBus::InMemory

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeInMemory



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