Commit ecdcf04e authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add undefined CI node strategies to handle defaults

parent de8b93bb
...@@ -13,38 +13,57 @@ module Gitlab ...@@ -13,38 +13,57 @@ module Gitlab
class Undefined < Entry class Undefined < Entry
include Validatable include Validatable
delegate :valid?, :errors, :value, to: :@strategy
validations do validations do
validates :config, type: Class validates :config, type: Class
end end
def initialize(node) def initialize(node)
super super
@strategy = create_strategy(node, node.default)
unless node.default.nil?
@default = fabricate_default(node)
end
end end
def value def defined?
@default.value if @default false
end end
def valid? private
@default ? @default.valid? : true
end def create_strategy(node, default)
if default.nil?
Undefined::NullStrategy.new
else
entry = Node::Factory
.fabricate(node, default, attributes)
def errors Undefined::DefaultStrategy.new(entry)
@default ? @default.errors : [] end
end end
def defined? class DefaultStrategy
false delegate :valid?, :errors, :value, to: :@default
def initialize(entry)
@default = entry
end
end end
private class NullStrategy
def initialize(*)
end
def fabricate_default(node) def value
Node::Factory.fabricate(node, node.default, attributes) nil
end
def valid?
true
end
def errors
[]
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment