Class: GenevaDrive::StepCollection Private
- Inherits:
-
Object
- Object
- GenevaDrive::StepCollection
- 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
-
#[](index) ⇒ StepDefinition?
Returns the step at the given index.
-
#at(position) ⇒ StepDefinition?
private
Finds a step by position (0-indexed).
-
#each {|StepDefinition| ... } ⇒ Enumerator
Iterates over steps in order.
-
#empty? ⇒ Boolean
Checks if the collection is empty.
-
#first ⇒ StepDefinition?
Returns the first step in the workflow.
-
#initialize(step_definitions) ⇒ StepCollection
constructor
private
Creates a new step collection from an array of step definitions.
-
#key?(name) ⇒ Boolean
private
Checks if a step exists with the given name.
-
#last ⇒ StepDefinition?
Returns the last step in the workflow.
-
#named(name) ⇒ StepDefinition?
private
Finds a step by name.
-
#next_after(current_name) ⇒ StepDefinition?
private
Returns the next runnable step after the given step name.
-
#previous_before(current_name) ⇒ StepDefinition?
private
Returns the previous runnable step before the given step name in the ordered sequence.
-
#removed ⇒ Array<StepDefinition>
private
Returns the
removed_stepgravestones, in order. -
#runnable ⇒ Array<StepDefinition>
private
Returns the steps that can actually run, in order, with
removed_stepgravestones filtered out. -
#size ⇒ Integer
(also: #length)
Returns the number of steps.
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.
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.
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).
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.
|
|
# File 'lib/geneva_drive/step_collection.rb', line 14
|
#empty? ⇒ Boolean
Checks if the collection is empty.
|
|
# File 'lib/geneva_drive/step_collection.rb', line 31
|
#first ⇒ StepDefinition?
Returns the first step in the workflow.
|
|
# 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.
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.
|
|
# 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.
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.
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.
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.
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.
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.
|
|
# File 'lib/geneva_drive/step_collection.rb', line 19
|