Module: Synapse::Command::WiringCommandHandler
- Extended by:
- ActiveSupport::Concern
- Includes:
- CommandHandler, Wiring::MessageWiring
- Defined in:
- lib/synapse/command/wiring.rb
Overview
Mixin for a command handler that wishes to use the wiring DSL
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 wired.
-
#unsubscribe(command_bus) ⇒ undefined
Unsubscribes this handler from the given command bus for any types that have been wired.
Instance Method Details
#handle(command, current_unit) ⇒ Object
Returns The result of handling the given command.
16 17 18 19 20 21 22 23 24 |
# File 'lib/synapse/command/wiring.rb', line 16 def handle(command, current_unit) wire = wire_registry.wire_for command.payload_type unless wire raise ArgumentError, 'Not capable of handling [%s] commands' % command.payload_type end invoke_wire command, wire end |
#subscribe(command_bus) ⇒ undefined
Subscribes this handler to the given command bus for any types that have been wired
30 31 32 33 34 |
# File 'lib/synapse/command/wiring.rb', line 30 def subscribe(command_bus) self.wire_registry.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 wired
40 41 42 43 44 |
# File 'lib/synapse/command/wiring.rb', line 40 def unsubscribe(command_bus) self.wire_registry.each_type do |type| command_bus.unsubscribe type, self end end |