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

43 lines
876 B
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
module Gitlab
module Ci
class Config
2017-08-17 22:00:37 +05:30
module Entry
2016-08-24 12:49:21 +05:30
class Validator < SimpleDelegator
include ActiveModel::Validations
2017-08-17 22:00:37 +05:30
include Entry::Validators
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
def initialize(entry)
super(entry)
@entry = entry
2016-08-24 12:49:21 +05:30
end
def messages
errors.full_messages.map do |error|
"#{location} #{error}".downcase
end
end
def self.name
'Validator'
end
private
def location
predecessors = ancestors.map(&:key).compact
2016-09-13 17:45:13 +05:30
predecessors.append(key_name).join(':')
end
def key_name
if key.blank?
2017-08-17 22:00:37 +05:30
@entry.class.name.demodulize.underscore.humanize
2016-09-13 17:45:13 +05:30
else
key
end
2016-08-24 12:49:21 +05:30
end
end
end
end
end
end