summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-07 13:09:36 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-07 13:17:50 +0200
commitecdcf04e88f6313ae8773e7b9886bc983adab83d (patch)
treed197b9a388db42b3793253bc8132795c3ce3c4be
parentde8b93bbff65844438d7dfbde178746c3585bd92 (diff)
downloadgitlab-ce-ecdcf04e88f6313ae8773e7b9886bc983adab83d.tar.gz
Add undefined CI node strategies to handle defaults
-rw-r--r--lib/gitlab/ci/config/node/undefined.rb51
1 files changed, 35 insertions, 16 deletions
diff --git a/lib/gitlab/ci/config/node/undefined.rb b/lib/gitlab/ci/config/node/undefined.rb
index f152c433c42..7b18e364675 100644
--- a/lib/gitlab/ci/config/node/undefined.rb
+++ b/lib/gitlab/ci/config/node/undefined.rb
@@ -13,38 +13,57 @@ module Gitlab
class Undefined < Entry
include Validatable
+ delegate :valid?, :errors, :value, to: :@strategy
+
validations do
validates :config, type: Class
end
def initialize(node)
super
-
- unless node.default.nil?
- @default = fabricate_default(node)
- end
+ @strategy = create_strategy(node, node.default)
end
- def value
- @default.value if @default
+ def defined?
+ false
end
- def valid?
- @default ? @default.valid? : true
- end
+ private
+
+ def create_strategy(node, default)
+ if default.nil?
+ Undefined::NullStrategy.new
+ else
+ entry = Node::Factory
+ .fabricate(node, default, attributes)
- def errors
- @default ? @default.errors : []
+ Undefined::DefaultStrategy.new(entry)
+ end
end
- def defined?
- false
+ class DefaultStrategy
+ delegate :valid?, :errors, :value, to: :@default
+
+ def initialize(entry)
+ @default = entry
+ end
end
- private
+ class NullStrategy
+ def initialize(*)
+ end
- def fabricate_default(node)
- Node::Factory.fabricate(node, node.default, attributes)
+ def value
+ nil
+ end
+
+ def valid?
+ true
+ end
+
+ def errors
+ []
+ end
end
end
end