2016-06-16 23:09:34 +05:30
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Node
|
|
|
|
##
|
|
|
|
# Factory class responsible for fabricating node entry objects.
|
|
|
|
#
|
|
|
|
class Factory
|
|
|
|
class InvalidFactory < StandardError; end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
def initialize(node)
|
|
|
|
@node = node
|
2016-06-16 23:09:34 +05:30
|
|
|
@attributes = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def with(attributes)
|
|
|
|
@attributes.merge!(attributes)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def create!
|
|
|
|
raise InvalidFactory unless @attributes.has_key?(:value)
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
fabricate.tap do |entry|
|
|
|
|
entry.key = @attributes[:key]
|
|
|
|
entry.parent = @attributes[:parent]
|
2016-06-16 23:09:34 +05:30
|
|
|
entry.description = @attributes[:description]
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def fabricate
|
|
|
|
##
|
|
|
|
# We assume that unspecified entry is undefined.
|
|
|
|
# See issue #18775.
|
|
|
|
#
|
|
|
|
if @attributes[:value].nil?
|
|
|
|
Node::Undefined.new(@node)
|
|
|
|
else
|
|
|
|
@node.new(@attributes[:value])
|
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|