blob: c238ac8f18eb8633b3fa7fee097b3e01dda2fa7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
module Gitlab
module Ci
module Variables
class Collection
class Item
def initialize(**options)
@variable = {
key: options.fetch(:key),
value: options.fetch(:value),
public: options.fetch(:public, false),
file: options.fetch(:files, false)
}
end
def ==(other)
to_hash == self.class.fabricate(other).to_hash
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).
#
def to_hash
@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)
when ::Ci::Variable
self.new(resource.to_hash)
when ::Ci::PipelineVariable
self.new(resource.to_hash)
when self
resource.dup
else
raise ArgumentError, "Unknown `#{resource.class}` variable resource!"
end
end
end
end
end
end
end
|