debian-mirror-gitlab/lib/gitlab/ci/variables/collection.rb

49 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
module Gitlab
module Ci
module Variables
class Collection
include Enumerable
def initialize(variables = [])
@variables = []
variables.each { |variable| self.append(variable) }
end
def append(resource)
tap { @variables.append(Collection::Item.fabricate(resource)) }
end
def concat(resources)
2019-07-07 11:18:12 +05:30
return self if resources.nil?
2018-05-09 12:01:36 +05:30
tap { resources.each { |variable| self.append(variable) } }
end
def each
@variables.each { |variable| yield variable }
end
def +(other)
self.class.new.tap do |collection|
self.each { |variable| collection.append(variable) }
other.each { |variable| collection.append(variable) }
end
end
def to_runner_variables
self.map(&:to_runner_variable)
end
def to_hash
self.to_runner_variables
.map { |env| [env.fetch(:key), env.fetch(:value)] }
.to_h.with_indifferent_access
end
end
end
end
end