diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-13 13:42:57 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-13 13:42:57 +0200 |
commit | 097550f08a2a92dd1efff5da97cff0228afde57b (patch) | |
tree | 895c2d040fe41b3b4b7a8bb42d937ef6a6fff15a /lib | |
parent | de4c9a273867864a9033dab0624e0cfd72201384 (diff) | |
download | gitlab-ce-097550f08a2a92dd1efff5da97cff0228afde57b.tar.gz |
Fabricate CI entry with value, set attributes later
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/config/node/factory.rb | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/gitlab/ci/config/node/factory.rb b/lib/gitlab/ci/config/node/factory.rb index 602660acb93..339548e0feb 100644 --- a/lib/gitlab/ci/config/node/factory.rb +++ b/lib/gitlab/ci/config/node/factory.rb @@ -32,27 +32,39 @@ module Gitlab raise InvalidFactory unless defined?(@value) raise InvalidFactory unless defined?(@parent) - attributes = { parent: @parent, global: @parent.global } - attributes.merge!(@attributes) - ## # We assume that unspecified entry is undefined. # See issue #18775. # if @value.nil? - Node::Undefined.new(fabricate_undefined(attributes)) + Node::Undefined.new( + fabricate_undefined + ) else - @node.new(@value, attributes) + fabricate(@node, @value) end end private - def fabricate_undefined(attributes) + def fabricate_undefined + ## + # If node has a default value we fabricate concrete node + # with default value. + # if @node.default.nil? - Node::Null.new(nil, attributes) + fabricate(Node::Null) else - @node.new(@node.default, attributes) + fabricate(@node, @node.default) + end + end + + def fabricate(node, value = nil) + node.new(value).tap do |entry| + entry.key = @attributes[:key] + entry.parent = @attributes[:parent] || @parent + entry.global = @attributes[:global] || @parent.global + entry.description = @attributes[:description] end end end |