2016-06-07 05:58:02 -04:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Node
|
2016-06-10 05:20:46 -04:00
|
|
|
##
|
2016-06-22 08:26:33 -04:00
|
|
|
# This class represents an undefined entry node.
|
2016-06-10 05:20:46 -04:00
|
|
|
#
|
2016-07-07 06:41:31 -04:00
|
|
|
# It takes original entry class as configuration and creates an object
|
|
|
|
# if original entry has a default value. If there is default value
|
|
|
|
# some methods are delegated to it.
|
2016-06-10 05:20:46 -04:00
|
|
|
#
|
2016-06-22 04:44:33 -04:00
|
|
|
#
|
|
|
|
class Undefined < Entry
|
2016-06-22 08:26:33 -04:00
|
|
|
include Validatable
|
|
|
|
|
2016-07-07 07:09:36 -04:00
|
|
|
delegate :valid?, :errors, :value, to: :@strategy
|
|
|
|
|
2016-06-22 08:26:33 -04:00
|
|
|
validations do
|
|
|
|
validates :config, type: Class
|
|
|
|
end
|
|
|
|
|
2016-07-07 06:41:31 -04:00
|
|
|
def initialize(node)
|
|
|
|
super
|
2016-07-07 07:09:36 -04:00
|
|
|
@strategy = create_strategy(node, node.default)
|
2016-07-07 06:41:31 -04:00
|
|
|
end
|
|
|
|
|
2016-07-07 07:09:36 -04:00
|
|
|
def defined?
|
|
|
|
false
|
2016-07-07 06:41:31 -04:00
|
|
|
end
|
|
|
|
|
2016-07-07 07:09:36 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def create_strategy(node, default)
|
|
|
|
if default.nil?
|
|
|
|
Undefined::NullStrategy.new
|
|
|
|
else
|
|
|
|
entry = Node::Factory
|
|
|
|
.fabricate(node, default, attributes)
|
2016-07-07 06:41:31 -04:00
|
|
|
|
2016-07-07 07:09:36 -04:00
|
|
|
Undefined::DefaultStrategy.new(entry)
|
|
|
|
end
|
2016-06-07 05:58:02 -04:00
|
|
|
end
|
2016-06-23 07:51:07 -04:00
|
|
|
|
2016-07-07 07:09:36 -04:00
|
|
|
class DefaultStrategy
|
|
|
|
delegate :valid?, :errors, :value, to: :@default
|
|
|
|
|
|
|
|
def initialize(entry)
|
|
|
|
@default = entry
|
|
|
|
end
|
2016-06-23 07:51:07 -04:00
|
|
|
end
|
2016-07-07 06:41:31 -04:00
|
|
|
|
2016-07-07 07:09:36 -04:00
|
|
|
class NullStrategy
|
|
|
|
def initialize(*)
|
|
|
|
end
|
2016-07-07 06:41:31 -04:00
|
|
|
|
2016-07-07 07:09:36 -04:00
|
|
|
def value
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors
|
|
|
|
[]
|
|
|
|
end
|
2016-07-07 06:41:31 -04:00
|
|
|
end
|
2016-06-07 05:58:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|