Sha256: f2198017078d1e976b5ec921895c5670d78853c2eeae1e27502a03397d687c63

Contents?: true

Size: 992 Bytes

Versions: 3

Compression:

Stored size: 992 Bytes

Contents

# frozen_string_literal: true

module Floe
  class Workflow
    module States
      class Choice < Floe::Workflow::State
        attr_reader :choices, :default, :input_path, :output_path

        def initialize(workflow, name, payload)
          super

          @choices = payload["Choices"].map { |choice| ChoiceRule.build(choice) }
          @default = payload["Default"]

          @input_path  = Path.new(payload.fetch("InputPath", "$"))
          @output_path = Path.new(payload.fetch("OutputPath", "$"))
        end

        def start(input)
          super
          input      = input_path.value(context, input)
          next_state = choices.detect { |choice| choice.true?(context, input) }&.next || default
          output     = output_path.value(context, input)

          context.next_state = next_state
          context.output     = output
        end

        def running?
          false
        end

        def end?
          false
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
floe-0.5.0 lib/floe/workflow/states/choice.rb
floe-0.4.1 lib/floe/workflow/states/choice.rb
floe-0.4.0 lib/floe/workflow/states/choice.rb