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 ...@@ -5,10 +5,6 @@ module Gitlab
class BeforeScript < Entry class BeforeScript < Entry
include ValidationHelpers include ValidationHelpers
def keys
{}
end
def validate! def validate!
unless validate_array_of_strings(@value) unless validate_array_of_strings(@value)
@errors << 'before_script should be an array of strings' @errors << 'before_script should be an array of strings'
......
...@@ -48,12 +48,22 @@ module Gitlab ...@@ -48,12 +48,22 @@ module Gitlab
end end
def keys def keys
raise NotImplementedError self.class.nodes || {}
end end
def validate! def validate!
raise NotImplementedError raise NotImplementedError
end 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 end
end end
......
...@@ -3,9 +3,7 @@ module Gitlab ...@@ -3,9 +3,7 @@ module Gitlab
class Config class Config
module Node module Node
class Global < Entry class Global < Entry
def keys add_node :before_script, BeforeScript
{ before_script: BeforeScript }
end
end end
end end
end end
......
...@@ -3,10 +3,6 @@ module Gitlab ...@@ -3,10 +3,6 @@ module Gitlab
class Config class Config
module Node module Node
class Null < Entry class Null < Entry
def keys
{}
end
def method_missing(*) def method_missing(*)
nil nil
end end
......
...@@ -7,6 +7,10 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -7,6 +7,10 @@ describe Gitlab::Ci::Config::Node::Global do
it 'can contain global config keys' do it 'can contain global config keys' do
expect(global.keys).to include :before_script expect(global.keys).to include :before_script
end end
it 'returns a hash' do
expect(global.keys).to be_a Hash
end
end end
context 'when hash is valid' do 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