lib/floe/workflow/states/choice.rb in floe-0.5.0 vs lib/floe/workflow/states/choice.rb in floe-0.6.0

- old
+ new

@@ -7,10 +7,12 @@ attr_reader :choices, :default, :input_path, :output_path def initialize(workflow, name, payload) super + validate_state! + @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", "$")) @@ -30,9 +32,25 @@ false end def end? false + end + + private + + def validate_state! + validate_state_choices! + validate_state_default! + end + + def validate_state_choices! + raise Floe::InvalidWorkflowError, "Choice state must have \"Choices\"" unless payload.key?("Choices") + raise Floe::InvalidWorkflowError, "\"Choices\" must be a non-empty array" unless payload["Choices"].kind_of?(Array) && !payload["Choices"].empty? + end + + def validate_state_default! + raise Floe::InvalidWorkflowError, "\"Default\" not in \"States\"" unless workflow.payload["States"].include?(payload["Default"]) end end end end end