Class: Fractor::Workflow::PreExecutionContext
- Inherits:
-
Object
- Object
- Fractor::Workflow::PreExecutionContext
- Defined in:
- lib/fractor/workflow/pre_execution_context.rb
Overview
Manages pre-execution validation for workflows. Provides hooks for custom validation logic and detailed error messages.
This class ensures workflows are validated with full context before execution begins, catching errors early with clear messages.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
-
#workflow ⇒ Object
readonly
Returns the value of attribute workflow.
Instance Method Summary collapse
-
#add_error(message) ⇒ Object
Add an error message to the validation context.
-
#add_validation_hook(name = nil) {|context| ... } ⇒ Object
Register a custom validation hook.
-
#add_warning(message) ⇒ Object
Add a warning message to the validation context.
-
#has_warnings? ⇒ Boolean
Check if there are any warnings (regardless of errors).
-
#initialize(workflow, input) ⇒ PreExecutionContext
constructor
A new instance of PreExecutionContext.
-
#valid? ⇒ Boolean
Check if validation passed (errors only).
-
#validate! ⇒ Boolean
Run all validations and return whether validation passed.
Constructor Details
#initialize(workflow, input) ⇒ PreExecutionContext
Returns a new instance of PreExecutionContext.
13 14 15 16 17 18 19 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 13 def initialize(workflow, input) @workflow = workflow @input = input @errors = [] @warnings = [] @validation_hooks = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 11 def errors @errors end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
11 12 13 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 11 def input @input end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
11 12 13 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 11 def warnings @warnings end |
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
11 12 13 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 11 def workflow @workflow end |
Instance Method Details
#add_error(message) ⇒ Object
Add an error message to the validation context.
70 71 72 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 70 def add_error() @errors << end |
#add_validation_hook(name = nil) {|context| ... } ⇒ Object
Register a custom validation hook. Hooks should return true if validation passes, or add error messages.
33 34 35 36 37 38 39 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 33 def add_validation_hook(name = nil, &block) unless block raise ArgumentError, "Must provide a block for validation hook" end @validation_hooks << { name: name, block: block } end |
#add_warning(message) ⇒ Object
Add a warning message to the validation context.
77 78 79 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 77 def add_warning() @warnings << end |
#has_warnings? ⇒ Boolean
Check if there are any warnings (regardless of errors).
91 92 93 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 91 def has_warnings? !@warnings.empty? end |
#valid? ⇒ Boolean
Check if validation passed (errors only).
84 85 86 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 84 def valid? @errors.empty? end |
#validate! ⇒ Boolean
Run all validations and return whether validation passed.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fractor/workflow/pre_execution_context.rb', line 45 def validate! reset_results # Run built-in validations validate_workflow_definition! validate_input_type! validate_input_presence! # Run custom validation hooks run_validation_hooks # Raise error if any validation failed unless @errors.empty? raise WorkflowError, end # Log warnings if any log_warnings unless @warnings.empty? true end |