Commit 17084d42 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Simplify abstract class for CI config entry nodes

parent 4bb60b07
......@@ -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
......
......@@ -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
......
......@@ -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')
......
......@@ -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
......
......@@ -51,11 +51,11 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.descendants.second.description)
.to eq 'Docker image that will be used to execute jobs.'
end
end
describe '#leaf?' do
it 'is not leaf' do
expect(global).not_to be_leaf
describe '#leaf?' do
it 'is not leaf' do
expect(global).not_to be_leaf
end
end
end
......@@ -65,6 +65,12 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.before_script).to be nil
end
end
describe '#leaf?' do
it 'is leaf' do
expect(global).to be_leaf
end
end
end
context 'when processed' 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