valid_email2 1.2.22 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +27 -7
- data/gemfiles/activemodel3.gemfile +3 -3
- data/gemfiles/activemodel4.gemfile +3 -3
- data/gemfiles/activemodel5.gemfile +5 -0
- data/lib/email_validator.rb +10 -0
- data/lib/valid_email2.rb +1 -0
- data/lib/valid_email2/email_validator.rb +22 -20
- data/lib/valid_email2/version.rb +1 -1
- data/spec/valid_email2_spec.rb +16 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea9b203a1d3faf3c116e75dfa87249eef2771056
|
4
|
+
data.tar.gz: e8dd47bc33c9f5d1a7e8e9fa65ceee9f28b53cb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ef8ca38e7b4727ab80125cfc5ce2cdf13b2f4de6660ec3c88fcd6bde42fcb2be6ff8545f7fa4cd74e15041c36fcd69ab84f754c03a6e20b63bb4de1c631bf4a
|
7
|
+
data.tar.gz: 044148fdb6e8095d70f2de16e197d21715a975d7142f3c33bba5dc83a1e9d1be93346eb6ed2a40db4e5c871efed0a5d9b6fa8b34d2256f133664dfbc16e59515
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## Version 2.0.0
|
2
|
+
Add validator namespaced under `ValidEmail2` https://github.com/lisinge/valid_email2/pull/79
|
3
|
+
Deprecate global `EmailValidator` in favor of the namespaced one.
|
4
|
+
|
1
5
|
## Version 1.2.22
|
2
6
|
Added more disposable email domains (https://github.com/lisinge/valid_email2/pull/80)
|
3
7
|
|
data/README.md
CHANGED
@@ -39,28 +39,28 @@ Or install it yourself as:
|
|
39
39
|
If you just want to validate that it is a valid email address:
|
40
40
|
```ruby
|
41
41
|
class User < ActiveRecord::Base
|
42
|
-
validates :email, presence: true, email: true
|
42
|
+
validates :email, presence: true, 'valid_email_2/email': true
|
43
43
|
end
|
44
44
|
```
|
45
45
|
|
46
46
|
To validate that the domain has a MX record:
|
47
47
|
```ruby
|
48
|
-
validates :email, email: { mx: true }
|
48
|
+
validates :email, 'valid_email_2/email': { mx: true }
|
49
49
|
```
|
50
50
|
|
51
51
|
To validate that the domain is not a disposable email:
|
52
52
|
```ruby
|
53
|
-
validates :email, email: { disposable: true }
|
53
|
+
validates :email, 'valid_email_2/email': { disposable: true }
|
54
54
|
```
|
55
55
|
|
56
56
|
To validate that the domain is not blacklisted (under vendor/blacklist.yml):
|
57
57
|
```ruby
|
58
|
-
validates :email, email: { blacklist: true }
|
58
|
+
validates :email, 'valid_email_2/email': { blacklist: true }
|
59
59
|
```
|
60
60
|
|
61
61
|
All together:
|
62
62
|
```ruby
|
63
|
-
validates :email, email: { mx: true, disposable: true }
|
63
|
+
validates :email, 'valid_email_2/email': { mx: true, disposable: true }
|
64
64
|
```
|
65
65
|
|
66
66
|
> Note that this gem will let an empty email pass through so you will need to
|
@@ -89,10 +89,30 @@ end
|
|
89
89
|
## Requirements
|
90
90
|
|
91
91
|
This gem requires Rails 3.2 or 4.0 or higher. It is tested against both versions using:
|
92
|
-
* Ruby-2.0
|
93
|
-
* Ruby-2.1
|
94
92
|
* Ruby-2.2
|
95
93
|
* Ruby-2.3
|
94
|
+
* Ruby-2.4
|
95
|
+
|
96
|
+
## Upgrading to v2.0.0
|
97
|
+
|
98
|
+
In version 1.0 of valid_email2 we only defined the `email` validator.
|
99
|
+
But since other gems also define a `email` validator this can cause some unintended
|
100
|
+
behaviours and emails that shouldn't be valid are regarded valid because the
|
101
|
+
wrong validator is used by rails.
|
102
|
+
|
103
|
+
So in version 2.0 we decided to deprecate using the `email` validator directly
|
104
|
+
and instead define a `valid_email_2/email` validator to be sure that the correct
|
105
|
+
validator gets used.
|
106
|
+
|
107
|
+
So this:
|
108
|
+
```ruby
|
109
|
+
validates :email, email: { mx: true, disposable: true }
|
110
|
+
```
|
111
|
+
|
112
|
+
Becomes this:
|
113
|
+
```ruby
|
114
|
+
validates :email, 'valid_email_2/email': { mx: true, disposable: true }
|
115
|
+
```
|
96
116
|
|
97
117
|
## Contributing
|
98
118
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# This is a shim for keeping backwards compatibility.
|
2
|
+
# See the discussion in: https://github.com/lisinge/valid_email2/pull/79
|
3
|
+
class EmailValidator < ValidEmail2::EmailValidator
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
warn "DEPRECATION WARNING: The email validator from valid_email2 has been " +
|
6
|
+
"deprecated in favour of using the namespaced 'valid_email_2/email' validator. " +
|
7
|
+
"For more information see https://github.com/lisinge/valid_email2#upgrading-to-v200"
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
data/lib/valid_email2.rb
CHANGED
@@ -2,33 +2,35 @@ require "valid_email2/address"
|
|
2
2
|
require "active_model"
|
3
3
|
require "active_model/validations"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module ValidEmail2
|
6
|
+
class EmailValidator < ActiveModel::EachValidator
|
7
|
+
def default_options
|
8
|
+
{ regex: true, disposable: false, mx: false }
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def validate_each(record, attribute, value)
|
12
|
+
return unless value.present?
|
13
|
+
options = default_options.merge(self.options)
|
13
14
|
|
14
|
-
|
15
|
+
address = ValidEmail2::Address.new(value)
|
15
16
|
|
16
|
-
|
17
|
+
error(record, attribute) && return unless address.valid?
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
if options[:disposable]
|
20
|
+
error(record, attribute) && return if address.disposable?
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
if options[:blacklist]
|
24
|
+
error(record, attribute) && return if address.blacklisted?
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
if options[:mx]
|
28
|
+
error(record, attribute) && return unless address.valid_mx?
|
29
|
+
end
|
28
30
|
end
|
29
|
-
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
def error(record, attribute)
|
33
|
+
record.errors.add(attribute, options[:message] || :invalid)
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
data/lib/valid_email2/version.rb
CHANGED
data/spec/valid_email2_spec.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
class TestUser < TestModel
|
4
|
-
validates :email, email: true
|
4
|
+
validates :email, 'valid_email_2/email': true
|
5
5
|
end
|
6
6
|
|
7
7
|
class TestUserMX < TestModel
|
8
|
-
validates :email, email: { mx: true }
|
8
|
+
validates :email, 'valid_email_2/email': { mx: true }
|
9
9
|
end
|
10
10
|
|
11
11
|
class TestUserDisallowDisposable < TestModel
|
12
|
-
validates :email, email: { disposable: true }
|
12
|
+
validates :email, 'valid_email_2/email': { disposable: true }
|
13
13
|
end
|
14
14
|
|
15
15
|
class TestUserDisallowBlacklisted < TestModel
|
16
|
-
validates :email, email: { blacklist: true }
|
16
|
+
validates :email, 'valid_email_2/email': { blacklist: true }
|
17
|
+
end
|
18
|
+
|
19
|
+
class BackwardsCompatibleUser < TestModel
|
20
|
+
validates :email, email: true
|
17
21
|
end
|
18
22
|
|
19
23
|
describe ValidEmail2 do
|
@@ -44,6 +48,14 @@ describe ValidEmail2 do
|
|
44
48
|
user = TestUser.new(email: "foo@bar..com")
|
45
49
|
expect(user.valid?).to be_falsey
|
46
50
|
end
|
51
|
+
|
52
|
+
it "still works with the backwards-compatible syntax" do
|
53
|
+
user = BackwardsCompatibleUser.new(email: "foo@bar.com")
|
54
|
+
expect(user.valid?).to be_truthy
|
55
|
+
|
56
|
+
user = BackwardsCompatibleUser.new(email: "foo@bar")
|
57
|
+
expect(user.valid?).to be_falsey
|
58
|
+
end
|
47
59
|
end
|
48
60
|
|
49
61
|
describe "disposable emails" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valid_email2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micke Lisinge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,6 +97,8 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- gemfiles/activemodel3.gemfile
|
99
99
|
- gemfiles/activemodel4.gemfile
|
100
|
+
- gemfiles/activemodel5.gemfile
|
101
|
+
- lib/email_validator.rb
|
100
102
|
- lib/valid_email2.rb
|
101
103
|
- lib/valid_email2/address.rb
|
102
104
|
- lib/valid_email2/email_validator.rb
|