Add DSL for adding nodes in Ci config interface

This commit is contained in:
Grzegorz Bizon 2016-06-07 13:19:22 +02:00
parent df25c19699
commit c2d6d61dac
5 changed files with 16 additions and 12 deletions

View File

@ -5,10 +5,6 @@ module Gitlab
class BeforeScript < Entry
include ValidationHelpers
def keys
{}
end
def validate!
unless validate_array_of_strings(@value)
@errors << 'before_script should be an array of strings'

View File

@ -48,12 +48,22 @@ module Gitlab
end
def keys
raise NotImplementedError
self.class.nodes || {}
end
def validate!
raise NotImplementedError
end
class << self
attr_reader :nodes
private
def add_node(symbol, entry_class)
(@nodes ||= {}).merge!(symbol.to_sym => entry_class)
end
end
end
end
end

View File

@ -3,9 +3,7 @@ module Gitlab
class Config
module Node
class Global < Entry
def keys
{ before_script: BeforeScript }
end
add_node :before_script, BeforeScript
end
end
end

View File

@ -3,10 +3,6 @@ module Gitlab
class Config
module Node
class Null < Entry
def keys
{}
end
def method_missing(*)
nil
end

View File

@ -7,6 +7,10 @@ describe Gitlab::Ci::Config::Node::Global do
it 'can contain global config keys' do
expect(global.keys).to include :before_script
end
it 'returns a hash' do
expect(global.keys).to be_a Hash
end
end
context 'when hash is valid' do