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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f6a6ce26e15d4bde1afc0b72c52fdc7cdb2b1bee5c67d559a1e59c26c3f01a9
4
- data.tar.gz: bfd1e3d561a487613d71e6ef25c42dc7cff0b7ffb02ed58cc17dddf8f120f061
3
+ metadata.gz: 35147b0210c36fba2c92ccf367ac7971ec695037335a5992fe6ab4057f91b1d9
4
+ data.tar.gz: 45b57da9546f802c26fad4928708c5300ec9c82520c4e28e09cda345c1342fcc
5
5
  SHA512:
6
- metadata.gz: 4b0bf639a327bca0b5ce7448ec1a641f235f33ce4d873c9fd28b1c4f9922600ae4090ebf9317ab946199593e214ea34049eb801e78331b0ec6b2c82bd94ac60b
7
- data.tar.gz: d0489b3c90a4735cfc18e4eabb9c9e85e8482d7007646c42c26528e362b26573407d11d283fdc6d91056c830812032496bc51f3e498de1f9a9bd54a9ddef1256
6
+ metadata.gz: 905c27c5b7e6f8fe94112e346a84f956e289bb1c1c66a58c9a9c3f3ac0a5419e2d1ec5f2f957db57d93438da24d0418e1fb03051461d464315215eaab05dd3e9
7
+ data.tar.gz: ef4792acd3f5b1b118182473c580663f4960d09d2576004c95d54ad2666d2252ac74f18e64a2e7785ead19604416ff36d1577629b6bcb0301fe7f73621889281
@@ -12,7 +12,7 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  strategy:
14
14
  matrix:
15
- ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
15
+ ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4']
16
16
 
17
17
  steps:
18
18
  - uses: actions/checkout@v2
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 regex
26
-
27
- If you want to use a specific regular expression:
25
+ ### Bring your own logic
28
26
 
29
- validates :email, :email_address => {:format => /.+@.+\..+/}
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
- ### Bring your own logic
29
+ validates :email, :email_address => {:with => /.+@.+\..+/}
32
30
 
33
- If a regular expression isn't enough for you, you can include your own rules for email addresses. For example, you could validate that all email adresses belong to the same company:
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", "< 8.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"
@@ -1,3 +1,3 @@
1
1
  module ActiveModelEmailAddressValidator
2
- VERSION = "2.1.1.1"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -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
- rules = Array(options[:with] || [])
7
- if rules.empty?
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 build_rule_from_format(format)
38
+ def build_default_rule
38
39
  proc { |attribute_value|
39
40
  address =
40
41
  ActiveModelEmailAddressValidator::EmailAddress.new(attribute_value)
41
- address.valid?(format)
42
+ address.valid?
42
43
  }
43
44
  end
44
45
 
@@ -1,6 +1,6 @@
1
1
  require "minitest_helper"
2
2
 
3
- class EmailAddressValidTest < MiniTest::Test
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 < MiniTest::Test
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 < MiniTest::Test
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 test_validates_with_custom_regular_expression
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
- accept("whatever@enterprise.museum", subject)
39
- reject("totally@valid.com", subject)
38
+ assert_raises(ArgumentError) { subject.valid? }
40
39
  end
41
40
 
42
- def test_validates_with_custom_regular_as_a_rule
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: 2.1.1.1
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: 2023-01-18 00:00:00.000000000 Z
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: '8.0'
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: '8.0'
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.4.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