summaryrefslogtreecommitdiff
path: root/app/validators/gitlab/emoji_name_validator.rb
blob: a9092d0194ffa543c58aa5fd5f3fbfa978709440 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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