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 'app/validators/gitlab/emoji_name_validator.rb')
-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