Sha256: aff879e6d29d3aab02614da55465e06b6b1f33b52c63d2ac28a50dd654db9976

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

module BusinessFlow
  # Default behavior for running a step queue -- execute each step in turn
  # halting the moment something goes wrong. Use the same flow as input
  # and output to all steps.
  class DefaultStepExecutor
    def initialize(step_queue, flow)
      @step_queue = step_queue
      @flow = flow
    end

    def call
      @step_queue.each do |step|
        catch(:halt_step) { process_step(step) }
        break if @flow.errors.any?
      end
    end

    protected

    def process_step(step)
      ActiveSupport::Notifications.instrument(
        event_name(step), flow: @flow
      ) do |payload|
        payload[:step_result] = result = step.call(@flow)
        result.merge_into(@flow)
        result
      end
    end

    def event_name(step)
      "business_flow.step.#{@flow.class.to_s.underscore}. " \
        "#{step.to_s.underscore}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
business_flow-0.4.0 lib/business_flow/default_step_executor.rb