Method: Teckel::Chain::Config#result_constructor

Defined in:
lib/teckel/chain/config.rb

#result_constructorProc #result_constructor(sym_or_proc) ⇒ #call

Overloads:

  • #result_constructorProc

    The callable constructor to build an instance of the result class. Defaults to DEFAULT_CONSTRUCTOR

    Returns:

    • (Proc)

      A callable that will return an instance of result class.

  • #result_constructor(sym_or_proc) ⇒ #call

    Define how to build the result.

    Examples:

    class MyOperation
      include Teckel::Operation
    
      class Result < Teckel::Operation::Result
        def initialize(value, success, step, options = {}); end
      end
    
      # If you need more control over how to build a new +Settings+ instance
      result_constructor ->(value, success, step) { result.new(value, success, step, {foo: :bar}) }
    end

    Parameters:

    • sym_or_proc (Symbol, #call)
      • Either a Symbol representing the public method to call on the result class.

      • Or anything that response to #call (like a Proc).

    Returns:

    • (#call)

      The callable constructor



114
115
116
117
118
119
120
# File 'lib/teckel/chain/config.rb', line 114

def result_constructor(sym_or_proc = nil)
  constructor = build_constructor(result, sym_or_proc) unless sym_or_proc.nil?

  @config.for(:result_constructor, constructor) {
    build_constructor(result, Teckel::DEFAULT_CONSTRUCTOR)
  } || raise(MissingConfigError, "Missing result_constructor config for #{self}")
end