Class: Roast::Workflow::ConditionalExecutor
- Inherits:
-
Object
- Object
- Roast::Workflow::ConditionalExecutor
- Defined in:
- lib/roast/workflow/conditional_executor.rb
Overview
Handles execution of conditional steps (if and unless)
Instance Method Summary collapse
- #execute_conditional(conditional_config) ⇒ Object
-
#initialize(workflow, context_path, state_manager, workflow_executor = nil) ⇒ ConditionalExecutor
constructor
A new instance of ConditionalExecutor.
Constructor Details
#initialize(workflow, context_path, state_manager, workflow_executor = nil) ⇒ ConditionalExecutor
Returns a new instance of ConditionalExecutor.
7 8 9 10 11 12 |
# File 'lib/roast/workflow/conditional_executor.rb', line 7 def initialize(workflow, context_path, state_manager, workflow_executor = nil) @workflow = workflow @context_path = context_path @state_manager = state_manager @workflow_executor = workflow_executor end |
Instance Method Details
#execute_conditional(conditional_config) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/roast/workflow/conditional_executor.rb', line 14 def execute_conditional(conditional_config) $stderr.puts "Executing conditional step: #{conditional_config.inspect}" # Determine if this is an 'if' or 'unless' condition condition_expr = conditional_config["if"] || conditional_config["unless"] is_unless = conditional_config.key?("unless") then_steps = conditional_config["then"] # Verify required parameters raise WorkflowExecutor::ConfigurationError, "Missing condition in conditional configuration" unless condition_expr raise WorkflowExecutor::ConfigurationError, "Missing 'then' steps in conditional configuration" unless then_steps # Create and execute a ConditionalStep conditional_step = ConditionalStep.new( @workflow, config: conditional_config, name: "conditional_#{condition_expr.gsub(/[^a-zA-Z0-9_]/, "_")[0..20]}", context_path: @context_path, workflow_executor: @workflow_executor, ) result = conditional_step.call # Store a marker in workflow output to indicate which branch was taken condition_key = is_unless ? "unless" : "if" step_name = "#{condition_key}_#{condition_expr.gsub(/[^a-zA-Z0-9_]/, "_")[0..30]}" @workflow.output[step_name] = result # Save state @state_manager.save_state(step_name, @workflow.output[step_name]) result end |