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
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def location
|
2016-06-29 07:39:04 +00:00
|
|
|
predecessors = ancestors.map(&:key).compact
|
2016-07-14 11:14:09 +00:00
|
|
|
predecessors.append(key_name).join(':')
|
|
|
|
end
|
|
|
|
|
|
|
|
def key_name
|
2016-07-18 13:38:06 +00:00
|
|
|
if key.blank?
|
2016-07-14 11:14:09 +00:00
|
|
|
@node.class.name.demodulize.underscore.humanize
|
|
|
|
else
|
|
|
|
key
|
|
|
|
end
|
2016-06-29 07:10:23 +00:00
|
|
|
end
|
2016-06-16 12:16:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|