Class: HecksApp::ApplicationPort::CommandRunner
- Inherits:
-
Object
- Object
- HecksApp::ApplicationPort::CommandRunner
- Defined in:
- lib/application_port/command_runner.rb,
lib/application_port/command_runner/event.rb
Defined Under Namespace
Classes: Event
Instance Attribute Summary collapse
-
#runnable ⇒ Object
readonly
Returns the value of attribute runnable.
Instance Method Summary collapse
-
#initialize(runnable) ⇒ CommandRunner
constructor
A new instance of CommandRunner.
- #method_missing(name, *args, &block) ⇒ Object
- #run(name, args, &block) ⇒ Object
Constructor Details
#initialize(runnable) ⇒ CommandRunner
Returns a new instance of CommandRunner.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
21 22 23 |
# File 'lib/application_port/command_runner.rb', line 21 def method_missing(name, *args, &block) run(name, args, &block) end |
Instance Attribute Details
#runnable ⇒ Object (readonly)
Returns the value of attribute runnable.
5 6 7 |
# File 'lib/application_port/command_runner.rb', line 5 def runnable @runnable end |
Instance Method Details
#run(name, args, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# 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.])) && return if block raise e end |