Module: Emoji::Validator::NoEmojiAnywhereValidator

Defined in:
lib/emoji/validator/no_emoji_anywhere_validator.rb

Overview

Validates all string and text attributes of an ActiveRecord::Base class Include it in your model to automatically apply the validation

class Person < ActiveRecord::Base
  include Emoji::Validator::NoEmojiAnywhereValidator
end

person = Person.new(first_name: "😃", last_name: "😃")
person.valid? #false
person.errors.count #2

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/emoji/validator/no_emoji_anywhere_validator.rb', line 19

def self.included(base)
  base.class_eval do
    columns_hash.each do |k, v|
      next unless %i[string text].include?(v.type)

      validates k, no_emoji: true
    end
  end
end