Module: Inquirex::Actions

Defined in:
lib/inquirex/actions.rb,
lib/inquirex/actions/base.rb,
lib/inquirex/actions/action.rb,
lib/inquirex/actions/custom.rb,
lib/inquirex/actions/outbox.rb,
lib/inquirex/actions/runner.rb,
lib/inquirex/actions/webhook.rb,
lib/inquirex/actions/template.rb,
lib/inquirex/actions/send_email.rb

Overview

Post-completion actions: named side-effect declarations that run server-side after a flow finishes, with access to the collected answers.

The DSL word action groups one or more effects (send_email, run, ...). Effects are looked up in a registry keyed by their DSL verb, so new effect types — a webhook, a save_record in inquirex-rails — plug in without core changes: register the class and it gains both the DSL word and JSON wire support.

Inquirex::Actions.register(:webhook, MyGem::WebhookEffect)

Actions never deliver anything themselves. send_email builds Mail::Message objects into Answers#outbox; the host application decides how to send them.

Defined Under Namespace

Modules: Template Classes: Action, Base, Custom, Outbox, Runner, SendEmail, Webhook

Class Method Summary collapse

Class Method Details

.lookup(type) ⇒ Class

Parameters:

  • type (Symbol, String)

Returns:

  • (Class)

Raises:



38
39
40
41
42
# File 'lib/inquirex/actions.rb', line 38

def lookup(type)
  @registry.fetch(type.to_sym) do
    raise Errors::SerializationError, "Unknown action effect type: #{type.inspect}"
  end
end

.register(type, klass) ⇒ Object

Registers an effect class under a DSL verb name.

Parameters:

  • type (Symbol)

    DSL verb (e.g. :send_email)

  • klass (Class)

    an Actions::Base subclass



25
26
27
# File 'lib/inquirex/actions.rb', line 25

def register(type, klass)
  @registry[type.to_sym] = klass
end

.registered?(type) ⇒ Boolean

Parameters:

  • type (Symbol, String)

Returns:

  • (Boolean)


31
32
33
# File 'lib/inquirex/actions.rb', line 31

def registered?(type)
  @registry.key?(type.to_sym)
end

.run(definition, answers) ⇒ Answers

Runs all of the definition's actions against the given answers.

Parameters:

Returns:

  • (Answers)

    with #outbox populated



52
53
54
# File 'lib/inquirex/actions.rb', line 52

def run(definition, answers)
  Runner.new(definition).call(answers)
end

.typesArray<Symbol>

Returns registered effect verbs.

Returns:

  • (Array<Symbol>)

    registered effect verbs



45
# File 'lib/inquirex/actions.rb', line 45

def types = @registry.keys