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