Class: Aggregates::CommandDispatcher
- Inherits:
-
Object
- Object
- Aggregates::CommandDispatcher
- Includes:
- Singleton
- 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
-
#initialize ⇒ CommandDispatcher
constructor
A new instance of CommandDispatcher.
-
#process_command(command) ⇒ Object
Takes a single command and processes it.
-
#process_commands(*commands) ⇒ Object
Takes a sequence of commands and executes them one at a time.
Constructor Details
#initialize ⇒ CommandDispatcher
12 13 14 |
# File 'lib/aggregates/command_dispatcher.rb', line 12 def initialize @config = Configuration.instance end |
Instance Method Details
#process_command(command) ⇒ 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.
25 26 27 28 29 30 31 |
# File 'lib/aggregates/command_dispatcher.rb', line 25 def process_command(command) command.validate! return unless should_process? command send_to_processors command store command end |
#process_commands(*commands) ⇒ Object
Takes a sequence of commands and executes them one at a time.
17 18 19 20 21 |
# File 'lib/aggregates/command_dispatcher.rb', line 17 def process_commands(*commands) commands.each do |command| process_command command end end |