Class: Inquirex::Actions::Runner
- Inherits:
-
Object
- Object
- Inquirex::Actions::Runner
- Defined in:
- lib/inquirex/actions/runner.rb
Overview
Executes a definition's actions against completed answers, in declaration order, populating Answers#outbox with built messages and a result trail.
Deliberately separate from the Engine: in the cross-site architecture the frontend collects answers and a different server process post-processes them, so the runner is a pure function of (definition, answers) — which also makes rebuilding messages inside a background job trivial.
A failing effect records a :failed result and never aborts the other actions; the host inspects outbox.failures and decides what to do.
Instance Method Summary collapse
-
#call(answers) ⇒ Answers
The (possibly wrapped) answers with #outbox populated.
-
#initialize(definition) ⇒ Runner
constructor
A new instance of Runner.
Constructor Details
#initialize(definition) ⇒ Runner
Returns a new instance of Runner.
19 20 21 |
# File 'lib/inquirex/actions/runner.rb', line 19 def initialize(definition) @definition = definition end |
Instance Method Details
#call(answers) ⇒ Answers
Returns the (possibly wrapped) answers with #outbox populated.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/inquirex/actions/runner.rb', line 25 def call(answers) answers = Answers.new(answers) unless answers.is_a?(Answers) context = answers.to_h @definition.actions.each do |action| unless action.applicable?(context) answers.outbox.record(action.id, :skipped) next end execute(action, answers) end answers end |