class Linearly::Mixins::StepCollection::Reducer
{Reducer} encapsulates the logic required to process a single Step
in a larger collection.
@api private
Attributes
Return the original {Statefully::State}
@return [Statefully::State] @api private
Return the {Step} to run
@return [Step] @api private
Public Class Methods
Public interface for the {Reducer}
@param input [Statefully::State] @param step [Step]
@return [Statefully::State] @api private
# File lib/linearly/mixins/step_collection.rb, line 34 def self.reduce(input, step) new(input: input, step: step).reduce end
Private Class Methods
Private constructor for the {Reducer}
@param input [Statefully::State] @param step [Step]
@api private
# File lib/linearly/mixins/step_collection.rb, line 68 def initialize(input:, step:) @input = input @step = step end
Public Instance Methods
Internal Reducer
method to create {Step} output
@return [Statefully::State] @api private
# File lib/linearly/mixins/step_collection.rb, line 42 def reduce return input if input.failed? || input.finished? return input.fail(bad_output_error) unless state_returned? output end
Private Instance Methods
Construct an {Errors::StateNotReturned} error from internal state
@return [Errors::StateNotReturned] @api private
# File lib/linearly/mixins/step_collection.rb, line 78 def bad_output_error Errors::StateNotReturned.new( output: output, step: step.class.name, ) end
Create output and memoize for reuse
@return [Statefully::State] @api private
# File lib/linearly/mixins/step_collection.rb, line 89 def output @output ||= begin step.call(input) rescue StandardError => error input.fail(error) end end
Check if output is an instance of {Statefully::State}
@return [Boolean] @api private
# File lib/linearly/mixins/step_collection.rb, line 101 def state_returned? output.is_a?(Statefully::State) end