Class: RubyEventStore::Broker
- Inherits:
-
Object
- Object
- RubyEventStore::Broker
- Defined in:
- lib/ruby_event_store/broker.rb
Instance Method Summary collapse
- #add_global_subscription(subscriber) ⇒ Object
- #add_subscription(subscriber, event_types) ⇒ Object
- #add_thread_global_subscription(subscriber) ⇒ Object
- #add_thread_subscription(subscriber, event_types) ⇒ Object
- #call(event, record) ⇒ Object
-
#initialize(subscriptions:, dispatcher:) ⇒ Broker
constructor
A new instance of Broker.
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
20 21 22 23 |
# File 'lib/ruby_event_store/broker.rb', line 20 def add_global_subscription(subscriber) verify_subscription(subscriber) subscriptions.add_global_subscription(subscriber) end |
#add_subscription(subscriber, event_types) ⇒ Object
15 16 17 18 |
# File 'lib/ruby_event_store/broker.rb', line 15 def add_subscription(subscriber, event_types) verify_subscription(subscriber) subscriptions.add_subscription(subscriber, event_types) end |
#add_thread_global_subscription(subscriber) ⇒ Object
30 31 32 33 |
# File 'lib/ruby_event_store/broker.rb', line 30 def add_thread_global_subscription(subscriber) verify_subscription(subscriber) subscriptions.add_thread_global_subscription(subscriber) end |
#add_thread_subscription(subscriber, event_types) ⇒ Object
25 26 27 28 |
# File 'lib/ruby_event_store/broker.rb', line 25 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 |
# File 'lib/ruby_event_store/broker.rb', line 10 def call(event, record) subscribers = subscriptions.all_for(event.event_type) subscribers.each { |subscriber| dispatcher.call(subscriber, event, record) } end |