summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-15 22:35:29 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-15 22:49:18 +0200
commit17084d42aa4f2a9d58d6b6d30656d5b7cfffe007 (patch)
treea0a67c65421ee9d7e788e4d744c034dff24e8312 /lib
parent4bb60b0789a31061cbc81af90b7d5dc558f985b3 (diff)
downloadgitlab-ce-17084d42aa4f2a9d58d6b6d30656d5b7cfffe007.tar.gz
Simplify abstract class for CI config entry nodes
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/config/node/configurable.rb12
-rw-r--r--lib/gitlab/ci/config/node/entry.rb17
-rw-r--r--lib/gitlab/ci/config/node/global.rb2
-rw-r--r--lib/gitlab/ci/config/node/jobs.rb31
4 files changed, 23 insertions, 39 deletions
diff --git a/lib/gitlab/ci/config/node/configurable.rb b/lib/gitlab/ci/config/node/configurable.rb
index 10b2db86d24..93a9a253322 100644
--- a/lib/gitlab/ci/config/node/configurable.rb
+++ b/lib/gitlab/ci/config/node/configurable.rb
@@ -25,12 +25,14 @@ module Gitlab
private
- def create(key, factory)
- factory
- .value(@config[key])
- .with(key: key, parent: self)
+ def compose!
+ self.class.nodes.each do |key, factory|
+ factory
+ .value(@config[key])
+ .with(key: key, parent: self)
- factory.create!
+ @entries[key] = factory.create!
+ end
end
class_methods do
diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb
index 559688c1bca..813e394e51b 100644
--- a/lib/gitlab/ci/config/node/entry.rb
+++ b/lib/gitlab/ci/config/node/entry.rb
@@ -28,11 +28,7 @@ module Gitlab
end
def leaf?
- nodes.none?
- end
-
- def nodes
- self.class.nodes
+ @entries.none?
end
def descendants
@@ -74,10 +70,6 @@ module Gitlab
def self.default
end
- def self.nodes
- {}
- end
-
def self.validator
Validator
end
@@ -85,13 +77,6 @@ module Gitlab
private
def compose!
- nodes.each do |key, essence|
- @entries[key] = create(key, essence)
- end
- end
-
- def create(entry, essence)
- raise NotImplementedError
end
end
end
diff --git a/lib/gitlab/ci/config/node/global.rb b/lib/gitlab/ci/config/node/global.rb
index 3b0d0113d61..b545b78a940 100644
--- a/lib/gitlab/ci/config/node/global.rb
+++ b/lib/gitlab/ci/config/node/global.rb
@@ -47,7 +47,7 @@ module Gitlab
def compose_jobs!
factory = Node::Factory.new(Node::Jobs)
- .value(@config.except(*nodes.keys))
+ .value(@config.except(*self.class.nodes.keys))
.with(key: :jobs, parent: self,
description: 'Jobs definition for this pipeline')
diff --git a/lib/gitlab/ci/config/node/jobs.rb b/lib/gitlab/ci/config/node/jobs.rb
index 77ff3459958..908c8f4f120 100644
--- a/lib/gitlab/ci/config/node/jobs.rb
+++ b/lib/gitlab/ci/config/node/jobs.rb
@@ -22,28 +22,25 @@ module Gitlab
end
end
- def nodes
- @config
- end
-
private
- def create(name, config)
- Node::Factory.new(job_class(name))
- .value(config || {})
- .metadata(name: name)
- .with(key: name, parent: self,
- description: "#{name} job definition.")
- .create!
- end
+ def compose!
+ @config.each do |name, config|
+ node = hidden?(name) ? Node::HiddenJob : Node::Job
- def job_class(name)
- if name.to_s.start_with?('.')
- Node::HiddenJob
- else
- Node::Job
+ factory = Node::Factory.new(node)
+ .value(config || {})
+ .metadata(name: name)
+ .with(key: name, parent: self,
+ description: "#{name} job definition.")
+
+ @entries[name] = factory.create!
end
end
+
+ def hidden?(name)
+ name.to_s.start_with?('.')
+ end
end
end
end