summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-08-16 15:01:27 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-09-04 14:17:01 +0200
commitef26622d62fe37371adf0d66c81f8428ad4bb1b6 (patch)
tree112a10b9c37bcf5df0dd199b88b48d9b5fa4a05a /lib
parent58414c143f928aa229ae871541cd35df293d6f54 (diff)
downloadgitlab-ce-ef26622d62fe37371adf0d66c81f8428ad4bb1b6.tar.gz
Do not modify extensible CI/CD entries by reference
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/config/extendable/collection.rb7
-rw-r--r--lib/gitlab/ci/config/extendable/entry.rb24
2 files changed, 13 insertions, 18 deletions
diff --git a/lib/gitlab/ci/config/extendable/collection.rb b/lib/gitlab/ci/config/extendable/collection.rb
index 4ffc4d91c82..3a71e06e3e2 100644
--- a/lib/gitlab/ci/config/extendable/collection.rb
+++ b/lib/gitlab/ci/config/extendable/collection.rb
@@ -7,16 +7,15 @@ module Gitlab
ExtensionError = Class.new(StandardError)
- def initialize(hash, context = hash)
+ def initialize(hash)
@hash = hash
- @context = context
end
def each
@hash.each_pair do |key, value|
next unless value.key?(:extends)
- yield Extendable::Entry.new(key, value, @context)
+ yield Extendable::Entry.new(key, @hash)
end
end
@@ -24,7 +23,7 @@ module Gitlab
each do |entry|
raise ExtensionError unless entry.valid?
- @hash[entry.key] = entry.extend!
+ entry.extend!
end
end
end
diff --git a/lib/gitlab/ci/config/extendable/entry.rb b/lib/gitlab/ci/config/extendable/entry.rb
index a39fa127e80..5844cb098b9 100644
--- a/lib/gitlab/ci/config/extendable/entry.rb
+++ b/lib/gitlab/ci/config/extendable/entry.rb
@@ -5,10 +5,9 @@ module Gitlab
class Entry
attr_reader :key
- def initialize(key, value, context, parent = nil)
+ def initialize(key, hash, parent = nil)
@key = key
- @value = value
- @context = context
+ @hash = hash
@parent = parent
end
@@ -16,32 +15,29 @@ module Gitlab
true
end
- # def circular_dependency?
- # @extends.to_s == @key.to_s
- # end
+ def value
+ @value ||= @hash.fetch(@key)
+ end
def base
Extendable::Entry
- .new(extends, @context.fetch(extends), @context, self)
+ .new(extends, @hash, self)
.extend!
end
def extensible?
- @value.key?(:extends)
+ value.key?(:extends)
end
def extends
- @value.fetch(:extends).to_sym
+ value.fetch(:extends).to_sym
end
def extend!
if extensible?
- original = @value.dup
- parent = base.dup
-
- @value.clear.deep_merge!(parent).deep_merge!(original)
+ @hash[key] = base.deep_merge(value)
else
- @value.to_h
+ value
end
end
end