Module: Synapse::Command::MappingCommandHandler
- Extended by:
- ActiveSupport::Concern
- Includes:
- CommandHandler
- Defined in:
- lib/synapse/command/mapping.rb
Overview
Mixin for a command handler that uses the mapping DSL
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#handle(command, current_unit) ⇒ Object
The result of handling the given command.
-
#subscribe(command_bus) ⇒ undefined
Subscribes this handler to the given command bus for any types that have been mapped.
-
#unsubscribe(command_bus) ⇒ undefined
Unsubscribes this handler from the given command bus for any types that have been mapped.
Instance Method Details
#handle(command, current_unit) ⇒ Object
Returns The result of handling the given command.
40 41 42 43 44 45 46 47 48 |
# File 'lib/synapse/command/mapping.rb', line 40 def handle(command, current_unit) mapping = command_mapper.mapping_for command.payload_type unless mapping raise ArgumentError, 'Not capable of handling [%s] commands' % command.payload_type end mapping.invoke self, command.payload, command, current_unit end |
#subscribe(command_bus) ⇒ undefined
Subscribes this handler to the given command bus for any types that have been mapped
54 55 56 57 58 |
# File 'lib/synapse/command/mapping.rb', line 54 def subscribe(command_bus) command_mapper.each_type do |type| command_bus.subscribe type, self end end |
#unsubscribe(command_bus) ⇒ undefined
Unsubscribes this handler from the given command bus for any types that have been mapped
64 65 66 67 68 |
# File 'lib/synapse/command/mapping.rb', line 64 def unsubscribe(command_bus) command_mapper.each_type do |type| command_bus.unsubscribe type, self end end |