Skip to content
Snippets Groups Projects
Commit 69a3755c authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Add Ci config entry that implements Null Object

parent b95c60a0
No related branches found
No related tags found
1 merge request!4482Add global entry with before script to new CI config
Pipeline #
Loading
@@ -5,22 +5,28 @@ module Gitlab
Loading
@@ -5,22 +5,28 @@ module Gitlab
class Entry class Entry
include Config::ValidationHelpers include Config::ValidationHelpers
   
attr_reader :value, :parent attr_reader :value, :nodes, :parent
   
def initialize(value, config, parent = nil) def initialize(value, config, parent = nil)
@value = value @value = value
@config = config @config = config
@parent = parent @parent = parent
@nodes = {} @nodes, @errors = [], []
@errors = []
keys.each_key do |key|
instance_variable_set("@#{key}", Null.new(nil, config, self))
end
end end
   
def process! def process!
return if leaf? return if leaf?
   
keys.each_pair do |key, entry| keys.each do |key, entry_class|
next unless @value.include?(key) next unless @value.has_key?(key)
@nodes[key] = entry.new(@value[key], @config, self)
entry = entry_class.new(@value[key], @config, self)
instance_variable_set("@#{key}", entry)
@nodes.append(entry)
end end
   
nodes.each(&:process!) nodes.each(&:process!)
Loading
@@ -31,10 +37,6 @@ module Gitlab
Loading
@@ -31,10 +37,6 @@ module Gitlab
@errors + nodes.map(&:errors).flatten @errors + nodes.map(&:errors).flatten
end end
   
def nodes
@nodes.values
end
def valid? def valid?
errors.none? errors.none?
end end
Loading
Loading
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment