Sha256: 579eb71e0d338bf6cee1871b765ae1797eb6f0c87123dfbf5544392074c196d4

Contents?: true

Size: 797 Bytes

Versions: 2

Compression:

Stored size: 797 Bytes

Contents

# rubocop:disable Style/AsciiComments
module Emoji
  module Validator
    # Validates all `string` and `text` attributes of ActiveRecord::Base class
    # Include it in your model to automatically apply the validation
    # ```ruby
    # class Person < ActiveRecord::Base
    #   include Emoji::Validator::NoEmojiAnywhereValidator
    # end
    #
    # person = Person.new(first_name: "😃", last_name: "😃")
    # person.valid? #false
    # person.errors.count #2
    # ```
    module NoEmojiAnywhereValidator
      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
    end
  end
end
# rubocop:enable Style/AsciiComments

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
emoji-validator-0.1.1 lib/emoji/validator/no_emoji_anywhere_validator.rb
emoji-validator-0.1.0 lib/emoji/validator/no_emoji_anywhere_validator.rb