Commit 69a3755c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add Ci config entry that implements Null Object

parent b95c60a0
......@@ -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
......
module Gitlab
module Ci
class Config
module Node
class Null < Entry
def keys
{}
end
def method_missing(*)
nil
end
end
end
end
end
end
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Null do
let(:entry) { described_class.new(double, double) }
describe '#leaf?' do
it 'is leaf node' do
expect(entry).to be_leaf
end
end
describe '#any_method' do
it 'responds with nil' do
expect(entry.any_method).to be nil
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