Class: Inquirex::Actions::Custom

Inherits:
Base
  • Object
show all
Defined in:
lib/inquirex/actions/custom.rb

Overview

Escape-hatch effect wrapping an arbitrary Ruby block, declared in the DSL as run { |answers, outbox| ... }. Full language power — build a Mail::Message by hand with outbox.add_message, call a service, record metrics — at the cost of serialization: like every lambda in Inquirex, the block is stripped from JSON and exists only in Ruby-authored definitions.

Instance Method Summary collapse

Methods inherited from Base

#to_h, #validate_against

Constructor Details

#initialize(block) ⇒ Custom

Returns a new instance of Custom.

Parameters:

  • block (Proc)

    receives (answers, outbox)



13
14
15
16
17
# File 'lib/inquirex/actions/custom.rb', line 13

def initialize(block)
  super()
  @block = block
  freeze
end

Instance Method Details

#call(answers, outbox) ⇒ Object

Invokes the wrapped block with the collected answers and the outbox.

Parameters:

  • answers (Answers)

    completed answers

  • outbox (Outbox)

    collector for messages the block may build

Returns:

  • (Object)

    whatever the block returns (recorded, not interpreted)



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

def call(answers, outbox)
  @block.call(answers, outbox)
end

#serializable?Boolean

Returns:

  • (Boolean)


28
# File 'lib/inquirex/actions/custom.rb', line 28

def serializable? = false