Class: Roast::Workflow::WorkflowContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(workflow:, config_hash:, context_path:) ⇒ WorkflowContext

Initialize the workflow context

Parameters:

  • workflow (BaseWorkflow)

    The workflow instance

  • config_hash (Hash)

    The workflow configuration hash

  • context_path (String)

    The context directory path



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_hashObject (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_pathObject (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

#workflowObject (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

Parameters:

  • step_name (String)

    The name of the step

Returns:

  • (Boolean)

    true if the step should exit on error (default true)



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

Returns:

  • (Boolean)

    true if workflow responds to resource and has one



34
35
36
# File 'lib/roast/workflow/workflow_context.rb', line 34

def has_resource?
  workflow.respond_to?(:resource) && workflow.resource
end

#resource_typeSymbol?

Get the resource type from the workflow

Returns:

  • (Symbol, nil)

    The resource type or nil



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

Parameters:

  • step_name (String)

    The name of the step

Returns:

  • (Hash)

    The step configuration or empty hash



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

Parameters:

Returns:



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