Sha256: a51b2cae3fe8b3f39131b7b7285bf22c39a8ec618685a48a56dac3cdc14a50fb

Contents?: true

Size: 451 Bytes

Versions: 3

Compression:

Stored size: 451 Bytes

Contents

module Flows
  # Simple sequentional flow
  class Flow
    def initialize(start_node:, nodes:)
      @start_node = start_node
      @nodes = Hash[
        nodes.map { |node| [node.name, node] }
      ]
    end

    def call(input, context:)
      current_node_name = @start_node

      while current_node_name != :term
        input, current_node_name = @nodes[current_node_name].call(input, context: context)
      end

      input
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flows-0.1.0 lib/flows/flow.rb
flows-0.0.2 lib/flows/flow.rb
flows-0.0.1 lib/flows/flow.rb