Class: Junkfood::Ceb::Executors::CommandExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/junkfood/ceb/executors/command_executor.rb

Overview

Processes the command from the command_bus. The command is saved, then its perform method is executed.

Instance Method Summary collapse

Instance Method Details

#call(command) ⇒ Object

Parameters:

  • command (BaseCommand)

    the command to save and perform.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/junkfood/ceb/executors/command_executor.rb', line 29

def call(command)
  # We need to raise an error here if we can't save.
  # But we only save if it's a new record.
  # Junction asserted that command was valid before calling this
  # executor, thus any errors in saving probably have to do with
  # connectivity... we want to abort.
  command.save! if command.new_record?
  # We assume that the command will catch all of its problems and
  # publish error events?
  # TODO: should wrap this up and publish a generic CommandFailedEvent.
  return command.perform
end