summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-09 10:08:49 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-09 10:08:49 +0200
commit33cd090b93714e147e59195d24918e8b7c6d4614 (patch)
treeb2d41650bd8e153df93b18432a9f9331d2c6a879 /lib
parent48a59c1a8baf3921f26c8503a9fdd63bf7398f0f (diff)
downloadgitlab-ce-33cd090b93714e147e59195d24918e8b7c6d4614.tar.gz
Move new Ci config configurable DSL to concern
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/config/node/configurable.rb39
-rw-r--r--lib/gitlab/ci/config/node/entry.rb34
-rw-r--r--lib/gitlab/ci/config/node/global.rb2
3 files changed, 49 insertions, 26 deletions
diff --git a/lib/gitlab/ci/config/node/configurable.rb b/lib/gitlab/ci/config/node/configurable.rb
new file mode 100644
index 00000000000..9c04a1cdc08
--- /dev/null
+++ b/lib/gitlab/ci/config/node/configurable.rb
@@ -0,0 +1,39 @@
+module Gitlab
+ module Ci
+ class Config
+ module Node
+ module Configurable
+ extend ActiveSupport::Concern
+
+ def keys
+ self.class.nodes || {}
+ end
+
+ private
+
+ def add_node(key, entry_class)
+ if @value.has_key?(key)
+ entry = entry_class.new(@value[key], @root, self)
+ else
+ entry = Node::Null.new(nil, @root, self)
+ end
+
+ @nodes[key] = entry
+ end
+
+ class_methods do
+ attr_reader :nodes
+
+ private
+
+ def add_node(symbol, entry_class)
+ node = { symbol.to_sym => entry_class }
+
+ (@nodes ||= {}).merge!(node)
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb
index 302cded664f..c45744efdf5 100644
--- a/lib/gitlab/ci/config/node/entry.rb
+++ b/lib/gitlab/ci/config/node/entry.rb
@@ -20,8 +20,8 @@ module Gitlab
def process!
return if leaf? || invalid?
- keys.each do |key, entry_class|
- add_node(key, entry_class)
+ keys.each do |key, entry|
+ add_node(key, entry)
end
nodes.each(&:process!)
@@ -49,7 +49,7 @@ module Gitlab
end
def keys
- self.class.nodes || {}
+ {}
end
def errors
@@ -60,7 +60,11 @@ module Gitlab
super unless keys.has_key?(name)
raise InvalidError unless valid?
- @nodes[name].value
+ @nodes[name].try(:value)
+ end
+
+ def add_node(key, entry)
+ raise NotImplementedError
end
def value
@@ -74,28 +78,6 @@ module Gitlab
def description
raise NotImplementedError
end
-
- private
-
- def add_node(key, entry_class)
- if @value.has_key?(key)
- entry = entry_class.new(@value[key], @root, self)
- else
- entry = Node::Null.new(nil, @root, self)
- end
-
- @nodes[key] = entry
- 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
diff --git a/lib/gitlab/ci/config/node/global.rb b/lib/gitlab/ci/config/node/global.rb
index 2e899b0b2a3..5a176ab5eaf 100644
--- a/lib/gitlab/ci/config/node/global.rb
+++ b/lib/gitlab/ci/config/node/global.rb
@@ -3,6 +3,8 @@ module Gitlab
class Config
module Node
class Global < Entry
+ include Configurable
+
add_node :before_script, Script
end
end