Class: RubyEventStore::Broker

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/broker.rb

Instance Method Summary collapse

Constructor Details

#initialize(subscriptions:, dispatcher:) ⇒ Broker

Returns a new instance of Broker.


5
6
7
8
# File 'lib/ruby_event_store/broker.rb', line 5

def initialize(subscriptions:, dispatcher:)
  @subscriptions = subscriptions
  @dispatcher = dispatcher
end

Instance Method Details

#add_global_subscription(subscriber) ⇒ Object


22
23
24
25
# File 'lib/ruby_event_store/broker.rb', line 22

def add_global_subscription(subscriber)
  verify_subscription(subscriber)
  subscriptions.add_global_subscription(subscriber)
end

#add_subscription(subscriber, event_types) ⇒ Object


17
18
19
20
# File 'lib/ruby_event_store/broker.rb', line 17

def add_subscription(subscriber, event_types)
  verify_subscription(subscriber)
  subscriptions.add_subscription(subscriber, event_types)
end

#add_thread_global_subscription(subscriber) ⇒ Object


32
33
34
35
# File 'lib/ruby_event_store/broker.rb', line 32

def add_thread_global_subscription(subscriber)
  verify_subscription(subscriber)
  subscriptions.add_thread_global_subscription(subscriber)
end

#add_thread_subscription(subscriber, event_types) ⇒ Object


27
28
29
30
# File 'lib/ruby_event_store/broker.rb', line 27

def add_thread_subscription(subscriber, event_types)
  verify_subscription(subscriber)
  subscriptions.add_thread_subscription(subscriber, event_types)
end

#call(event, record) ⇒ Object


10
11
12
13
14
15
# File 'lib/ruby_event_store/broker.rb', line 10

def call(event, record)
  subscribers = subscriptions.all_for(event.event_type)
  subscribers.each do |subscriber|
    dispatcher.call(subscriber, event, record)
  end
end