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

#firstStepDefinition?

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



99
100
101
102
# File 'lib/geneva_drive/step_collection.rb', line 99

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

#lastStepDefinition?

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 step after the given step name.

Parameters:

  • current_name (String, Symbol, nil)

    the current step name

Returns:



72
73
74
75
76
77
78
79
# File 'lib/geneva_drive/step_collection.rb', line 72

def next_after(current_name)
  return first if current_name.nil?

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

  self[current_index + 1]
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 step before the given step name in the ordered sequence.

Parameters:

  • current_name (String, Symbol, nil)

    the current step name

Returns:



85
86
87
88
89
90
91
92
# File 'lib/geneva_drive/step_collection.rb', line 85

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

  self[current_index - 1]
end

#sizeInteger Also known as: length

Returns the number of steps.

Returns:

  • (Integer)

    the step count



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