diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 00:12:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 00:12:08 +0300 |
commit | 840c85c174e4f134bdce103b8226d5a2a7bcd4ac (patch) | |
tree | db0e17d07c19265e3696bafe9bf570114b946dbb /app/validators | |
parent | ee2c09733d98492dcd992c567e0b44ab2838f798 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/gitlab/emoji_name_validator.rb | 19 |
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 |