emoji-validator 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8c78eaec76edabf318de16e9d31dbb156c7030c
|
4
|
+
data.tar.gz: 9e57b00fe7ba0a58b16bc55d0a7e6d5b3725445a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3f1109bf6b4f8de35efe93f4973843e481d306f2567dea535c38767e173cf154780a887b5a842a832e586fb853b8a5b97b8200fa657ab51d230c561ce6d5a50
|
7
|
+
data.tar.gz: b1f409270d37f485e1e5c85f495afe257da49c864b5b367886e2b1bd10db9993f5ab3e77c68e8948b07f3a3cb4139c526d721ba640552ef1bc5bd17de929fa40
|
data/lib/emoji/validator.rb
CHANGED
@@ -5,7 +5,7 @@ require 'emoji/validator/no_emoji_anywhere_validator'
|
|
5
5
|
require 'emoji/validator/no_emoji_validator'
|
6
6
|
|
7
7
|
module Emoji
|
8
|
-
# ActiveModel and ActiveRecord validators to prevent
|
8
|
+
# <tt>ActiveModel</tt> and <tt>ActiveRecord</tt> validators to prevent
|
9
9
|
# emojis from being present in your attributes
|
10
10
|
module Validator
|
11
11
|
# Your code goes here...
|
@@ -1,17 +1,18 @@
|
|
1
1
|
# rubocop:disable Style/AsciiComments
|
2
2
|
module Emoji
|
3
3
|
module Validator
|
4
|
-
# Validates all
|
4
|
+
# Validates all <tt>string</tt> and <tt>text</tt> attributes
|
5
|
+
# of an <tt>ActiveRecord::Base</tt> class
|
5
6
|
# Include it in your model to automatically apply the validation
|
6
|
-
# ```ruby
|
7
|
-
# class Person < ActiveRecord::Base
|
8
|
-
# include Emoji::Validator::NoEmojiAnywhereValidator
|
9
|
-
# end
|
10
7
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
8
|
+
# class Person < ActiveRecord::Base
|
9
|
+
# include Emoji::Validator::NoEmojiAnywhereValidator
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# person = Person.new(first_name: "😃", last_name: "😃")
|
13
|
+
# person.valid? #false
|
14
|
+
# person.errors.count #2
|
15
|
+
#
|
15
16
|
module NoEmojiAnywhereValidator
|
16
17
|
def self.included(base)
|
17
18
|
base.class_eval do
|
@@ -2,16 +2,16 @@
|
|
2
2
|
module Emoji
|
3
3
|
module Validator
|
4
4
|
# Validate an attribute against emojis
|
5
|
-
# ```ruby
|
6
|
-
# class Person < ApplicationRecord
|
7
|
-
# validates :first_name, no_emoji: true
|
8
|
-
# end
|
9
5
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
6
|
+
# class Person < ApplicationRecord
|
7
|
+
# validates :first_name, no_emoji: true
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# person = Person.new(first_name: "John", last_name: "😃")
|
11
|
+
# person.valid? #true
|
12
|
+
# person.first_name = "😃"
|
13
|
+
# person.valid? #false
|
14
|
+
#
|
15
15
|
class NoEmojiValidator < ActiveModel::EachValidator
|
16
16
|
def validate_each(record, attribute, value)
|
17
17
|
return if value.match(Unicode::Emoji::REGEX_ANY).nil?
|