Class: Floe::Workflow::States::Choice

Inherits:
Floe::Workflow::State show all
Defined in:
lib/floe/workflow/states/choice.rb

Instance Attribute Summary collapse

Attributes inherited from Floe::Workflow::State

#comment, #name, #payload, #type

Instance Method Summary collapse

Methods inherited from Floe::Workflow::State

build!, #finished?, #long_name, #mark_error, #mark_finished, #mark_started, #ready?, #run_nonblock!, #short_name, #start, #started?, #wait, #wait_until, #waiting?

Methods included from ValidationMixin

included, #invalid_field_error!, #missing_field_error!, #parser_error!, #runtime_field_error!, #workflow_state?, #wrap_parser_error

Constructor Details

#initialize(workflow, name, payload) ⇒ Choice

Returns a new instance of Choice.



9
10
11
12
13
14
15
16
17
18
# File 'lib/floe/workflow/states/choice.rb', line 9

def initialize(workflow, name, payload)
  super

  @choices = payload["Choices"]&.map&.with_index { |choice, i| ChoiceRule.build(workflow, name + ["Choices", i.to_s], choice) }
  @default = payload["Default"]
  validate_state!(workflow)

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

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



7
8
9
# File 'lib/floe/workflow/states/choice.rb', line 7

def choices
  @choices
end

#defaultObject (readonly)

Returns the value of attribute default.



7
8
9
# File 'lib/floe/workflow/states/choice.rb', line 7

def default
  @default
end

#input_pathObject (readonly)

Returns the value of attribute input_path.



7
8
9
# File 'lib/floe/workflow/states/choice.rb', line 7

def input_path
  @input_path
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



7
8
9
# File 'lib/floe/workflow/states/choice.rb', line 7

def output_path
  @output_path
end

Instance Method Details

#end?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/floe/workflow/states/choice.rb', line 35

def end?
  false
end

#finish(context) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/floe/workflow/states/choice.rb', line 20

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

  runtime_field_error!("Default", nil, "not defined and no match found", :floe_error => "States.NoChoiceMatched") if next_state.nil?
  context.next_state = next_state
  context.output     = output
  super
end

#running?(_) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/floe/workflow/states/choice.rb', line 31

def running?(_)
  false
end