class Teckel::Chain::Runner
The default implementation for executing a {Chain}
@!visibility protected
Constants
- StepResult
@!visibility private
- UNDEFINED
@!visibility private
Attributes
chain[R]
settings[R]
Public Class Methods
new(chain, settings = UNDEFINED)
click to toggle source
# File lib/teckel/chain/runner.rb, line 15 def initialize(chain, settings = UNDEFINED) @chain, @settings = chain, settings end
Public Instance Methods
call(input = nil)
click to toggle source
Run steps
@param input Any form of input the first steps input
class can handle
@return [Teckel::Chain::Result] The result object wrapping
either the success or failure value.
# File lib/teckel/chain/runner.rb, line 26 def call(input = nil) step_result = run(input) chain.result_constructor.call(*step_result) end
steps()
click to toggle source
# File lib/teckel/chain/runner.rb, line 31 def steps settings == UNDEFINED ? chain.steps : steps_with_settings end
Private Instance Methods
run(input)
click to toggle source
# File lib/teckel/chain/runner.rb, line 37 def run(input) steps.each_with_object(StepResult.new(input)) do |step, step_result| result = step.operation.call(step_result.value) step_result.step = step step_result.value = result.value step_result.success = result.successful? break step_result if result.failure? end end
step_with_settings(step)
click to toggle source
# File lib/teckel/chain/runner.rb, line 49 def step_with_settings(step) settings.key?(step.name) ? step.with(settings[step.name]) : step end
steps_with_settings()
click to toggle source
# File lib/teckel/chain/runner.rb, line 53 def steps_with_settings Enumerator.new do |yielder| chain.steps.each do |step| yielder << step_with_settings(step) end end end