2016-06-10 12:01:07 +00:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Node
|
|
|
|
##
|
|
|
|
# Factory class responsible for fabricating node entry objects.
|
|
|
|
#
|
|
|
|
class Factory
|
|
|
|
class InvalidFactory < StandardError; end
|
|
|
|
|
2016-06-22 12:26:33 +00:00
|
|
|
def initialize(node)
|
|
|
|
@node = node
|
2016-06-10 12:01:07 +00:00
|
|
|
@attributes = {}
|
|
|
|
end
|
|
|
|
|
2016-06-13 07:14:23 +00:00
|
|
|
def with(attributes)
|
|
|
|
@attributes.merge!(attributes)
|
2016-06-10 12:01:07 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def create!
|
|
|
|
raise InvalidFactory unless @attributes.has_key?(:value)
|
|
|
|
|
2016-06-23 08:07:42 +00:00
|
|
|
##
|
|
|
|
# We assume unspecified entry is undefined.
|
|
|
|
# See issue #18775.
|
|
|
|
#
|
|
|
|
if @attributes[:value].nil?
|
|
|
|
node, value = Node::Undefined, @node
|
|
|
|
else
|
|
|
|
node, value = @node, @attributes[:value]
|
|
|
|
end
|
|
|
|
|
|
|
|
node.new(value).tap do |entry|
|
2016-06-10 12:01:07 +00:00
|
|
|
entry.description = @attributes[:description]
|
2016-06-09 12:48:40 +00:00
|
|
|
entry.key = @attributes[:key]
|
2016-06-10 12:01:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|