2018-03-12 08:58:54 -04:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
module Variables
|
|
|
|
class Collection
|
|
|
|
class Item
|
|
|
|
def initialize(**options)
|
|
|
|
@variable = {
|
|
|
|
key: options.fetch(:key),
|
|
|
|
value: options.fetch(:value),
|
2018-03-13 09:01:48 -04:00
|
|
|
public: options.fetch(:public, true),
|
2018-03-12 08:58:54 -04:00
|
|
|
file: options.fetch(:files, false)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-03-13 09:00:14 -04:00
|
|
|
def [](key)
|
|
|
|
@variable.fetch(key)
|
|
|
|
end
|
|
|
|
|
2018-03-12 08:58:54 -04:00
|
|
|
def ==(other)
|
2018-03-23 08:44:12 -04:00
|
|
|
to_runner_variable == self.class.fabricate(other).to_runner_variable
|
2018-03-12 08:58:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# If `file: true` has been provided we expose it, otherwise we
|
|
|
|
# don't expose `file` attribute at all (stems from what the runner
|
|
|
|
# expects).
|
|
|
|
#
|
2018-03-23 08:44:12 -04:00
|
|
|
def to_runner_variable
|
2018-03-12 08:58:54 -04:00
|
|
|
@variable.reject do |hash_key, hash_value|
|
|
|
|
hash_key == :file && hash_value == false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.fabricate(resource)
|
|
|
|
case resource
|
|
|
|
when Hash
|
|
|
|
self.new(resource)
|
2018-03-13 09:12:00 -04:00
|
|
|
when ::HasVariable
|
|
|
|
self.new(resource.to_runner_variable)
|
2018-03-12 08:58:54 -04:00
|
|
|
when self
|
|
|
|
resource.dup
|
|
|
|
else
|
2018-03-12 10:07:05 -04:00
|
|
|
raise ArgumentError, "Unknown `#{resource.class}` variable resource!"
|
2018-03-12 08:58:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|