debian-mirror-gitlab/lib/gitlab/ci/config/node/entry.rb

93 lines
1.8 KiB
Ruby
Raw Normal View History

module Gitlab
module Ci
class Config
module Node
##
# Base abstract class for each configuration entry node.
#
class Entry
class InvalidError < StandardError; end
2016-08-24 12:49:21 +05:30
attr_reader :config
attr_accessor :key, :parent, :description
2016-08-24 12:49:21 +05:30
def initialize(config)
@config = config
@nodes = {}
2016-08-24 12:49:21 +05:30
@validator = self.class.validator.new(self)
@validator.validate
end
def process!
return if leaf?
return unless valid?
compose!
2016-08-24 12:49:21 +05:30
process_nodes!
end
def nodes
@nodes.values
end
2016-08-24 12:49:21 +05:30
def leaf?
self.class.nodes.none?
end
2016-08-24 12:49:21 +05:30
def ancestors
@parent ? @parent.ancestors + [@parent] : []
end
def valid?
errors.none?
end
def errors
2016-08-24 12:49:21 +05:30
@validator.messages + nodes.flat_map(&:errors)
end
2016-08-24 12:49:21 +05:30
def value
if leaf?
@config
else
defined = @nodes.select { |_key, value| value.defined? }
Hash[defined.map { |key, node| [key, node.value] }]
end
end
2016-08-24 12:49:21 +05:30
def defined?
true
end
2016-08-24 12:49:21 +05:30
def self.default
end
2016-08-24 12:49:21 +05:30
def self.nodes
{}
end
2016-08-24 12:49:21 +05:30
def self.validator
Validator
end
2016-08-24 12:49:21 +05:30
private
def compose!
2016-08-24 12:49:21 +05:30
self.class.nodes.each do |key, essence|
@nodes[key] = create_node(key, essence)
end
end
2016-08-24 12:49:21 +05:30
def process_nodes!
nodes.each(&:process!)
end
def create_node(key, essence)
raise NotImplementedError
end
end
end
end
end
end