Skip to content

Commit 8df356a

Browse files
authored
Merge pull request #326 from agrare/dont_access_payload
Refactor workflow state check
2 parents 37a1bc2 + 3ec61c2 commit 8df356a

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

lib/floe/validation_mixin.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ def runtime_field_error!(field_name, field_value, comment, floe_error: "States.R
2222
raise Floe::ExecutionError.new(self.class.field_error_text(name, field_name, field_value, comment), floe_error)
2323
end
2424

25-
def workflow_state?(field_value, workflow)
26-
workflow.payload["States"] ? workflow.payload["States"].include?(field_value) : true
27-
end
28-
2925
def wrap_parser_error(field_name, field_value)
3026
yield
3127
rescue ArgumentError, InvalidWorkflowError => error

lib/floe/workflow/catcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize(workflow, name, payload)
2424

2525
def validate_state_next!(workflow)
2626
missing_field_error!("Next") if @next.nil?
27-
invalid_field_error!("Next", @next, "is not found in \"States\"") if @next && !workflow_state?(@next, workflow)
27+
invalid_field_error!("Next", @next, "is not found in \"States\"") if @next && !workflow.state?(@next)
2828
end
2929
end
3030
end

lib/floe/workflow/choice_rule.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def validate_next!(workflow)
5151
elsif !@next
5252
# top level nodes require a next
5353
missing_field_error!("Next")
54-
elsif !workflow_state?(@next, workflow)
54+
elsif !workflow.state?(@next)
5555
# top level nodes require a next field that is found
5656
invalid_field_error!("Next", @next, "is not found in \"States\"")
5757
end

lib/floe/workflow/states/choice.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def validate_state_choices!
4949
end
5050

5151
def validate_state_default!(workflow)
52-
invalid_field_error!("Default", @default, "is not found in \"States\"") if @default && !workflow_state?(@default, workflow)
52+
invalid_field_error!("Default", @default, "is not found in \"States\"") if @default && !workflow.state?(@default)
5353
end
5454
end
5555
end

lib/floe/workflow/states/non_terminal_mixin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def finish(context)
1313

1414
def validate_state_next!(workflow)
1515
missing_field_error!("Next") if @next.nil? && !@end
16-
invalid_field_error!("Next", @next, "is not found in \"States\"") if @next && !workflow_state?(@next, workflow)
16+
invalid_field_error!("Next", @next, "is not found in \"States\"") if @next && !workflow.state?(@next)
1717
end
1818
end
1919
end

lib/floe/workflow_base.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def output(context)
7777
context.output.to_json if end?(context)
7878
end
7979

80+
def state?(state_name)
81+
@payload["States"].include?(state_name)
82+
end
83+
8084
private
8185

8286
def step!(context)
@@ -102,7 +106,7 @@ def end_workflow!(context)
102106
def validate_workflow!
103107
missing_field_error!("States") if @states.empty?
104108
missing_field_error!("StartAt") if @start_at.nil?
105-
invalid_field_error!("StartAt", @start_at, "is not found in \"States\"") unless workflow_state?(@start_at, self)
109+
invalid_field_error!("StartAt", @start_at, "is not found in \"States\"") unless state?(@start_at)
106110
end
107111
end
108112
end

0 commit comments

Comments
 (0)