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

Instance Method Details

#handle(command, current_unit) ⇒ Object

Returns The result of handling the given command.

Parameters:

Returns:

  • (Object)

    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

Parameters:

Returns:

  • (undefined)


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

Parameters:

Returns:

  • (undefined)


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