activemodel-email_address_validator 2.1.1.1 → 3.0.0
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 +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/CHANGELOG.md +23 -0
- data/README.md +15 -6
- data/activemodel-email_address_validator.gemspec +1 -1
- data/lib/activemodel_email_address_validator/version.rb +1 -1
- data/lib/validator/email_address_validator.rb +7 -6
- data/test/activemodel-email_address_validator/test_email_address.rb +2 -2
- data/test/test_active_model_integration.rb +14 -5
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35147b0210c36fba2c92ccf367ac7971ec695037335a5992fe6ab4057f91b1d9
|
4
|
+
data.tar.gz: 45b57da9546f802c26fad4928708c5300ec9c82520c4e28e09cda345c1342fcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 905c27c5b7e6f8fe94112e346a84f956e289bb1c1c66a58c9a9c3f3ac0a5419e2d1ec5f2f957db57d93438da24d0418e1fb03051461d464315215eaab05dd3e9
|
7
|
+
data.tar.gz: ef4792acd3f5b1b118182473c580663f4960d09d2576004c95d54ad2666d2252ac74f18e64a2e7785ead19604416ff36d1577629b6bcb0301fe7f73621889281
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## Unreleased
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
-
|
13
|
+
|
14
|
+
### Removed
|
15
|
+
|
16
|
+
-
|
17
|
+
|
18
|
+
## [3.0.0]
|
19
|
+
|
20
|
+
### Added
|
21
|
+
|
22
|
+
- Support for ActiveModel 8 (no changes).
|
23
|
+
- Support for Ruby 3.3 and 3.4 (no changes).
|
24
|
+
|
25
|
+
### Removed
|
26
|
+
|
27
|
+
- Support for Rubies before 3.0.
|
28
|
+
- Passing a regular expression with :format is no longer supported. Use the
|
29
|
+
:with option instead.
|
30
|
+
|
8
31
|
## [2.1.1]
|
9
32
|
|
10
33
|
### Added
|
data/README.md
CHANGED
@@ -22,20 +22,29 @@ Quite frankly, I don't care about the RFC at this point, neither does the user.
|
|
22
22
|
|
23
23
|
validates :email, :email_address => true
|
24
24
|
|
25
|
-
### Bring your own
|
26
|
-
|
27
|
-
If you want to use a specific regular expression:
|
25
|
+
### Bring your own logic
|
28
26
|
|
29
|
-
|
27
|
+
If the default behavior isn't enough for you, you can include a custom rule for email addresses. For example to match the email addresses against a regular expression:
|
30
28
|
|
31
|
-
|
29
|
+
validates :email, :email_address => {:with => /.+@.+\..+/}
|
32
30
|
|
33
|
-
|
31
|
+
Or you could go beyound simple matching and validate that all email adresses belong to the same company:
|
34
32
|
|
35
33
|
validates :email, :email_address => {
|
36
34
|
:with => proc { |address| address.end_with?("@substancelab.com") }
|
37
35
|
}
|
38
36
|
|
37
|
+
You can even match against multiple rules, in which case all rules must pass:
|
38
|
+
|
39
|
+
validates :email, :email_address => {
|
40
|
+
:with => [
|
41
|
+
proc { |address| address.match(/.+@.+\..+/) },
|
42
|
+
proc { |address| !address.end_with?("@outlook.com") },
|
43
|
+
]
|
44
|
+
}
|
45
|
+
|
46
|
+
Do note that supplying your own rules means that the default email address validation isn't run - you're on your own, basically.
|
47
|
+
|
39
48
|
### Verify domain (still to be done - pull request, anybody?)
|
40
49
|
|
41
50
|
This also checks that the domain actually has an MX record. Note this might take a while because of DNS lookups.
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
16
|
spec.require_paths = ["lib"]
|
17
17
|
|
18
|
-
spec.add_dependency "activemodel", ">= 4.0", "<
|
18
|
+
spec.add_dependency "activemodel", ">= 4.0", "< 9.0"
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", ">= 1.7"
|
21
21
|
spec.add_development_dependency "rake", ">= 10.0"
|
@@ -3,12 +3,13 @@ require "activemodel_email_address_validator/email_address"
|
|
3
3
|
|
4
4
|
class EmailAddressValidator < ActiveModel::EachValidator
|
5
5
|
def validate_each(record, attribute, value)
|
6
|
-
|
7
|
-
|
8
|
-
# We are using the old syntax, assume regular expressions
|
9
|
-
rules = [build_rule_from_format(options[:format])]
|
6
|
+
if options[:format]
|
7
|
+
raise ArgumentError, "Don't use deprecated :format option. Use :with instead"
|
10
8
|
end
|
11
9
|
|
10
|
+
rules = Array(options[:with] || [])
|
11
|
+
rules << build_default_rule if rules.empty?
|
12
|
+
|
12
13
|
invalidate(record, attribute) unless all_rules_pass?(rules, value)
|
13
14
|
end
|
14
15
|
|
@@ -34,11 +35,11 @@ class EmailAddressValidator < ActiveModel::EachValidator
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
def
|
38
|
+
def build_default_rule
|
38
39
|
proc { |attribute_value|
|
39
40
|
address =
|
40
41
|
ActiveModelEmailAddressValidator::EmailAddress.new(attribute_value)
|
41
|
-
address.valid?
|
42
|
+
address.valid?
|
42
43
|
}
|
43
44
|
end
|
44
45
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "minitest_helper"
|
2
2
|
|
3
|
-
class EmailAddressValidTest <
|
3
|
+
class EmailAddressValidTest < Minitest::Test
|
4
4
|
def test_accepts_common_email_address_format
|
5
5
|
accept("bob@example.com")
|
6
6
|
end
|
@@ -153,7 +153,7 @@ class EmailAddressValidTest < MiniTest::Test
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
class EmailAddressTest <
|
156
|
+
class EmailAddressTest < Minitest::Test
|
157
157
|
def test_to_s_uses_address
|
158
158
|
email_address = ActiveModelEmailAddressValidator::EmailAddress.new(
|
159
159
|
"bob@example.com"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "minitest_helper"
|
2
2
|
require "active_model"
|
3
3
|
|
4
|
-
class EmailAddressValidatorTest <
|
4
|
+
class EmailAddressValidatorTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
@subject = build_model_with_validations
|
7
7
|
end
|
@@ -31,15 +31,14 @@ class EmailAddressValidatorTest < MiniTest::Test
|
|
31
31
|
assert !subject.errors[:work_email].empty?
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def test_fails_when_using_deprecated_format_option
|
35
35
|
subject = build_model_with_validations(
|
36
36
|
email: {email_address: {format: /.+@enterprise\..+/}}
|
37
37
|
)
|
38
|
-
|
39
|
-
reject("totally@valid.com", subject)
|
38
|
+
assert_raises(ArgumentError) { subject.valid? }
|
40
39
|
end
|
41
40
|
|
42
|
-
def
|
41
|
+
def test_validates_with_custom_regular_expression_as_a_rule
|
43
42
|
subject = build_model_with_validations(
|
44
43
|
email: {email_address: {with: /.+@enterprise\..+/}}
|
45
44
|
)
|
@@ -70,6 +69,16 @@ class EmailAddressValidatorTest < MiniTest::Test
|
|
70
69
|
reject("bob", subject)
|
71
70
|
end
|
72
71
|
|
72
|
+
def test_rules_overwrite_default_rule
|
73
|
+
subject = build_model_with_validations(
|
74
|
+
email: {email_address: {
|
75
|
+
with: proc { |address| true }
|
76
|
+
}}
|
77
|
+
)
|
78
|
+
|
79
|
+
accept("anything", subject)
|
80
|
+
end
|
81
|
+
|
73
82
|
private
|
74
83
|
|
75
84
|
def accept(email_address, subject)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel-email_address_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Skjerning
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '9.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '9.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.5.22
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: ActiveModel-style email address format validator
|