Class: Roast::Workflow::WorkflowContext
- Inherits:
-
Object
- Object
- Roast::Workflow::WorkflowContext
- Defined in:
- lib/roast/workflow/workflow_context.rb
Overview
Encapsulates common workflow execution context parameters Reduces data clump anti-pattern by grouping related parameters
Instance Attribute Summary collapse
-
#config_hash ⇒ Object
readonly
Returns the value of attribute config_hash.
-
#context_path ⇒ Object
readonly
Returns the value of attribute context_path.
-
#workflow ⇒ Object
readonly
Returns the value of attribute workflow.
Instance Method Summary collapse
-
#exit_on_error?(step_name) ⇒ Boolean
Check if a step should exit on error.
-
#has_resource? ⇒ Boolean
Check if the workflow has a resource.
-
#initialize(workflow:, config_hash:, context_path:) ⇒ WorkflowContext
constructor
Initialize the workflow context.
-
#resource_type ⇒ Symbol?
Get the resource type from the workflow.
-
#step_config(step_name) ⇒ Hash
Get configuration for a specific step.
-
#with_workflow(new_workflow) ⇒ WorkflowContext
Create a new context with updated workflow.
Constructor Details
#initialize(workflow:, config_hash:, context_path:) ⇒ WorkflowContext
Initialize the workflow context
14 15 16 17 18 19 |
# File 'lib/roast/workflow/workflow_context.rb', line 14 def initialize(workflow:, config_hash:, context_path:) @workflow = workflow @config_hash = config_hash @context_path = context_path freeze end |
Instance Attribute Details
#config_hash ⇒ Object (readonly)
Returns the value of attribute config_hash.
8 9 10 |
# File 'lib/roast/workflow/workflow_context.rb', line 8 def config_hash @config_hash end |
#context_path ⇒ Object (readonly)
Returns the value of attribute context_path.
8 9 10 |
# File 'lib/roast/workflow/workflow_context.rb', line 8 def context_path @context_path end |
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
8 9 10 |
# File 'lib/roast/workflow/workflow_context.rb', line 8 def workflow @workflow end |
Instance Method Details
#exit_on_error?(step_name) ⇒ Boolean
Check if a step should exit on error
54 55 56 57 |
# File 'lib/roast/workflow/workflow_context.rb', line 54 def exit_on_error?(step_name) config = step_config(step_name) config.is_a?(Hash) ? config.fetch("exit_on_error", true) : true end |
#has_resource? ⇒ Boolean
Check if the workflow has a resource
34 35 36 |
# File 'lib/roast/workflow/workflow_context.rb', line 34 def has_resource? workflow.respond_to?(:resource) && workflow.resource end |
#resource_type ⇒ Symbol?
Get the resource type from the workflow
40 41 42 |
# File 'lib/roast/workflow/workflow_context.rb', line 40 def resource_type has_resource? ? workflow.resource.type : nil end |
#step_config(step_name) ⇒ Hash
Get configuration for a specific step
47 48 49 |
# File 'lib/roast/workflow/workflow_context.rb', line 47 def step_config(step_name) config_hash[step_name] || {} end |
#with_workflow(new_workflow) ⇒ WorkflowContext
Create a new context with updated workflow
24 25 26 27 28 29 30 |
# File 'lib/roast/workflow/workflow_context.rb', line 24 def with_workflow(new_workflow) self.class.new( workflow: new_workflow, config_hash: config_hash, context_path: context_path, ) end |