gitlab-org--gitlab-foss/lib/gitlab/config/entry/factory.rb
Francisco Javier López 6ee1d8cf77 Add port section to CI Image object
In order to implement https://gitlab.com/gitlab-org/gitlab-ee/issues/10179
we need several modifications on the CI config file. We are
adding a new ports section in the default Image object.

Each of these ports will accept: number, protocol and name.

By default this new configuration will be only enabled in
the Web IDE config file.
2019-04-03 09:50:54 +00:00

74 lines
1.7 KiB
Ruby

# frozen_string_literal: true
module Gitlab
module Config
module Entry
##
# Factory class responsible for fabricating entry objects.
#
class Factory
InvalidFactory = Class.new(StandardError)
def initialize(entry)
@entry = entry
@metadata = {}
@attributes = { default: entry.default }
end
def value(value)
@value = value
self
end
def metadata(metadata)
@metadata.merge!(metadata.compact)
self
end
def with(attributes)
@attributes.merge!(attributes.compact)
self
end
def create!
raise InvalidFactory unless defined?(@value)
##
# We assume that unspecified entry is undefined.
# See issue #18775.
#
if @value.nil?
Entry::Unspecified.new(fabricate_unspecified)
else
fabricate(@entry, @value)
end
end
private
def fabricate_unspecified
##
# If entry has a default value we fabricate concrete node
# with default value.
#
default = @attributes.fetch(:default)
if default.nil?
fabricate(Entry::Undefined)
else
fabricate(@entry, default)
end
end
def fabricate(entry, value = nil)
entry.new(value, @metadata) do |node|
node.key = @attributes[:key]
node.parent = @attributes[:parent]
node.default = @attributes[:default]
node.description = @attributes[:description]
end
end
end
end
end
end