Sha256: 886fed74d3319506b070ac1faf8cc774a9af388822921a7282cf42c60a0da6c3

Contents?: true

Size: 668 Bytes

Versions: 3

Compression:

Stored size: 668 Bytes

Contents

module Flows
  class Railway
    # @api private
    Step = Struct.new(:name, :lambda, :next_step, keyword_init: true) do
      NODE_PREPROCESSOR = ->(input, _, _) { [[], input.unwrap] }

      NODE_POSTPROCESSOR = lambda do |output, context, meta|
        context[:last_step] = meta[:name]

        output
      end

      def to_node(method_source)
        Flows::Flow::Node.new(
          body: lambda || method_source.method(name),
          router: Flows::Flow::Router::Simple.new(next_step || :end, :end),
          meta: { name: name },
          preprocessor: NODE_PREPROCESSOR,
          postprocessor: NODE_POSTPROCESSOR
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flows-0.5.1 lib/flows/railway/step.rb
flows-0.5.0 lib/flows/railway/step.rb
flows-0.4.0 lib/flows/railway/step.rb