Class: Roast::Workflow::StepFinder

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

Overview

Finds step indices within workflow step arrays Handles various step formats: strings, hashes, parallel arrays

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps = nil) ⇒ StepFinder

Returns a new instance of StepFinder.



10
11
12
# File 'lib/roast/workflow/step_finder.rb', line 10

def initialize(steps = nil)
  @steps = steps || []
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



8
9
10
# File 'lib/roast/workflow/step_finder.rb', line 8

def steps
  @steps
end

Class Method Details

.find_index(steps_array, step_name) ⇒ Object



15
16
17
# File 'lib/roast/workflow/step_finder.rb', line 15

def find_index(steps_array, step_name)
  new(steps_array).find_index(step_name)
end

Instance Method Details

#extract_name(step) ⇒ String, Array

Extract the name from a step definition

Parameters:

  • step (String, Hash, Array)

    The step definition

Returns:

  • (String, Array)

    The step name(s)



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

def extract_name(step)
  case step
  when String
    step
  when Hash
    step.keys.first
  when Array
    # For arrays, extract names from all contained steps
    step.map { |s| extract_name(s) }
  end
end

#find_index(step_name, steps_array = nil) ⇒ Integer?

Find the index of a step in the workflow steps array

Parameters:

  • step_name (String)

    The name of the step to find

  • steps_array (Array, nil) (defaults to: nil)

    Optional steps array to search in

Returns:

  • (Integer, nil)

    The index of the step, or nil if not found



24
25
26
27
28
29
30
31
32
# File 'lib/roast/workflow/step_finder.rb', line 24

def find_index(step_name, steps_array = nil)
  search_array = steps_array || @steps
  # First, try direct search
  index = find_by_direct_search(search_array, step_name)
  return index if index

  # Fall back to extracted name search
  find_by_extracted_name(search_array, step_name)
end