email_address 0.1.17 → 0.1.18

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: 8835c0835419dbf67cab6698b47d8641e5839036685727d4e5ed0e455caef6f4
4
- data.tar.gz: 553e9787f16788dce7bcff2d9b0d1f962deb03c575b35d2131a93a1c6795fd08
3
+ metadata.gz: 2a5ff67ec79e4de2d356293664296391fc8296ad6a6ba08f1d1256e93f7c729c
4
+ data.tar.gz: 5485014c6f886d9a382c046f9025948eeed6c114accde2957424f1f613d1b51b
5
5
  SHA512:
6
- metadata.gz: b1be9796aa6e245c623b940e0254cd303726439c0382c8f30e4b3d444c97dbd5575bbec5e61745621c1a8e5a39e764dad0b19a1200c64a1187978db8c9664a04
7
- data.tar.gz: 7c395ddbacdb048c96b8ceeeed2504ebbf42acc8c68b9d1424811cb22156789f2844704ba2919841065421242830ec180fa13fbd810976f2ea02bec0626c60a3
6
+ metadata.gz: 336f61eb9e81ccf8fe859b0d05e5e4d1aaf734e06328169ce919a01fdf30caaebdb2f44e673b52cdde99e3790c413c854e486fd97e4c610b5ee6349c1e3dbe40
7
+ data.tar.gz: c08f83be388d6fdb646ea46439c0a65543091e401b9c9d38e312a7d2dc34313c3269f9c16916340d090f48ae224a1cd18631153d6478f87e32073f38e319ff28
data/README.md CHANGED
@@ -552,6 +552,33 @@ The value is an array of match tokens.
552
552
  * host_match: %w(.org example.com hotmail. user*@ sub.*.com)
553
553
  * exchanger_match: %w(google.com 127.0.0.1 10.9.8.0/24 ::1/64)
554
554
 
555
+ ### Namespace conflict resolution
556
+
557
+ If your application already uses the `EmailAddress` class name,
558
+ it's possible to create an alias prior to loading your code:
559
+
560
+ For a Rails application, you can do this in `config/application.rb`
561
+ after the `Bundler.require` line, usually:
562
+
563
+ ```ruby
564
+ Bundler.require(*Rails.groups)
565
+ ```
566
+
567
+ Add these lines immediately after that point:
568
+
569
+ ```ruby
570
+ EmailAddressValidator = EmailAddress
571
+ Object.send(:remove_const, :EmailAddress)
572
+ ```
573
+
574
+ Then your application loads with your EmailAddress class. You may
575
+ then use this gem with `EmailAddressValidator` or whatever name you
576
+ gave it above:
577
+
578
+ ```ruby
579
+ EmailAddressValidator.valid?("clark.kent@gmail.com") # => true
580
+ ```
581
+
555
582
  ## Notes
556
583
 
557
584
  #### Internationalization
@@ -40,31 +40,30 @@ module EmailAddress
40
40
  # secret to use in options[:secret]
41
41
  class << self
42
42
  (%i[valid? error normal redact munge canonical reference base srs] &
43
- EmailAddress::Address.public_instance_methods
43
+ Address.public_instance_methods
44
44
  ).each do |proxy_method|
45
45
  define_method(proxy_method) do |*args, &block|
46
- EmailAddress::Address.new(*args).public_send(proxy_method, &block)
46
+ Address.new(*args).public_send(proxy_method, &block)
47
47
  end
48
48
  end
49
- end
50
-
51
49
 
52
- # Creates an instance of this email address.
53
- # This is a short-cut to Email::Address::Address.new
54
- def self.new(email_address, config={})
55
- EmailAddress::Address.new(email_address, config)
56
- end
50
+ # Creates an instance of this email address.
51
+ # This is a short-cut to EmailAddress::Address.new
52
+ def new(email_address, config={})
53
+ Address.new(email_address, config)
54
+ end
57
55
 
58
- def self.new_redacted(email_address, config={})
59
- EmailAddress::Address.new(EmailAddress::Address.new(email_address, config).redact)
60
- end
56
+ def new_redacted(email_address, config={})
57
+ Address.new(Address.new(email_address, config).redact)
58
+ end
61
59
 
62
- def self.new_canonical(email_address, config={})
63
- EmailAddress::Address.new(EmailAddress::Address.new(email_address, config).canonical, config)
64
- end
60
+ def new_canonical(email_address, config={})
61
+ Address.new(Address.new(email_address, config).canonical, config)
62
+ end
65
63
 
66
- # Does the email address match any of the given rules
67
- def self.matches?(email_address, rules, config={})
68
- EmailAddress::Address.new(email_address, config).matches?(rules)
64
+ # Does the email address match any of the given rules
65
+ def matches?(email_address, rules, config={})
66
+ Address.new(email_address, config).matches?(rules)
67
+ end
69
68
  end
70
69
  end
@@ -35,10 +35,10 @@ module EmailAddress
35
35
 
36
36
  def validate_email(r,f)
37
37
  return if r[f].nil?
38
- e = EmailAddress.new(r[f])
38
+ e = Address.new(r[f])
39
39
  unless e.valid?
40
40
  r.errors[f] << (@opt[:message] ||
41
- EmailAddress::Config.error_messages[:invalid_address] ||
41
+ Config.error_messages[:invalid_address] ||
42
42
  "Invalid Email Address")
43
43
  end
44
44
  end
@@ -5,32 +5,32 @@ require "digest/md5"
5
5
 
6
6
  module EmailAddress
7
7
  # Implements the Email Address container, which hold the Local
8
- # (EmailAddress::Local) and Host (Email::AddressHost) parts.
8
+ # (EmailAddress::Local) and Host (EmailAddress::Host) parts.
9
9
  class Address
10
10
  include Comparable
11
- include EmailAddress::Rewriter
11
+ include Rewriter
12
12
 
13
13
  attr_accessor :original, :local, :host, :config, :reason
14
14
 
15
- CONVENTIONAL_REGEX = /\A#{::EmailAddress::Local::CONVENTIONAL_MAILBOX_WITHIN}
16
- @#{::EmailAddress::Host::DNS_HOST_REGEX}\z/x
17
- STANDARD_REGEX = /\A#{::EmailAddress::Local::STANDARD_LOCAL_WITHIN}
18
- @#{::EmailAddress::Host::DNS_HOST_REGEX}\z/x
19
- RELAXED_REGEX = /\A#{::EmailAddress::Local::RELAXED_MAILBOX_WITHIN}
20
- @#{::EmailAddress::Host::DNS_HOST_REGEX}\z/x
15
+ CONVENTIONAL_REGEX = /\A#{Local::CONVENTIONAL_MAILBOX_WITHIN}
16
+ @#{Host::DNS_HOST_REGEX}\z/x
17
+ STANDARD_REGEX = /\A#{Local::STANDARD_LOCAL_WITHIN}
18
+ @#{Host::DNS_HOST_REGEX}\z/x
19
+ RELAXED_REGEX = /\A#{Local::RELAXED_MAILBOX_WITHIN}
20
+ @#{Host::DNS_HOST_REGEX}\z/x
21
21
 
22
22
  # Given an email address of the form "local@hostname", this sets up the
23
23
  # instance, and initializes the address to the "normalized" format of the
24
24
  # address. The original string is available in the #original method.
25
25
  def initialize(email_address, config = {})
26
- @config = EmailAddress::Config.new(config)
26
+ @config = Config.new(config)
27
27
  @original = email_address
28
28
  email_address = (email_address || "").strip
29
29
  email_address = parse_rewritten(email_address) unless config[:skip_rewrite]
30
- local, host = EmailAddress::Address.split_local_host(email_address)
30
+ local, host = Address.split_local_host(email_address)
31
31
 
32
- @host = EmailAddress::Host.new(host, @config)
33
- @local = EmailAddress::Local.new(local, @config, @host)
32
+ @host = Host.new(host, @config)
33
+ @local = Local.new(local, @config, @host)
34
34
  @error = @error_message = nil
35
35
  end
36
36
 
@@ -114,7 +114,7 @@ module EmailAddress
114
114
  alias to_s normal
115
115
 
116
116
  def inspect
117
- "#<EmailAddress::Address:0x#{object_id.to_s(16)} address=\"#{self}\">"
117
+ "#<#{self.class}:0x#{object_id.to_s(16)} address=\"#{self}\">"
118
118
  end
119
119
 
120
120
  # Returns the canonical email address according to the provider
@@ -190,7 +190,7 @@ module EmailAddress
190
190
  # of this addres with another, using the canonical or redacted forms.
191
191
  def same_as?(other_email)
192
192
  if other_email.is_a?(String)
193
- other_email = EmailAddress::Address.new(other_email)
193
+ other_email = Address.new(other_email)
194
194
  end
195
195
 
196
196
  canonical == other_email.canonical ||
@@ -276,7 +276,7 @@ module EmailAddress
276
276
  def set_error(err, reason = nil)
277
277
  @error = err
278
278
  @reason = reason
279
- @error_message = EmailAddress::Config.error_message(err)
279
+ @error_message = Config.error_message(err)
280
280
  false
281
281
  end
282
282
 
@@ -29,20 +29,22 @@
29
29
  # user.canonical_email #=> "patsmith@gmail.com"
30
30
  ################################################################################
31
31
 
32
- class EmailAddress::CanonicalEmailAddressType < ActiveRecord::Type::Value
32
+ module EmailAddress
33
+ class CanonicalEmailAddressType < ActiveRecord::Type::Value
33
34
 
34
- # From user input, setter
35
- def cast(value)
36
- super(EmailAddress.canonical(value))
37
- end
35
+ # From user input, setter
36
+ def cast(value)
37
+ super(Address.new(value).canonical)
38
+ end
38
39
 
39
- # From a database value
40
- def deserialize(value)
41
- value && EmailAddress.normal(value)
42
- end
40
+ # From a database value
41
+ def deserialize(value)
42
+ value && Address.new(value).normal
43
+ end
43
44
 
44
- # To a database value (string)
45
- def serialize(value)
46
- value && EmailAddress.normal(value)
45
+ # To a database value (string)
46
+ def serialize(value)
47
+ value && Address.new(value).normal
48
+ end
47
49
  end
48
50
  end
@@ -201,7 +201,7 @@ module EmailAddress
201
201
  end
202
202
 
203
203
  def initialize(overrides = {})
204
- @config = EmailAddress::Config.all_settings(overrides)
204
+ @config = Config.all_settings(overrides)
205
205
  end
206
206
 
207
207
  def []=(setting, value)
@@ -29,20 +29,22 @@
29
29
  # user.canonical_email #=> "patsmith@gmail.com"
30
30
  ################################################################################
31
31
 
32
- class EmailAddress::EmailAddressType < ActiveRecord::Type::Value
32
+ module EmailAddress
33
+ class EmailAddressType < ActiveRecord::Type::Value
33
34
 
34
- # From user input, setter
35
- def cast(value)
36
- super(EmailAddress.normal(value))
37
- end
35
+ # From user input, setter
36
+ def cast(value)
37
+ super(Address.new(value).normal)
38
+ end
38
39
 
39
- # From a database value
40
- def deserialize(value)
41
- value && EmailAddress.normal(value)
42
- end
43
- #
44
- # To a database value (string)
45
- def serialize(value)
46
- value && EmailAddress.normal(value)
40
+ # From a database value
41
+ def deserialize(value)
42
+ value && Address.new(value).normal
43
+ end
44
+
45
+ # To a database value (string)
46
+ def serialize(value)
47
+ value && Address.new(value).normal
48
+ end
47
49
  end
48
50
  end
@@ -24,7 +24,7 @@ module EmailAddress
24
24
 
25
25
  def initialize(host, config = {})
26
26
  @host = host
27
- @config = config.is_a?(Hash) ? EmailAddress::Config.new(config) : config
27
+ @config = config.is_a?(Hash) ? Config.new(config) : config
28
28
  @dns_disabled = @config[:host_validation] == :syntax || @config[:dns_lookup] == :off
29
29
  end
30
30
 
@@ -38,7 +38,7 @@ module EmailAddress
38
38
  # Returns the provider name based on the MX-er host names, or nil if not matched
39
39
  def provider
40
40
  return @provider if defined? @provider
41
- EmailAddress::Config.providers.each do |provider, config|
41
+ Config.providers.each do |provider, config|
42
42
  if config[:exchanger_match] && matches?(config[:exchanger_match])
43
43
  return @provider = provider
44
44
  end
@@ -76,7 +76,7 @@ module EmailAddress
76
76
 
77
77
  # Returns Array of domain names for the MX'ers, used to determine the Provider
78
78
  def domains
79
- @_domains ||= mxers.map { |m| EmailAddress::Host.new(m.first).domain_name }.sort.uniq
79
+ @_domains ||= mxers.map { |m| Host.new(m.first).domain_name }.sort.uniq
80
80
  end
81
81
 
82
82
  # Returns an array of MX IP address (String) for the given email domain
@@ -87,7 +87,7 @@ module EmailAddress
87
87
  def initialize(host_name, config = {})
88
88
  @original = host_name ||= ""
89
89
  config[:host_type] ||= :email
90
- @config = config.is_a?(Hash) ? EmailAddress::Config.new(config) : config
90
+ @config = config.is_a?(Hash) ? Config.new(config) : config
91
91
  @error = @error_message = nil
92
92
  parse(host_name)
93
93
  end
@@ -209,7 +209,7 @@ module EmailAddress
209
209
  def find_provider # :nodoc:
210
210
  return provider if provider
211
211
 
212
- EmailAddress::Config.providers.each do |provider, config|
212
+ Config.providers.each do |provider, config|
213
213
  if config[:host_match] && matches?(config[:host_match])
214
214
  return set_provider(provider, config)
215
215
  end
@@ -233,7 +233,7 @@ module EmailAddress
233
233
  end
234
234
 
235
235
  def hosted_provider
236
- EmailAddress::Exchanger.cached(dns_name).provider
236
+ Exchanger.cached(dns_name).provider
237
237
  end
238
238
 
239
239
  ############################################################################
@@ -338,11 +338,11 @@ module EmailAddress
338
338
  @_dns_a_record ||= []
339
339
  end
340
340
 
341
- # Returns an array of EmailAddress::Exchanger hosts configured in DNS.
341
+ # Returns an array of Exchanger hosts configured in DNS.
342
342
  # The array will be empty if none are configured.
343
343
  def exchangers
344
344
  # return nil if @config[:host_type] != :email || !self.dns_enabled?
345
- @_exchangers ||= EmailAddress::Exchanger.cached(dns_name, @config)
345
+ @_exchangers ||= Exchanger.cached(dns_name, @config)
346
346
  end
347
347
 
348
348
  # Returns a DNS TXT Record
@@ -497,7 +497,7 @@ module EmailAddress
497
497
  def set_error(err, reason = nil)
498
498
  @error = err
499
499
  @reason = reason
500
- @error_message = EmailAddress::Config.error_message(err)
500
+ @error_message = Config.error_message(err)
501
501
  false
502
502
  end
503
503
 
@@ -107,7 +107,7 @@ module EmailAddress
107
107
  %r/^([\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+)$/i.freeze
108
108
 
109
109
  def initialize(local, config={}, host=nil)
110
- @config = config.is_a?(Hash) ? EmailAddress::Config.new(config) : config
110
+ @config = config.is_a?(Hash) ? Config.new(config) : config
111
111
  self.local = local
112
112
  @host = host
113
113
  @error = @error_message = nil
@@ -388,7 +388,7 @@ module EmailAddress
388
388
  def set_error(err, reason=nil)
389
389
  @error = err
390
390
  @reason= reason
391
- @error_message = EmailAddress::Config.error_message(err)
391
+ @error_message = Config.error_message(err)
392
392
  false
393
393
  end
394
394
 
@@ -1,3 +1,3 @@
1
1
  module EmailAddress
2
- VERSION = "0.1.17"
2
+ VERSION = "0.1.18"
3
3
  end
@@ -0,0 +1,54 @@
1
+ # encoding: UTF-8
2
+ require_relative 'test_helper'
3
+
4
+ class TestAliasing < MiniTest::Test
5
+ def setup
6
+ Object.send(:const_set, :EmailAddressValidator, EmailAddress)
7
+ Object.send(:remove_const, :EmailAddress)
8
+ end
9
+
10
+ def test_email_address_not_defined
11
+ assert_nil defined?(EmailAddress)
12
+ assert_nil defined?(EmailAddress::Address)
13
+ assert_nil defined?(EmailAddress::Config)
14
+ assert_nil defined?(EmailAddress::Exchanger)
15
+ assert_nil defined?(EmailAddress::Host)
16
+ assert_nil defined?(EmailAddress::Local)
17
+ assert_nil defined?(EmailAddress::Rewriter)
18
+ end
19
+
20
+ def test_alias_defined
21
+ assert_equal defined?(EmailAddressValidator), "constant"
22
+ assert_equal defined?(EmailAddressValidator::Address), "constant"
23
+ assert_equal defined?(EmailAddressValidator::Config), "constant"
24
+ assert_equal defined?(EmailAddressValidator::Exchanger), "constant"
25
+ assert_equal defined?(EmailAddressValidator::Host), "constant"
26
+ assert_equal defined?(EmailAddressValidator::Local), "constant"
27
+ assert_equal defined?(EmailAddressValidator::Rewriter), "constant"
28
+ end
29
+
30
+ def test_alias_class_methods
31
+ assert_equal true, EmailAddressValidator.valid?("user@yahoo.com")
32
+ end
33
+
34
+ def test_alias_host_methods
35
+ assert_equal true, EmailAddressValidator::Host.new("yahoo.com").valid?
36
+ end
37
+
38
+ def test_alias_address_methods
39
+ assert_equal true, EmailAddressValidator::Address.new("user@yahoo.com").valid?
40
+ end
41
+
42
+ def test_alias_config_methods
43
+ assert Hash, EmailAddressValidator::Config.new.to_h
44
+ end
45
+
46
+ def test_alias_local_methods
47
+ assert_equal true, EmailAddressValidator::Local.new("user").valid?
48
+ end
49
+
50
+ def teardown
51
+ Object.send(:const_set, :EmailAddress, EmailAddressValidator)
52
+ Object.send(:remove_const, :EmailAddressValidator)
53
+ end
54
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_address
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Fair
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-10 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -162,13 +162,14 @@ files:
162
162
  - test/email_address/test_host.rb
163
163
  - test/email_address/test_local.rb
164
164
  - test/email_address/test_rewriter.rb
165
+ - test/test_aliasing.rb
165
166
  - test/test_email_address.rb
166
167
  - test/test_helper.rb
167
168
  homepage: https://github.com/afair/email_address
168
169
  licenses:
169
170
  - MIT
170
171
  metadata: {}
171
- post_install_message:
172
+ post_install_message:
172
173
  rdoc_options: []
173
174
  require_paths:
174
175
  - lib
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  version: '0'
185
186
  requirements: []
186
187
  rubygems_version: 3.0.6
187
- signing_key:
188
+ signing_key:
188
189
  specification_version: 4
189
190
  summary: This gem provides a ruby language library for working with and validating
190
191
  email addresses. By default, it validates against conventional usage, the format
@@ -199,5 +200,6 @@ test_files:
199
200
  - test/email_address/test_host.rb
200
201
  - test/email_address/test_local.rb
201
202
  - test/email_address/test_rewriter.rb
203
+ - test/test_aliasing.rb
202
204
  - test/test_email_address.rb
203
205
  - test/test_helper.rb