Class: GenevaDrive::StepCollection Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/geneva_drive/step_collection.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Manages an ordered collection of step definitions for a workflow. Handles step ordering based on before_step/after_step positioning and provides methods for navigating between steps.

Instance Method Summary collapse

Constructor Details

#initialize(step_definitions) ⇒ StepCollection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new step collection from an array of step definitions.

Parameters:

  • step_definitions (Array<StepDefinition>) —

    the step definitions to manage



46
47
48
49
# File 'lib/geneva_drive/step_collection.rb', line 46

def initialize(step_definitions)
  @step_definitions = step_definitions
  @ordered_steps = nil
end

Instance Method Details

#[](index) ⇒ StepDefinition?

Returns the step at the given index.

Parameters:

  • index (Integer) —

    the index

Returns:



40
# File 'lib/geneva_drive/step_collection.rb', line 40

def_delegators :ordered_steps, :each, :size, :first, :last, :empty?, :[], :index, :find_index

#at(position) ⇒ StepDefinition?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds a step by position (0-indexed).

Parameters:

  • position (Integer) —

    the position index

Returns:

  • (StepDefinition, nil) —

    the step definition or nil if out of bounds



64
65
66
# File 'lib/geneva_drive/step_collection.rb', line 64

def at(position)
  ordered_steps[position]
end

#each {|StepDefinition| ... } ⇒ Enumerator

Iterates over steps in order.

Yields:

Returns:

  • (Enumerator) —

    if no block given



# File 'lib/geneva_drive/step_collection.rb', line 14

#empty? ⇒ Boolean

Checks if the collection is empty.

Returns:

  • (Boolean) —

    true if no steps



# File 'lib/geneva_drive/step_collection.rb', line 31

#first ⇒ StepDefinition?

Returns the first step in the workflow.

Returns:



# File 'lib/geneva_drive/step_collection.rb', line 23

#key?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks if a step exists with the given name. Does not trigger ordering computation.

Parameters:

  • name (String, Symbol) —

    the step name

Returns:

  • (Boolean) —

    true if step exists



123
124
125
126
# File 'lib/geneva_drive/step_collection.rb', line 123

def key?(name)
  name_str = name.to_s
  @step_definitions.any? { |step| step.name == name_str }
end

#last ⇒ StepDefinition?

Returns the last step in the workflow.

Returns:



# File 'lib/geneva_drive/step_collection.rb', line 27

#named(name) ⇒ StepDefinition?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds a step by name.

Parameters:

  • name (String, Symbol) —

    the step name

Returns:



55
56
57
58
# File 'lib/geneva_drive/step_collection.rb', line 55

def named(name)
  name_str = name.to_s
  find { |step| step.name == name_str }
end

#next_after(current_name) ⇒ StepDefinition?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the next runnable step after the given step name.

Steps declared with removed_step are stepped over: they hold a position in the sequence so that executions scheduled before their removal still resolve, but no execution is ever scheduled for one.

A nil current_name means "the beginning", so the first runnable step is returned - which is how the first step of a workflow is chosen.

Parameters:

  • current_name (String, Symbol, nil) —

    the current step name

Returns:



79
80
81
82
83
84
85
86
# File 'lib/geneva_drive/step_collection.rb', line 79

def next_after(current_name)
  return ordered_steps.find { |s| !s.removed? } if current_name.nil?

  current_index = ordered_steps.index { |s| s.name == current_name.to_s }
  return nil unless current_index

  ordered_steps[(current_index + 1)..].find { |s| !s.removed? }
end

#previous_before(current_name) ⇒ StepDefinition?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the previous runnable step before the given step name in the ordered sequence. Removed steps are stepped over, for the same reason #next_after steps over them.

Parameters:

  • current_name (String, Symbol, nil) —

    the current step name

Returns:

  • (StepDefinition, nil) —

    the previous runnable step or nil if at beginning



94
95
96
97
98
99
100
101
# File 'lib/geneva_drive/step_collection.rb', line 94

def previous_before(current_name)
  return nil if current_name.nil?

  current_index = find_index { |s| s.name == current_name.to_s }
  return nil unless current_index && current_index > 0

  ordered_steps[0...current_index].reverse_each.find { |s| !s.removed? }
end

#removed ⇒ Array<StepDefinition>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the removed_step gravestones, in order.

Returns:



114
115
116
# File 'lib/geneva_drive/step_collection.rb', line 114

def removed
  ordered_steps.select(&:removed?)
end

#runnable ⇒ Array<StepDefinition>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the steps that can actually run, in order, with removed_step gravestones filtered out.

Returns:



107
108
109
# File 'lib/geneva_drive/step_collection.rb', line 107

def runnable
  ordered_steps.reject(&:removed?)
end

#size ⇒ Integer Also known as: length

Returns the number of steps.

Returns:

  • (Integer) —

    the step count



# File 'lib/geneva_drive/step_collection.rb', line 19