Class: Gitlab::Ci::Variables::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gitlab/ci/variables/collection.rb,
lib/gitlab/ci/variables/collection/item.rb

Defined Under Namespace

Classes: Item

Instance Method Summary collapse

Constructor Details

#initialize(variables = []) ⇒ Collection

Returns a new instance of Collection.


9
10
11
12
13
# File 'lib/gitlab/ci/variables/collection.rb', line 9

def initialize(variables = [])
  @variables = []

  variables.each { |variable| self.append(variable) }
end

Instance Method Details

#+(other) ⇒ Object


29
30
31
32
33
34
# File 'lib/gitlab/ci/variables/collection.rb', line 29

def +(other)
  self.class.new.tap do |collection|
    self.each { |variable| collection.append(variable) }
    other.each { |variable| collection.append(variable) }
  end
end

#append(resource) ⇒ Object


15
16
17
# File 'lib/gitlab/ci/variables/collection.rb', line 15

def append(resource)
  tap { @variables.append(Collection::Item.fabricate(resource)) }
end

#concat(resources) ⇒ Object


19
20
21
22
23
# File 'lib/gitlab/ci/variables/collection.rb', line 19

def concat(resources)
  return self if resources.nil?

  tap { resources.each { |variable| self.append(variable) } }
end

#eachObject


25
26
27
# File 'lib/gitlab/ci/variables/collection.rb', line 25

def each
  @variables.each { |variable| yield variable }
end

#to_hashObject


40
41
42
43
44
# File 'lib/gitlab/ci/variables/collection.rb', line 40

def to_hash
  self.to_runner_variables
    .map { |env| [env.fetch(:key), env.fetch(:value)] }
    .to_h.with_indifferent_access
end

#to_runner_variablesObject


36
37
38
# File 'lib/gitlab/ci/variables/collection.rb', line 36

def to_runner_variables
  self.map(&:to_runner_variable)
end