Class: EventSourcing::Event::Publisher
- Inherits:
-
Concurrent::Actor::RestartingContext
- Object
- Concurrent::Actor::RestartingContext
- EventSourcing::Event::Publisher
- Defined in:
- lib/event_sourcing/event/publisher.rb,
lib/event_sourcing/event/publisher/reference.rb
Defined Under Namespace
Classes: Reference
Class Attribute Summary collapse
-
.subscribers ⇒ Object
readonly
Returns the value of attribute subscribers.
Class Method Summary collapse
Instance Method Summary collapse
- #default_reference_class ⇒ Object
-
#initialize ⇒ Publisher
constructor
A new instance of Publisher.
- #on_message(event) ⇒ Object
Constructor Details
#initialize ⇒ Publisher
Returns a new instance of Publisher.
20 21 22 23 24 25 |
# File 'lib/event_sourcing/event/publisher.rb', line 20 def initialize @subscribed_actors = {} self.class.subscribers.each do |event,subscribers| @subscribed_actors[event] = subscribers.map { |s| actor_for(s) } end end |
Class Attribute Details
.subscribers ⇒ Object (readonly)
Returns the value of attribute subscribers.
12 13 14 |
# File 'lib/event_sourcing/event/publisher.rb', line 12 def subscribers @subscribers end |
Class Method Details
.subscribe(klass, event) ⇒ Object
14 15 16 17 |
# File 'lib/event_sourcing/event/publisher.rb', line 14 def subscribe(klass, event) @subscribers[event.to_s] ||= [] @subscribers[event.to_s] << klass end |
Instance Method Details
#default_reference_class ⇒ Object
33 34 35 |
# File 'lib/event_sourcing/event/publisher.rb', line 33 def default_reference_class Reference end |
#on_message(event) ⇒ Object
27 28 29 30 31 |
# File 'lib/event_sourcing/event/publisher.rb', line 27 def (event) subscribers_for(event).each do |subscriber| subscriber.tell(event) # TODO: Add support for some kind of ACK + recovery end end |