Class: RubyEventStore::PubSub::Broker
- Inherits:
-
Object
- Object
- RubyEventStore::PubSub::Broker
- Defined in:
- lib/ruby_event_store/pub_sub/broker.rb
Instance Method Summary collapse
- #add_global_subscriber(subscriber) ⇒ Object
- #add_subscriber(subscriber, event_types) ⇒ Object
-
#initialize ⇒ Broker
constructor
A new instance of Broker.
- #notify_subscribers(event) ⇒ Object
Constructor Details
#initialize ⇒ Broker
Returns a new instance of Broker.
5 6 7 8 |
# File 'lib/ruby_event_store/pub_sub/broker.rb', line 5 def initialize @subscribers = Hash.new {|hsh, key| hsh[key] = [] } @global_subscribers = [] end |
Instance Method Details
#add_global_subscriber(subscriber) ⇒ Object
15 16 17 18 |
# File 'lib/ruby_event_store/pub_sub/broker.rb', line 15 def add_global_subscriber(subscriber) verify_subscriber(subscriber) @global_subscribers << subscriber end |
#add_subscriber(subscriber, event_types) ⇒ Object
10 11 12 13 |
# File 'lib/ruby_event_store/pub_sub/broker.rb', line 10 def add_subscriber(subscriber, event_types) verify_subscriber(subscriber) subscribe(subscriber, event_types) end |
#notify_subscribers(event) ⇒ Object
20 21 22 23 24 |
# File 'lib/ruby_event_store/pub_sub/broker.rb', line 20 def notify_subscribers(event) all_subscribers_for(event.event_type).each do |subscriber| subscriber.handle_event(event) end end |