class RubyEventStore::CorrelatedCommands
Attributes
command_bus[R]
event_store[R]
Public Class Methods
new(event_store, command_bus)
click to toggle source
# File lib/ruby_event_store/correlated_commands.rb, line 5 def initialize(event_store, command_bus) @event_store = event_store @command_bus = command_bus end
Public Instance Methods
call(command)
click to toggle source
# File lib/ruby_event_store/correlated_commands.rb, line 13 def call(command) correlation_id = event_store.metadata[:correlation_id] causation_id = event_store.metadata[:causation_id] if correlation_id && causation_id command.correlate_with(MiniEvent.new(correlation_id, causation_id)) if command.respond_to?(:correlate_with) event_store.with_metadata(causation_id: command.message_id) { command_bus.call(command) } else event_store.with_metadata(correlation_id: command.message_id, causation_id: command.message_id) do command_bus.call(command) end end end