Sha256: afdcb2e60835fe0f323fb8b60c374f97b0800a37bb3d0a7f3b9e0883fd093824

Contents?: true

Size: 912 Bytes

Versions: 1

Compression:

Stored size: 912 Bytes

Contents

module Flows
  class SharedContextPipeline
    EMPTY_HASH = {}.freeze
    EMPTY_OK = Flows::Result::Ok.new(nil).freeze
    EMPTY_ERR = Flows::Result::Err.new(nil).freeze

    # @api private
    class MutationStep < Step
      NODE_PREPROCESSOR = lambda do |_input, context, meta|
        context[:last_step] = meta[:name]

        context[:class].before_each_callbacks.each do |callback|
          callback.call(context[:class], meta[:name], context[:data])
        end

        [[context[:data]], EMPTY_HASH]
      end

      NODE_POSTPROCESSOR = lambda do |output, context, meta|
        case output
        when Flows::Result then output
        else output ? EMPTY_OK : EMPTY_ERR
        end.tap do |result|
          context[:class].after_each_callbacks.each do |callback|
            callback.call(context[:class], meta[:name], context[:data], result)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flows-0.4.0 lib/flows/shared_context_pipeline/mutation_step.rb