Class: Aggregates::CommandDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/aggregates/command_dispatcher.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(command_processors, command_filters) ⇒ CommandDispatcher

Returns a new instance of CommandDispatcher.



8
9
10
11
# File 'lib/aggregates/command_dispatcher.rb', line 8

def initialize(command_processors, command_filters)
  @command_processors = command_processors
  @command_filters = command_filters
end

Instance Method Details

#execute_command(execution) ⇒ Object

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.



15
16
17
18
19
20
# File 'lib/aggregates/command_dispatcher.rb', line 15

def execute_command(execution)
  return false unless should_process? execution

  send_to_processors(execution)
  true
end