Class: Buildkite::Builder::StepCollection
- Inherits:
-
Object
- Object
- Buildkite::Builder::StepCollection
- Defined in:
- lib/buildkite/builder/step_collection.rb
Constant Summary collapse
- STEP_TYPES =
{ block: Pipelines::Steps::Block, command: Pipelines::Steps::Command, group: Pipelines::Steps::Group, input: Pipelines::Steps::Input, trigger: Pipelines::Steps::Trigger, wait: Pipelines::Steps::Wait }.freeze
Instance Attribute Summary collapse
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
- #each(*types, traverse_groups: true, &block) ⇒ Object
- #empty? ⇒ Boolean
- #find(key) ⇒ Object
- #find!(key) ⇒ Object
-
#initialize ⇒ StepCollection
constructor
A new instance of StepCollection.
- #move(*movable_steps, before: nil, after: nil) ⇒ Object
- #push(step) ⇒ Object
- #remove(step) ⇒ Object
- #replace(old_step, new_step) ⇒ Object
- #to_definition ⇒ Object
Constructor Details
#initialize ⇒ StepCollection
Returns a new instance of StepCollection.
15 16 17 |
# File 'lib/buildkite/builder/step_collection.rb', line 15 def initialize @steps = [] end |
Instance Attribute Details
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
13 14 15 |
# File 'lib/buildkite/builder/step_collection.rb', line 13 def steps @steps end |
Instance Method Details
#each(*types, traverse_groups: true, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/buildkite/builder/step_collection.rb', line 19 def each(*types, traverse_groups: true, &block) types = types.flatten types.map! { |type| STEP_TYPES.values.include?(type) ? type : STEP_TYPES.fetch(type) } types = STEP_TYPES.values if types.empty? matched_steps = steps.each_with_object([]) do |step, matches| if types.any? { |step_type| step.is_a?(step_type) } matches << step end if step.is_a?(Pipelines::Steps::Group) && traverse_groups step.steps.each(types) { |step| matches << step } end end matched_steps.each(&block) end |
#empty? ⇒ Boolean
73 74 75 |
# File 'lib/buildkite/builder/step_collection.rb', line 73 def empty? @steps.empty? || (@steps.all? { |step| step.is_a?(Pipelines::Steps::Group) && step.steps.empty? }) end |
#find(key) ⇒ Object
35 36 37 |
# File 'lib/buildkite/builder/step_collection.rb', line 35 def find(key) steps.find { |step| step.has?(:key) && step.key.to_s == key.to_s } end |
#find!(key) ⇒ Object
61 62 63 |
# File 'lib/buildkite/builder/step_collection.rb', line 61 def find!(key) find(key) || raise(ArgumentError, "Can't find step with key: #{key}") end |
#move(*movable_steps, before: nil, after: nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/buildkite/builder/step_collection.rb', line 47 def move(*movable_steps, before: nil, after: nil) raise ArgumentError, 'Specify either before or after' if before && after raise ArgumentError, 'Specify before or after' unless before || after movable_steps.each do |step| steps.delete(step) end index = steps.index(before || after) index += 1 if after steps.insert(index, *movable_steps) end |
#push(step) ⇒ Object
65 66 67 |
# File 'lib/buildkite/builder/step_collection.rb', line 65 def push(step) @steps.push(step) end |
#remove(step) ⇒ Object
39 40 41 |
# File 'lib/buildkite/builder/step_collection.rb', line 39 def remove(step) steps.delete(step) end |
#replace(old_step, new_step) ⇒ Object
43 44 45 |
# File 'lib/buildkite/builder/step_collection.rb', line 43 def replace(old_step, new_step) steps[steps.index(old_step)] = new_step end |
#to_definition ⇒ Object
69 70 71 |
# File 'lib/buildkite/builder/step_collection.rb', line 69 def to_definition @steps.map(&:to_h) end |