summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-07 11:58:02 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-07 11:58:02 +0200
commit69a3755c5a93395fd2fdfd5bee00e6064d1670f8 (patch)
tree0d6dfd43cc863e5164e40e86695d96e8f5ec1d3e /lib
parentb95c60a0715b5639e70b64e04fd4923e8bdd1923 (diff)
downloadgitlab-ce-69a3755c5a93395fd2fdfd5bee00e6064d1670f8.tar.gz
Add Ci config entry that implements Null Object
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/config/node/entry.rb22
-rw-r--r--lib/gitlab/ci/config/node/null.rb17
2 files changed, 29 insertions, 10 deletions
diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb
index 007585d4019..af92899af40 100644
--- a/lib/gitlab/ci/config/node/entry.rb
+++ b/lib/gitlab/ci/config/node/entry.rb
@@ -5,22 +5,28 @@ module Gitlab
class Entry
include Config::ValidationHelpers
- attr_reader :value, :parent
+ attr_reader :value, :nodes, :parent
def initialize(value, config, parent = nil)
@value = value
@config = config
@parent = parent
- @nodes = {}
- @errors = []
+ @nodes, @errors = [], []
+
+ keys.each_key do |key|
+ instance_variable_set("@#{key}", Null.new(nil, config, self))
+ end
end
def process!
return if leaf?
- keys.each_pair do |key, entry|
- next unless @value.include?(key)
- @nodes[key] = entry.new(@value[key], @config, self)
+ keys.each do |key, entry_class|
+ next unless @value.has_key?(key)
+
+ entry = entry_class.new(@value[key], @config, self)
+ instance_variable_set("@#{key}", entry)
+ @nodes.append(entry)
end
nodes.each(&:process!)
@@ -31,10 +37,6 @@ module Gitlab
@errors + nodes.map(&:errors).flatten
end
- def nodes
- @nodes.values
- end
-
def valid?
errors.none?
end
diff --git a/lib/gitlab/ci/config/node/null.rb b/lib/gitlab/ci/config/node/null.rb
new file mode 100644
index 00000000000..6147b0d882f
--- /dev/null
+++ b/lib/gitlab/ci/config/node/null.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module Ci
+ class Config
+ module Node
+ class Null < Entry
+ def keys
+ {}
+ end
+
+ def method_missing(*)
+ nil
+ end
+ end
+ end
+ end
+ end
+end