Module: Linearly::Mixins::Reducer Private

Included in:
Flow
Defined in:
lib/linearly/mixins/reducer.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Reducer is a mixin to include in all classes which need to run more than one step.

Instance Method Summary collapse

Instance Method Details

#call(state) ⇒ Statefully::State

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Keep calling steps as long as the state is successful

This method reeks of :reek:TooManyStatements and :reek:FeatureEnvy.

Parameters:

  • state (Statefully::State)

Returns:

  • (Statefully::State)


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/linearly/mixins/reducer.rb', line 17

def call(state)
  steps.reduce(state) do |current, step|
    break current if current.failed? || current.finished?
    begin
      next_state = step.call(current)
    rescue StandardError => err
      break current.fail(err)
    end
    next next_state if next_state.is_a?(Statefully::State)
    current.fail(Errors::StateNotReturned.new(step))
  end
end