Class: RailsEventSourcing::Dispatcher::RuleSet
- Inherits:
-
Object
- Object
- RailsEventSourcing::Dispatcher::RuleSet
- Defined in:
- lib/rails-event-sourcing/dispatcher.rb
Instance Method Summary collapse
-
#for(event) ⇒ Object
Return a ReactorSet containing all Reactors matching an Event.
-
#initialize ⇒ RuleSet
constructor
A new instance of RuleSet.
- #register(events:, sync:, async:) ⇒ Object
Constructor Details
#initialize ⇒ RuleSet
Returns a new instance of RuleSet.
36 37 38 |
# File 'lib/rails-event-sourcing/dispatcher.rb', line 36 def initialize @rules = Hash.new { |h, k| h[k] = ReactorSet.new } end |
Instance Method Details
#for(event) ⇒ Object
Return a ReactorSet containing all Reactors matching an Event
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rails-event-sourcing/dispatcher.rb', line 48 def for(event) reactors = ReactorSet.new @rules.each do |event_class, rule| # Match event by class including ancestors. e.g. All events match a role for BaseEvent. if event.is_a?(event_class) reactors.add_sync(rule.sync) reactors.add_async(rule.async) end end reactors end |
#register(events:, sync:, async:) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rails-event-sourcing/dispatcher.rb', line 40 def register(events:, sync:, async:) events.each do |event| @rules[event].add_sync(sync) @rules[event].add_async(async) end end |