Class: Roast::Workflow::ConditionalStep
- Includes:
- ExpressionEvaluator
- Defined in:
- lib/roast/workflow/conditional_step.rb
Instance Attribute Summary
Attributes inherited from BaseStep
#available_tools, #coerce_to, #context_path, #json, #model, #name, #params, #print_response, #resource, #workflow
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(workflow, config:, name:, context_path:, workflow_executor:, **kwargs) ⇒ ConditionalStep
constructor
A new instance of ConditionalStep.
Methods included from ExpressionEvaluator
#evaluate_bash_command, #evaluate_ruby_expression, #evaluate_step_or_value
Methods included from ExpressionUtils
#bash_command?, #extract_command, #extract_expression, #ruby_expression?
Constructor Details
#initialize(workflow, config:, name:, context_path:, workflow_executor:, **kwargs) ⇒ ConditionalStep
Returns a new instance of ConditionalStep.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/roast/workflow/conditional_step.rb', line 8 def initialize(workflow, config:, name:, context_path:, workflow_executor:, **kwargs) super(workflow, name: name, context_path: context_path, **kwargs) @config = config @condition = config["if"] || config["unless"] @is_unless = config.key?("unless") @then_steps = config["then"] || [] @else_steps = config["else"] || [] @workflow_executor = workflow_executor end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/roast/workflow/conditional_step.rb', line 19 def call # Evaluate the condition condition_result = evaluate_condition(@condition) # Invert the result if this is an 'unless' condition condition_result = !condition_result if @is_unless # Select which steps to execute based on the condition steps_to_execute = condition_result ? @then_steps : @else_steps # Execute the selected steps unless steps_to_execute.empty? @workflow_executor.execute_steps(steps_to_execute) end # Return a result indicating which branch was taken { condition_result: condition_result, branch_executed: condition_result ? "then" : "else" } end |