Sha256: 87b1be10afd77bcca98ba3755418945a9d31a4ff6541b62750de9b7b33997228

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Flows
  class SharedContextPipeline
    # @api private
    class Track
      TRACK_ENTRY_ROUTER_DEF = RouterDefinition.new(
        Flows::Result::Ok => :next,
        Flows::Result::Err => :end
      )

      def initialize(name)
        @name = name
        @step_list = []
      end

      def initialize_dup(_other)
        @step_list = @step_list.map(&:dup)
      end

      def add_step(step)
        last_step = @step_list.last
        last_step.next_step = step.name if last_step

        @step_list << step

        self
      end

      def first_step_name
        @step_list.first.name
      end

      def empty?
        @step_list.empty?
      end

      def to_node_map(method_source)
        @step_list.each_with_object(@name => make_track_entry_node) do |step, node_map|
          node_map[step.name] = step.to_node(method_source)
        end
      end

      private

      def make_track_entry_node
        MutationStep.new(
          name: @name,
          body: proc { true },
          router_def: TRACK_ENTRY_ROUTER_DEF,
          next_step: first_step_name
        ).to_node(nil)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flows-0.6.0 lib/flows/shared_context_pipeline/track.rb