Class: Roast::Workflow::CaseExecutor
- Inherits:
-
Object
- Object
- Roast::Workflow::CaseExecutor
- Defined in:
- lib/roast/workflow/case_executor.rb
Overview
Handles execution of case/when/else steps
Instance Method Summary collapse
- #execute_case(case_config) ⇒ Object
-
#initialize(workflow, context_path, state_manager, workflow_executor = nil) ⇒ CaseExecutor
constructor
A new instance of CaseExecutor.
Constructor Details
#initialize(workflow, context_path, state_manager, workflow_executor = nil) ⇒ CaseExecutor
Returns a new instance of CaseExecutor.
7 8 9 10 11 12 |
# File 'lib/roast/workflow/case_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_case(case_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 |
# File 'lib/roast/workflow/case_executor.rb', line 14 def execute_case(case_config) $stderr.puts "Executing case step: #{case_config.inspect}" # Extract case expression case_expr = case_config["case"] when_clauses = case_config["when"] case_config["else"] # Verify required parameters raise WorkflowExecutor::ConfigurationError, "Missing 'case' expression in case configuration" unless case_expr raise WorkflowExecutor::ConfigurationError, "Missing 'when' clauses in case configuration" unless when_clauses # Create and execute a CaseStep case_step = CaseStep.new( @workflow, config: case_config, name: "case_#{case_expr.to_s.gsub(/[^a-zA-Z0-9_]/, "_")[0..30]}", context_path: @context_path, workflow_executor: @workflow_executor, ) result = case_step.call # Store the result in workflow output step_name = "case_#{case_expr.to_s.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 |