Extract CI configuration entry node factory method

This commit is contained in:
Grzegorz Bizon 2016-07-04 11:29:59 +02:00
parent b4f03e8b1e
commit eb151e77ff
1 changed files with 12 additions and 8 deletions

View File

@ -21,20 +21,24 @@ module Gitlab
def create!
raise InvalidFactory unless @attributes.has_key?(:value)
fabricate.tap do |entry|
entry.key = @attributes[:key]
entry.parent = @attributes[:parent]
entry.description = @attributes[:description]
end
end
private
def fabricate
##
# We assume that unspecified entry is undefined.
# See issue #18775.
#
if @attributes[:value].nil?
node, value = Node::Undefined, @node
Node::Undefined.new(@node)
else
node, value = @node, @attributes[:value]
end
node.new(value).tap do |entry|
entry.key = @attributes[:key]
entry.parent = @attributes[:parent]
entry.description = @attributes[:description]
@node.new(@attributes[:value])
end
end
end