Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/config/entry/validator.rb')
-rw-r--r--lib/gitlab/ci/config/entry/validator.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/gitlab/ci/config/entry/validator.rb b/lib/gitlab/ci/config/entry/validator.rb
new file mode 100644
index 00000000000..55343005fe3
--- /dev/null
+++ b/lib/gitlab/ci/config/entry/validator.rb
@@ -0,0 +1,42 @@
+module Gitlab
+ module Ci
+ class Config
+ module Entry
+ class Validator < SimpleDelegator
+ include ActiveModel::Validations
+ include Entry::Validators
+
+ def initialize(entry)
+ super(entry)
+ @entry = entry
+ 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
+ predecessors.append(key_name).join(':')
+ end
+
+ def key_name
+ if key.blank?
+ @entry.class.name.demodulize.underscore.humanize
+ else
+ key
+ end
+ end
+ end
+ end
+ end
+ end
+end