gitlab-org--gitlab-foss/lib/gitlab/ci/config/node/factory.rb

44 lines
1.0 KiB
Ruby
Raw Normal View History

module Gitlab
module Ci
class Config
module Node
##
# Factory class responsible for fabricating node entry objects.
#
class Factory
class InvalidFactory < StandardError; end
def initialize(node)
@node = node
@attributes = {}
end
2016-06-13 07:14:23 +00:00
def with(attributes)
@attributes.merge!(attributes)
self
end
def create!
raise InvalidFactory unless @attributes.has_key?(:value)
##
# 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|
entry.description = @attributes[:description]
entry.key = @attributes[:key]
end
end
end
end
end
end
end