2016-06-16 12:16:33 +00:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Node
|
|
|
|
class Validator < SimpleDelegator
|
2016-06-17 07:33:32 +00:00
|
|
|
include ActiveModel::Validations
|
2016-06-17 10:06:48 +00:00
|
|
|
include Node::Validators
|
2016-06-17 07:33:32 +00:00
|
|
|
|
2016-06-16 12:16:33 +00:00
|
|
|
def initialize(node)
|
|
|
|
super(node)
|
2016-06-29 07:10:23 +00:00
|
|
|
@node = node
|
2016-06-16 12:16:33 +00:00
|
|
|
end
|
|
|
|
|
2016-06-23 11:51:34 +00:00
|
|
|
def messages
|
2016-06-16 12:16:33 +00:00
|
|
|
errors.full_messages.map do |error|
|
2016-06-29 07:39:04 +00:00
|
|
|
"#{location} #{error}".downcase
|
2016-06-16 12:16:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.name
|
|
|
|
'Validator'
|
|
|
|
end
|
2016-06-29 07:10:23 +00:00
|
|
|
|
2016-06-29 08:46:30 +00:00
|
|
|
def unknown_keys
|
|
|
|
return [] unless config.is_a?(Hash)
|
2016-07-04 09:37:28 +00:00
|
|
|
|
2016-06-29 08:46:30 +00:00
|
|
|
config.keys - @node.class.nodes.keys
|
|
|
|
end
|
|
|
|
|
2016-06-29 07:10:23 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def location
|
2016-06-29 07:39:04 +00:00
|
|
|
predecessors = ancestors.map(&:key).compact
|
2016-07-06 10:58:43 +00:00
|
|
|
current = key || @node.class.name.demodulize.underscore.humanize
|
2016-06-29 07:39:04 +00:00
|
|
|
predecessors.append(current).join(':')
|
2016-06-29 07:10:23 +00:00
|
|
|
end
|
2016-06-16 12:16:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|