class HecksApplication::CommandRunner
Run an application command, with validations and broacast lifecycle events
Attributes
application[R]
args[R]
async[R]
command[R]
command_name[R]
domain_spec[R]
module_name[R]
Public Class Methods
new(command_name:, module_name:, args:, application:, async: false)
click to toggle source
# File lib/command_runner.rb, line 8 def initialize(command_name:, module_name:, args:, application:, async: false) @command_name = command_name @module_name = module_name @args = args @application = application @domain_spec = application.domain_spec @async = async end
Public Instance Methods
call()
click to toggle source
# File lib/command_runner.rb, line 17 def call() fetch_command run_command broadcast command end
Private Instance Methods
broadcast()
click to toggle source
# File lib/command_runner.rb, line 28 def broadcast application.events_port.send(command: command, module_name: module_name) end
fetch_command()
click to toggle source
# File lib/command_runner.rb, line 32 def fetch_command args.merge!(id: SecureRandom.uuid) if command_name == :create @command = Commands.const_get(command_name.to_s.camelcase).new( repository: application.database[module_name], args: args, domain_module: fetch_module ) end
fetch_module()
click to toggle source
# File lib/command_runner.rb, line 41 def fetch_module domain_spec.domain_modules[module_name.to_s.camelize.to_sym] end
run_command()
click to toggle source
# File lib/command_runner.rb, line 45 def run_command if async Thread::new { command.call } else command.call end command end