Class: Inquirex::Actions::Runner

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(definition) ⇒ Runner

Returns a new instance of Runner.

Parameters:



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.

Parameters:

  • answers (Answers, Hash)

    completed answers (a Hash is wrapped)

Returns:

  • (Answers)

    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