class Aggregates::CommandDispatcher
The CommandDispatcher
is effectively a router of incoming commands to CommandProcessors that are responsible for handling them appropriately. By convention, you likely will not need to interact with it directly, instead simply call Aggregates.process_command or Aggregates.process_commands.
Public Class Methods
new(command_processors, command_filters)
click to toggle source
# File lib/aggregates/command_dispatcher.rb, line 8 def initialize(command_processors, command_filters) @command_processors = command_processors @command_filters = command_filters end
Public Instance Methods
execute_command(execution)
click to toggle source
Takes a single command and processes it. The command will be validated through it's contract, sent to command processors and finally stored with the configured StorageBackend
used for messages.
# File lib/aggregates/command_dispatcher.rb, line 15 def execute_command(execution) return false unless should_process? execution send_to_processors(execution) true end
Private Instance Methods
send_to_processors(execution)
click to toggle source
# File lib/aggregates/command_dispatcher.rb, line 32 def send_to_processors(execution) @command_processors.each do |command_processor| command_processor.process(execution) end end
should_process?(execution)
click to toggle source
# File lib/aggregates/command_dispatcher.rb, line 24 def should_process?(execution) # Each command processor is going to give a true/false value for itself. # So if they all allow it, then we can return true. Else false. @command_filters.all? do |command_filter| command_filter.allow?(execution) end end