Module: Teckel::Chain::ClassMethods

Defined in:
lib/teckel/chain.rb

Instance Method Summary collapse

Instance Method Details

#call(input = nil) ⇒ Teckel::Chain::Result

The primary interface to call the chain with the given input.

Parameters:

  • input (defaults to: nil)

    Any form of input the first steps input class can handle

Returns:

  • (Teckel::Chain::Result)

    The result object wrapping the result value, the success state and last executed step.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/teckel/chain.rb', line 47

def call(input = nil)
  default_settings = self.default_settings

  runner =
    if default_settings
      self.runner.new(self, default_settings)
    else
      self.runner.new(self)
    end

  if around
    around.call(runner, input)
  else
    runner.call(input)
  end
end

#errors<Class>

List of all possible errors

Returns:

  • (<Class>)

    List of all steps Operation.errors



34
35
36
37
38
39
# File 'lib/teckel/chain.rb', line 34

def errors
  steps.each_with_object([]) do |step, m|
    err = step.operation.error
    m << err if err
  end
end

#inputClass

The expected input for this chain

Returns:

  • (Class)

    The Operation.input of the first step



22
23
24
# File 'lib/teckel/chain.rb', line 22

def input
  steps.first&.operation&.input
end

#outputClass

The expected output for this chain

Returns:

  • (Class)

    The Operation.output of the last step



28
29
30
# File 'lib/teckel/chain.rb', line 28

def output
  steps.last&.operation&.output
end

#with(settings) ⇒ Object Also known as: set

Parameters:

  • settings (Hash{String,Symbol => Object})

    Set settings for a step by it’s name



65
66
67
68
69
70
71
72
# File 'lib/teckel/chain.rb', line 65

def with(settings)
  runner = self.runner.new(self, settings)
  if around
    ->(input) { around.call(runner, input) }
  else
    runner
  end
end