Class: Roast::Workflow::StepTypeResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/workflow/step_type_resolver.rb

Overview

Determines the type of a step and how it should be executed

Constant Summary collapse

COMMAND_STEP =

Step type constants

:command
GLOB_STEP =
:glob
ITERATION_STEP =
:iteration
CONDITIONAL_STEP =
:conditional
CASE_STEP =
:case
INPUT_STEP =
:input
HASH_STEP =
:hash
PARALLEL_STEP =
:parallel
STRING_STEP =
:string
STANDARD_STEP =
:standard
AGENT_STEP =
:agent
ITERATION_STEPS =

Special step names for iterations

["repeat", "each"].freeze
CONDITIONAL_STEPS =

Special step names for conditionals

["if", "unless"].freeze
CASE_STEPS =

Special step name for case statements

["case"].freeze
INPUT_STEPS =

Special step name for input steps

["input"].freeze

Class Method Summary collapse

Class Method Details

.agent_step?(step) ⇒ Boolean

Check if a step is an agent step

Parameters:

  • step (String)

    The step to check

Returns:

  • (Boolean)

    true if it’s an agent step



60
61
62
# File 'lib/roast/workflow/step_type_resolver.rb', line 60

def agent_step?(step)
  step.is_a?(String) && step.start_with?("^")
end

.case_step?(step) ⇒ Boolean

Check if a step is a case step

Parameters:

  • step (Hash)

    The step to check

Returns:

  • (Boolean)

    true if it’s a case step



98
99
100
101
102
103
# File 'lib/roast/workflow/step_type_resolver.rb', line 98

def case_step?(step)
  return false unless step.is_a?(Hash)

  step_name = step.keys.first
  CASE_STEPS.include?(step_name)
end

.command_step?(step) ⇒ Boolean

Check if a step is a command step

Parameters:

  • step (String)

    The step to check

Returns:

  • (Boolean)

    true if it’s a command step



53
54
55
# File 'lib/roast/workflow/step_type_resolver.rb', line 53

def command_step?(step)
  step.is_a?(String) && step.start_with?("$(")
end

.conditional_step?(step) ⇒ Boolean

Check if a step is a conditional step

Parameters:

  • step (Hash)

    The step to check

Returns:

  • (Boolean)

    true if it’s a conditional step



88
89
90
91
92
93
# File 'lib/roast/workflow/step_type_resolver.rb', line 88

def conditional_step?(step)
  return false unless step.is_a?(Hash)

  step_name = step.keys.first
  CONDITIONAL_STEPS.include?(step_name)
end

.extract_name(step) ⇒ String?

Extract the step name from various step formats

Parameters:

  • step (String, Hash, Array)

    The step

Returns:

  • (String, nil)

    The step name or nil



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/roast/workflow/step_type_resolver.rb', line 118

def extract_name(step)
  case step
  when String
    # Strip ^ prefix for agent steps
    agent_step?(step) ? step[1..] : step
  when Hash
    step.keys.first
  when Array
    nil # Parallel steps don't have a single name
  end
end

.glob_step?(step, context = nil) ⇒ Boolean

Check if a step is a glob pattern

Parameters:

  • step (String)

    The step to check

  • context (WorkflowContext, nil) (defaults to: nil)

    The workflow context

Returns:

  • (Boolean)

    true if it’s a glob pattern



68
69
70
71
72
73
# File 'lib/roast/workflow/step_type_resolver.rb', line 68

def glob_step?(step, context = nil)
  return false unless step.is_a?(String) && step.include?("*")

  # Only treat as glob if we don't have a resource
  context.nil? || !context.has_resource?
end

.input_step?(step) ⇒ Boolean

Check if a step is an input step

Parameters:

  • step (Hash)

    The step to check

Returns:

  • (Boolean)

    true if it’s an input step



108
109
110
111
112
113
# File 'lib/roast/workflow/step_type_resolver.rb', line 108

def input_step?(step)
  return false unless step.is_a?(Hash)

  step_name = step.keys.first
  INPUT_STEPS.include?(step_name)
end

.iteration_step?(step) ⇒ Boolean

Check if a step is an iteration step

Parameters:

  • step (Hash)

    The step to check

Returns:

  • (Boolean)

    true if it’s an iteration step



78
79
80
81
82
83
# File 'lib/roast/workflow/step_type_resolver.rb', line 78

def iteration_step?(step)
  return false unless step.is_a?(Hash)

  step_name = step.keys.first
  ITERATION_STEPS.include?(step_name)
end

.resolve(step, context = nil) ⇒ Symbol

Resolve the type of a step

Parameters:

  • step (String, Hash, Array)

    The step to analyze

  • context (WorkflowContext) (defaults to: nil)

    The workflow context

Returns:

  • (Symbol)

    The step type



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/roast/workflow/step_type_resolver.rb', line 37

def resolve(step, context = nil)
  case step
  when String
    resolve_string_step(step, context)
  when Hash
    resolve_hash_step(step)
  when Array
    PARALLEL_STEP
  else
    STANDARD_STEP
  end
end