class HecksApp::ApplicationPort::CommandRunner

Attributes

runnable[R]

Public Class Methods

new(runnable) click to toggle source
# File lib/application_port/command_runner.rb, line 6
def initialize(runnable)
  @runnable =
    case runnable
    when Symbol
      ApplicationPort.domain::Domain
        .const_get(runnable)::Root
    when Hash
      ApplicationPort.domain::Domain
        .const_get(runnable.keys.first)
        .const_get(runnable.values.first)
    else
      runnable
    end
end

Public Instance Methods

method_missing(name, *args, &block) click to toggle source
# File lib/application_port/command_runner.rb, line 21
def method_missing(name, *args, &block)
  run(name, args, &block)
end
run(name, args) { |event(domain_event: domain_event)| ... } click to toggle source
# File lib/application_port/command_runner.rb, line 25
def run(name, args, &block)
  @runnable.send(name, *args) do |domain_event|
    yield(Event.new(domain_event: domain_event)) if block
  end
rescue ApplicationPort.domain::InvariantViolationError => e
  yield(Event.new(errors: [e.message])) && return if block

  raise e
end