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

40 lines
922 B
Ruby
Raw Normal View History

module Gitlab
module Ci
class Config
module Node
##
# Factory class responsible for fabricating node entry objects.
#
# It uses Fluent Interface pattern to set all necessary attributes.
#
class Factory
class InvalidFactory < StandardError; end
def initialize(entry_class)
@entry_class = entry_class
@attributes = {}
end
2016-06-13 07:14:23 +00:00
def with(attributes)
@attributes.merge!(attributes)
self
end
2016-06-13 07:14:23 +00:00
def nullify!
@entry_class = Node::Null
self
end
def create!
raise InvalidFactory unless @attributes.has_key?(:value)
@entry_class.new(@attributes[:value]).tap do |entry|
entry.description = @attributes[:description]
end
end
end
end
end
end
end