Skip to content

Commit

Permalink
Merge pull request #277 from kbrock/choice_validation
Browse files Browse the repository at this point in the history
For Choice validation, use instance variables and not payload
  • Loading branch information
agrare committed Sep 20, 2024
2 parents 82053b3 + ce8de3a commit 27f5f91
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/floe/workflow/states/choice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ class Choice < Floe::Workflow::State
def initialize(workflow, name, payload)
super

validate_state!(workflow)

@choices = payload["Choices"].map.with_index { |choice, i| ChoiceRule.build(workflow, name + ["Choices", i.to_s], choice) }
@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", "$"))
Expand Down Expand Up @@ -45,12 +44,12 @@ def validate_state!(workflow)
end

def validate_state_choices!
missing_field_error!("Choices") unless payload.key?("Choices")
invalid_field_error!("Choices", nil, "must be a non-empty array") unless payload["Choices"].kind_of?(Array) && !payload["Choices"].empty?
missing_field_error!("Choices") if @choices.nil?
invalid_field_error!("Choices", nil, "must be a non-empty array") unless @choices.kind_of?(Array) && !@choices.empty?
end

def validate_state_default!(workflow)
invalid_field_error!("Default", payload["Default"], "is not found in \"States\"") if payload["Default"] && !workflow_state?(payload["Default"], workflow)
invalid_field_error!("Default", @default, "is not found in \"States\"") if @default && !workflow_state?(@default, workflow)
end
end
end
Expand Down

0 comments on commit 27f5f91

Please sign in to comment.