BigW Consortium Gitlab

Commit 5065612a by Grzegorz Bizon

Add minor improvements in new Ci config design

parent 87fe50f2
......@@ -12,22 +12,16 @@ module Gitlab
@nodes = {}
@errors = []
unless leaf? || value.is_a?(Hash)
unless leaf? || has_config?
@errors << 'should be a configuration entry with hash value'
end
end
def process!
return if leaf? || !valid?
return if leaf? || invalid?
keys.each do |key, entry_class|
if @value.has_key?(key)
entry = entry_class.new(@value[key], @root, self)
else
entry = Node::Null.new(nil, @root, self)
end
@nodes[key] = entry
add_node(key, entry_class)
end
nodes.each(&:process!)
......@@ -38,22 +32,30 @@ module Gitlab
@nodes.values
end
def errors
@errors + nodes.map(&:errors).flatten
end
def valid?
errors.none?
end
def invalid?
!valid?
end
def leaf?
keys.none?
end
def has_config?
@value.is_a?(Hash)
end
def keys
self.class.nodes || {}
end
def errors
@errors + nodes.map(&:errors).flatten
end
def method_missing(name, *args)
super unless keys.has_key?(name)
raise InvalidError unless valid?
......@@ -73,6 +75,18 @@ module Gitlab
raise NotImplementedError
end
private
def add_node(key, entry_class)
if @value.has_key?(key)
entry = entry_class.new(@value[key], @root, self)
else
entry = Node::Null.new(nil, @root, self)
end
@nodes[key] = entry
end
class << self
attr_reader :nodes
......
......@@ -8,6 +8,7 @@ module Gitlab
end
def validate!
nil
end
def method_missing(*)
......
......@@ -18,6 +18,12 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
expect(entry.errors).to be_empty
end
end
describe '#has_config?' do
it 'does not have config' do
expect(entry).not_to have_config
end
end
end
context 'when entry value is not correct' do
......@@ -29,5 +35,11 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
.to include /should be an array of strings/
end
end
describe '#invalid?' do
it 'is not valid' do
expect(entry).to be_invalid
end
end
end
end
......@@ -35,6 +35,12 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
describe '#has_config?' do
it 'has config' do
expect(global).to have_config
end
end
describe '#leaf?' do
it 'is not leaf' do
expect(global).not_to be_leaf
......@@ -59,6 +65,12 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
describe '#invalid?' do
it 'is not valid' do
expect(global).to be_invalid
end
end
describe '#errors' do
it 'reports errors from child nodes' do
expect(global.errors)
......
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