Commit 12080ba1 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Simplify new ci config entry class interface

parent 828a15bc
...@@ -19,7 +19,7 @@ module Gitlab ...@@ -19,7 +19,7 @@ module Gitlab
def initialize(*) def initialize(*)
super super
unless leaf? || has_config? unless @value.is_a?(Hash)
@errors << 'should be a configuration entry with hash value' @errors << 'should be a configuration entry with hash value'
end end
end end
...@@ -39,9 +39,9 @@ module Gitlab ...@@ -39,9 +39,9 @@ module Gitlab
def create_entry(key, entry_class) def create_entry(key, entry_class)
if @value.has_key?(key) if @value.has_key?(key)
entry_class.new(@value[key], @root, self) entry_class.new(@value[key])
else else
Node::Null.new(nil, @root, self) Node::Null.new(nil)
end end
end end
......
...@@ -10,16 +10,15 @@ module Gitlab ...@@ -10,16 +10,15 @@ module Gitlab
attr_accessor :description attr_accessor :description
def initialize(value, root = nil, parent = nil) def initialize(value)
@value = value @value = value
@root = root
@parent = parent
@nodes = {} @nodes = {}
@errors = [] @errors = []
end end
def process! def process!
return if leaf? || invalid? return if leaf?
return unless valid?
compose! compose!
...@@ -41,18 +40,10 @@ module Gitlab ...@@ -41,18 +40,10 @@ module Gitlab
errors.none? errors.none?
end end
def invalid?
!valid?
end
def leaf? def leaf?
allowed_nodes.none? allowed_nodes.none?
end end
def has_config?
@value.is_a?(Hash)
end
def errors def errors
@errors + nodes.map(&:errors).flatten @errors + nodes.map(&:errors).flatten
end end
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node
## ##
# This class represents a configuration entry that is not being used # This class represents a configuration entry that is not being used
# in configuration file. # in configuration file.
# #
# This implements Null Object pattern. # This implements Null Object pattern.
# #
module Node
class Null < Entry class Null < Entry
def value def value
nil nil
......
...@@ -6,8 +6,8 @@ module Gitlab ...@@ -6,8 +6,8 @@ module Gitlab
# Entry that represents a script. # Entry that represents a script.
# #
# Each element in the value array is a command that will be executed # Each element in the value array is a command that will be executed
# by GitLab Runner. Currently we concatenate this commands with # by GitLab Runner. Currently we concatenate these commands with
# new line character as a separator what is compatbile with # new line character as a separator, what is compatible with
# implementation in Runner. # implementation in Runner.
# #
class Script < Entry class Script < Entry
......
...@@ -49,12 +49,6 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -49,12 +49,6 @@ describe Gitlab::Ci::Config::Node::Global do
end end
end end
describe '#has_config?' do
it 'has config' do
expect(global).to have_config
end
end
describe '#leaf?' do describe '#leaf?' do
it 'is not leaf' do it 'is not leaf' do
expect(global).not_to be_leaf expect(global).not_to be_leaf
...@@ -91,12 +85,6 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -91,12 +85,6 @@ describe Gitlab::Ci::Config::Node::Global do
end end
end end
describe '#invalid?' do
it 'is not valid' do
expect(global).to be_invalid
end
end
describe '#errors' do describe '#errors' do
it 'reports errors from child nodes' do it 'reports errors from child nodes' do
expect(global.errors) expect(global.errors)
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Null do describe Gitlab::Ci::Config::Node::Null do
let(:entry) { described_class.new(double, double) } let(:entry) { described_class.new(nil) }
describe '#leaf?' do describe '#leaf?' do
it 'is leaf node' do it 'is leaf node' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Script do describe Gitlab::Ci::Config::Node::Script do
let(:entry) { described_class.new(value, double)} let(:entry) { described_class.new(value) }
describe '#validate!' do
before { entry.validate! } before { entry.validate! }
context 'when entry value is correct' do context 'when entry value is correct' do
...@@ -19,9 +21,9 @@ describe Gitlab::Ci::Config::Node::Script do ...@@ -19,9 +21,9 @@ describe Gitlab::Ci::Config::Node::Script do
end end
end end
describe '#has_config?' do describe '#valid?' do
it 'does not have config' do it 'is valid' do
expect(entry).not_to have_config expect(entry).to be_valid
end end
end end
end end
...@@ -36,9 +38,10 @@ describe Gitlab::Ci::Config::Node::Script do ...@@ -36,9 +38,10 @@ describe Gitlab::Ci::Config::Node::Script do
end end
end end
describe '#invalid?' do describe '#valid?' do
it 'is not valid' do it 'is not valid' do
expect(entry).to be_invalid expect(entry).not_to be_valid
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