summaryrefslogtreecommitdiff
path: root/app/validators
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-10-19 21:12:08 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-10-19 21:12:08 +0000
commit840c85c174e4f134bdce103b8226d5a2a7bcd4ac (patch)
treedb0e17d07c19265e3696bafe9bf570114b946dbb /app/validators
parentee2c09733d98492dcd992c567e0b44ab2838f798 (diff)
downloadgitlab-ce-840c85c174e4f134bdce103b8226d5a2a7bcd4ac.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/gitlab/emoji_name_validator.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/validators/gitlab/emoji_name_validator.rb b/app/validators/gitlab/emoji_name_validator.rb
new file mode 100644
index 00000000000..a9092d0194f
--- /dev/null
+++ b/app/validators/gitlab/emoji_name_validator.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+# Gitlab::EmojiNameValidator
+#
+# Validates that the provided value matches an indexed emoji alpha code
+#
+# @example Usage
+# class AwardEmoji < ApplicationRecord
+# validate :name, 'gitlab/emoji_name': true
+# end
+module Gitlab
+ class EmojiNameValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ unless TanukiEmoji.find_by_alpha_code(value.to_s)
+ record.errors.add(attribute, (options[:message] || 'is not a valid emoji name'))
+ end
+ end
+ end
+end