2016-06-16 23:09:34 +05:30
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
2017-08-17 22:00:37 +05:30
|
|
|
module Entry
|
2016-06-16 23:09:34 +05:30
|
|
|
##
|
2017-08-17 22:00:37 +05:30
|
|
|
# Factory class responsible for fabricating entry objects.
|
2016-06-16 23:09:34 +05:30
|
|
|
#
|
|
|
|
class Factory
|
2017-08-17 22:00:37 +05:30
|
|
|
InvalidFactory = Class.new(StandardError)
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def initialize(entry)
|
|
|
|
@entry = entry
|
2016-09-13 17:45:13 +05:30
|
|
|
@metadata = {}
|
2016-06-16 23:09:34 +05:30
|
|
|
@attributes = {}
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def value(value)
|
|
|
|
@value = value
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def metadata(metadata)
|
|
|
|
@metadata.merge!(metadata)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def with(attributes)
|
|
|
|
@attributes.merge!(attributes)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def create!
|
2016-09-13 17:45:13 +05:30
|
|
|
raise InvalidFactory unless defined?(@value)
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
##
|
|
|
|
# We assume that unspecified entry is undefined.
|
|
|
|
# See issue #18775.
|
|
|
|
#
|
|
|
|
if @value.nil?
|
2017-08-17 22:00:37 +05:30
|
|
|
Entry::Unspecified.new(
|
2016-09-29 09:46:39 +05:30
|
|
|
fabricate_unspecified
|
2016-09-13 17:45:13 +05:30
|
|
|
)
|
|
|
|
else
|
2017-08-17 22:00:37 +05:30
|
|
|
fabricate(@entry, @value)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def fabricate_unspecified
|
2016-08-24 12:49:21 +05:30
|
|
|
##
|
2017-08-17 22:00:37 +05:30
|
|
|
# If entry has a default value we fabricate concrete node
|
2016-09-13 17:45:13 +05:30
|
|
|
# with default value.
|
2016-08-24 12:49:21 +05:30
|
|
|
#
|
2017-08-17 22:00:37 +05:30
|
|
|
if @entry.default.nil?
|
|
|
|
fabricate(Entry::Undefined)
|
2016-08-24 12:49:21 +05:30
|
|
|
else
|
2017-08-17 22:00:37 +05:30
|
|
|
fabricate(@entry, @entry.default)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def fabricate(entry, value = nil)
|
|
|
|
entry.new(value, @metadata).tap do |node|
|
|
|
|
node.key = @attributes[:key]
|
|
|
|
node.parent = @attributes[:parent]
|
|
|
|
node.description = @attributes[:description]
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|