email_address 0.2.5 → 0.2.6

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: 5a0acf217d99455d8e47f25dc21b4ff25478234932c8618f3d5fe0fe4629e433
4
- data.tar.gz: 5da4449168ec63611c8e510efd010b12995502b3162c67d3222c46cbabbbe6e8
3
+ metadata.gz: f6fb959ca75da2d73ed378a3b2f97b4dceead14d634cf24ff5ce18c5a52f0e4a
4
+ data.tar.gz: 47dd7dcb50a3e11b99d2be141dc1e3737b41b7a2b0f13ec80fb83ef59bc68d15
5
5
  SHA512:
6
- metadata.gz: 1703377fdf988adabaaf4d728db211320a1f33cf0daeeabd68448cf4a4d02b8647fcb9aad636d0aa14250386b8c8d2ede3cb89b42b55ffa2af793b1f788a9a08
7
- data.tar.gz: 15d5b84368e692e6ce08db5ad596ec1ef684f87c70a8db4d1a2d69ab977c72ed5b5f80d9945fc6cdf42af3af5581a9f3a55b26c9138370ce228ad663c758f387
6
+ metadata.gz: '097d2fa911cef5a006f7280e569107fcba3c18a025597fc89a18fb542e49bb4603efd1bae6ad39d68f9514ed26b27ea4e7890f018a32fa7e6d80ee608ebb6f4e'
7
+ data.tar.gz: 1c688907c73eb2dad9d64793fda1f2a8baece32f694710f9384a50cb92584c59b169f425d776e7d85a918d17cdcd5995f063fe8143f559d27241103f8e6114d5
@@ -28,16 +28,16 @@ module EmailAddress
28
28
  @opt[:fields].each { |f| validate_email(r, f) }
29
29
  elsif @opt[:field]
30
30
  validate_email(r, @opt[:field])
31
- elsif r.respond_to? :email
32
- validate_email(r, :email)
33
- elsif r.respond_to? :email_address
34
- validate_email(r, :email_address)
31
+ else
32
+ validate_email(r, :email) || validate_email(r, :email_address)
35
33
  end
36
34
  end
37
35
 
38
36
  def validate_email(r, f)
39
- return if r[f].nil?
40
- e = Address.new(r[f])
37
+ v = field_value(r, f)
38
+ return if v.nil?
39
+
40
+ e = Address.new(v)
41
41
  unless e.valid?
42
42
  error_code = @opt[:code] || :invalid_address
43
43
  error_message = @opt[:message] ||
@@ -46,5 +46,17 @@ module EmailAddress
46
46
  r.errors.add(f, error_code, message: error_message)
47
47
  end
48
48
  end
49
+
50
+ def field_value(r, f)
51
+ if r.respond_to?(f)
52
+ r.send(f)
53
+ elsif r[f]
54
+ r[f]
55
+ else
56
+ nil
57
+ end
58
+ rescue NoMethodError
59
+ nil
60
+ end
49
61
  end
50
62
  end
@@ -36,7 +36,7 @@ module EmailAddress
36
36
  MAX_HOST_LENGTH = 255
37
37
 
38
38
  # Sometimes, you just need a Regexp...
39
- DNS_HOST_REGEX = / [\p{L}\p{N}]+ (?: (?: -{1,2} | \.) [\p{L}\p{N}]+ )*/x
39
+ DNS_HOST_REGEX = / [\p{L}\p{N}]+ (?: (?: -{1,3} | \.) [\p{L}\p{N}]+ )*/x
40
40
 
41
41
  # The IPv4 and IPv6 were lifted from Resolv::IPv?::Regex and tweaked to not
42
42
  # \A...\z anchor at the edges.
@@ -1,3 +1,3 @@
1
1
  module EmailAddress
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -34,4 +34,14 @@ class TestAR < MiniTest::Test
34
34
  end
35
35
  end
36
36
  end
37
+
38
+ def test_store_accessor_valid_email
39
+ user = User.new(support_email: "test@gmail.com")
40
+ assert user.valid?
41
+ end
42
+
43
+ def test_store_accessor_invalid_email
44
+ user = User.new(support_email: "this_is_not_an_email")
45
+ assert_equal false, user.valid?
46
+ end
37
47
  end
@@ -45,6 +45,8 @@ end
45
45
  ################################################################################
46
46
 
47
47
  class User < ApplicationRecord
48
+ store :settings, accessors: [ :support_email ], coder: JSON
49
+
48
50
  if defined?(ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
49
51
  attribute :email, :email_address
50
52
  attribute :canonical_email, :canonical_email_address
@@ -52,7 +54,7 @@ class User < ApplicationRecord
52
54
  end
53
55
 
54
56
  validates_with EmailAddress::ActiveRecordValidator,
55
- fields: %i[email canonical_email]
57
+ fields: %i[email canonical_email support_email]
56
58
  validates_with EmailAddress::ActiveRecordValidator,
57
59
  field: :alternate_email, code: :some_error_code, message: "Check your email"
58
60
 
@@ -161,4 +161,9 @@ class TestHost < MiniTest::Test
161
161
  assert !EmailAddress::Host.new("zaboz.com").valid?
162
162
  assert EmailAddress::Host.new("zaboz.com", dns_lookup: :a).valid?
163
163
  end
164
+
165
+ # Issue #102 off---white.com should be valid
166
+ def test_triple_dash_domain
167
+ assert EmailAddress::Host.new("off---white.com").valid?
168
+ end
164
169
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_address
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Fair
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  - !ruby/object:Gem::Version
264
264
  version: '0'
265
265
  requirements: []
266
- rubygems_version: 3.6.2
266
+ rubygems_version: 3.6.9
267
267
  specification_version: 4
268
268
  summary: This gem provides a ruby language library for working with and validating
269
269
  email addresses. By default, it validates against conventional usage, the format