Commit c2d6d61d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add DSL for adding nodes in Ci config interface

parent df25c196
......@@ -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'
......
......@@ -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
......
......@@ -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
......
......@@ -3,10 +3,6 @@ module Gitlab
class Config
module Node
class Null < Entry
def keys
{}
end
def method_missing(*)
nil
end
......
......@@ -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
......
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