class RailsEventSourcing::Dispatcher::RuleSet
Public Class Methods
new()
click to toggle source
# File lib/rails-event-sourcing/dispatcher.rb, line 36 def initialize @rules = Hash.new { |h, k| h[k] = ReactorSet.new } end
Public Instance Methods
for(event)
click to toggle source
Return a ReactorSet
containing all Reactors matching an Event
# 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:)
click to toggle source
# 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