Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/variables/collection.rb')
-rw-r--r--lib/gitlab/ci/variables/collection.rb33
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/gitlab/ci/variables/collection.rb b/lib/gitlab/ci/variables/collection.rb
index f7bbb58df7e..45e2c535d3a 100644
--- a/lib/gitlab/ci/variables/collection.rb
+++ b/lib/gitlab/ci/variables/collection.rb
@@ -6,14 +6,22 @@ module Gitlab
class Collection
include Enumerable
- def initialize(variables = [])
+ attr_reader :errors
+
+ def initialize(variables = [], errors = nil)
@variables = []
+ @variables_by_key = {}
+ @errors = errors
variables.each { |variable| self.append(variable) }
end
def append(resource)
- tap { @variables.append(Collection::Item.fabricate(resource)) }
+ item = Collection::Item.fabricate(resource)
+ @variables.append(item)
+ @variables_by_key[item[:key]] = item
+
+ self
end
def concat(resources)
@@ -33,14 +41,31 @@ module Gitlab
end
end
+ def [](key)
+ @variables_by_key[key]
+ end
+
+ def size
+ @variables.size
+ 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
+ .to_h { |env| [env.fetch(:key), env.fetch(:value)] }
+ .with_indifferent_access
+ end
+
+ def reject(&block)
+ Collection.new(@variables.reject(&block))
+ end
+
+ # Returns a sorted Collection object, and sets errors property in case of an error
+ def sorted_collection(project)
+ Sort.new(self, project).collection
end
end
end