email_address 0.1.14 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f3decf66b46d08f8a8f3528ad331cfb009f7dfa302b8f887558bb535e189210
4
- data.tar.gz: a5aac0f73f92ae103cada5c57b5f51a7efb968752dfe5ab8710b72a52705c98a
3
+ metadata.gz: adfafdd9c68cbc88c13f77175ab945fce253b0c67d93cbf92f27d95358d9286d
4
+ data.tar.gz: 07ea20d4fddbc9a2626a870b40162fe5ecaedfd7f588ba56f8d9efffce9a4eac
5
5
  SHA512:
6
- metadata.gz: 6acd7e0c108cadaa5be29dc0d843c3d12311d96791f79130b6c1ed2a1e26c3e3c2838f40034504d74bd2717dd35947e789c39c72fd0c7470aaefec23167983c8
7
- data.tar.gz: bf7f061c707cac898ca51fd4bb8a697ad0c491be4a3119ded9c836e9ef8257ad3c513a2562c9803b415bbea8e747e5ae8c54805c00b03cfd4825a7b2754a5229
6
+ metadata.gz: 45005aaae90329115140e038aa9f17325d66a939de376a2efc0fdda6542a1b47850ae40b80503fd69e1308f3cfe2fb5392904d2ca5ba0f997b00b6712e01ccb9
7
+ data.tar.gz: e69900c156e676aac54f5f2d3ca395f08f08d07f768913df990d8b3c012e12e5cda678145f1dcdb0d141691ebf93d2beb85ba3b8dd654522fbb121962529585c
@@ -1,9 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.7.0
4
- - 2.3.7
4
+ - 2.3.0
5
5
  - jruby-9.2.9.0
6
- #- rbx
7
6
 
8
7
  addons:
9
8
  code_climate:
data/README.md CHANGED
@@ -50,7 +50,7 @@ It does not check:
50
50
  By default, MX records are required in DNS. MX or "mail exchanger" records
51
51
  tell where to deliver email for the domain. Many domains run their
52
52
  website on one provider (ISP, Heroku, etc.), and email on a different
53
- provider (such as Google Apps). Note that `example.com`, while
53
+ provider (such as G Suite). Note that `example.com`, while
54
54
  a valid domain name, does not have MX records.
55
55
 
56
56
  ```ruby
@@ -248,6 +248,16 @@ EmailAddress.normal("HIRO@こんにちは世界.com")
248
248
  EmailAddress.normal("hiro@xn--28j2a3ar1pp75ovm7c.com", host_encoding: :unicode)
249
249
  #=> "hiro@こんにちは世界.com"
250
250
  ```
251
+ As of release 0.1.17, exchanger_match is no longer used for host provider
252
+ determination, which designated the set of rules for that domain.
253
+ Sometimes, as in Google-hosted domains, the address
254
+ rules are different, notably the optional dots in mailboxes for gmail.com
255
+ accounts do not apply to other private domains hosted at google.
256
+
257
+ To access the provider service, you can now call:
258
+
259
+ EmailAddress.new("user@hosteddomain.com").host.hosted_provider
260
+
251
261
 
252
262
  #### Rails Validator
253
263
 
@@ -534,14 +544,38 @@ For the mailbox (AKA account, role), without the tag
534
544
  * address_size: 3..254,
535
545
  A range specifying the size limit of the complete address
536
546
 
537
- * address_local: false,
538
- Allow localhost, no domain, or local subdomains.
539
-
540
547
  For provider rules to match to domain names and Exchanger hosts
541
548
  The value is an array of match tokens.
542
549
  * host_match: %w(.org example.com hotmail. user*@ sub.*.com)
543
550
  * exchanger_match: %w(google.com 127.0.0.1 10.9.8.0/24 ::1/64)
544
551
 
552
+ ### Namespace conflict resolution
553
+
554
+ If your application already uses the `EmailAddress` class name,
555
+ it's possible to create an alias prior to loading your code:
556
+
557
+ For a Rails application, you can do this in `config/application.rb`
558
+ after the `Bundler.require` line, usually:
559
+
560
+ ```ruby
561
+ Bundler.require(*Rails.groups)
562
+ ```
563
+
564
+ Add these lines immediately after that point:
565
+
566
+ ```ruby
567
+ EmailAddressValidator = EmailAddress
568
+ Object.send(:remove_const, :EmailAddress)
569
+ ```
570
+
571
+ Then your application loads with your EmailAddress class. You may
572
+ then use this gem with `EmailAddressValidator` or whatever name you
573
+ gave it above:
574
+
575
+ ```ruby
576
+ EmailAddressValidator.valid?("clark.kent@gmail.com") # => true
577
+ ```
578
+
545
579
  ## Notes
546
580
 
547
581
  #### Internationalization
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/afair/email_address"
14
14
  spec.license = "MIT"
15
15
 
16
+ #spec.required_ruby_version = ">= 2.3.0"
16
17
  spec.files = `git ls-files`.split($/)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
@@ -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,11 +35,12 @@ 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
- r.errors[f] << (@opt[:message] ||
41
- EmailAddress::Config.error_messages[:invalid_address] ||
42
- "Invalid Email Address")
40
+ error_message = @opt[:message] ||
41
+ Config.error_messages[:invalid_address] ||
42
+ "Invalid Email Address"
43
+ r.errors.add(f, error_message)
43
44
  end
44
45
  end
45
46
 
@@ -5,33 +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 = config # This needs refactoring!
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
- @config = @host.config
34
- @local = EmailAddress::Local.new(local, @config, @host)
32
+ @host = Host.new(host, @config)
33
+ @local = Local.new(local, @config, @host)
35
34
  @error = @error_message = nil
36
35
  end
37
36
 
@@ -115,7 +114,7 @@ module EmailAddress
115
114
  alias to_s normal
116
115
 
117
116
  def inspect
118
- "#<EmailAddress::Address:0x#{object_id.to_s(16)} address=\"#{self}\">"
117
+ "#<#{self.class}:0x#{object_id.to_s(16)} address=\"#{self}\">"
119
118
  end
120
119
 
121
120
  # Returns the canonical email address according to the provider
@@ -191,7 +190,7 @@ module EmailAddress
191
190
  # of this addres with another, using the canonical or redacted forms.
192
191
  def same_as?(other_email)
193
192
  if other_email.is_a?(String)
194
- other_email = EmailAddress::Address.new(other_email)
193
+ other_email = Address.new(other_email)
195
194
  end
196
195
 
197
196
  canonical == other_email.canonical ||
@@ -215,7 +214,7 @@ module EmailAddress
215
214
 
216
215
  # Does "root@*.com" match "root@example.com" domain name
217
216
  rules.each do |r|
218
- if /.+@.+/.match?(r)
217
+ if r.match(/.+@.+/)
219
218
  return r if File.fnmatch?(r, to_s)
220
219
  end
221
220
  end
@@ -277,7 +276,7 @@ module EmailAddress
277
276
  def set_error(err, reason = nil)
278
277
  @error = err
279
278
  @reason = reason
280
- @error_message = EmailAddress::Config.error_message(err)
279
+ @error_message = Config.error_message(err)
281
280
  false
282
281
  end
283
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
@@ -143,6 +143,7 @@ module EmailAddress
143
143
  },
144
144
  msn: {
145
145
  host_match: %w[msn. hotmail. outlook. live.],
146
+ exchanger_match: %w[outlook.com],
146
147
  mailbox_validator: ->(m, t) { m =~ /\A\w[\-\w]*(?:\.[\-\w]+)*\z/i }
147
148
  },
148
149
  yahoo: {
@@ -175,8 +176,7 @@ module EmailAddress
175
176
  def self.provider(name, config = {})
176
177
  name = name.to_sym
177
178
  if config.size > 0
178
- @providers[name] ||= @config.clone
179
- @providers[name].merge!(config)
179
+ @providers[name.to_sym] = config
180
180
  end
181
181
  @providers[name]
182
182
  end
@@ -199,5 +199,25 @@ module EmailAddress
199
199
  configs.each { |c| config.merge!(c) }
200
200
  config
201
201
  end
202
+
203
+ def initialize(overrides = {})
204
+ @config = Config.all_settings(overrides)
205
+ end
206
+
207
+ def []=(setting, value)
208
+ @config[setting.to_sym] = value
209
+ end
210
+
211
+ def [](setting)
212
+ @config[setting.to_sym]
213
+ end
214
+
215
+ def configure(settings)
216
+ @config = @config.merge(settings)
217
+ end
218
+
219
+ def to_h
220
+ @config
221
+ end
202
222
  end
203
223
  end
@@ -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
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
90
+ @config = config.is_a?(Hash) ? Config.new(config) : config
91
91
  @error = @error_message = nil
92
92
  parse(host_name)
93
93
  end
@@ -149,7 +149,7 @@ module EmailAddress
149
149
  if @config[:host_remove_spaces]
150
150
  @host_name = @host_name.delete(" ")
151
151
  end
152
- @dns_name = if /[^[:ascii:]]/.match?(host_name)
152
+ @dns_name = if /[^[:ascii:]]/.match(host_name)
153
153
  ::SimpleIDN.to_ascii(host_name)
154
154
  else
155
155
  host_name
@@ -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
@@ -217,25 +217,23 @@ module EmailAddress
217
217
 
218
218
  return set_provider(:default) unless dns_enabled?
219
219
 
220
- provider = exchangers.provider
221
- if provider != :default
222
- set_provider(provider,
223
- EmailAddress::Config.provider(provider))
224
- end
225
-
226
220
  self.provider ||= set_provider(:default)
227
221
  end
228
222
 
229
223
  def set_provider(name, provider_config = {}) # :nodoc:
230
- self.config = EmailAddress::Config.all_settings(provider_config, @config)
231
- self.provider = name
224
+ config.configure(provider_config)
225
+ @provider = name
232
226
  end
233
227
 
234
228
  # Returns a hash of the parts of the host name after parsing.
235
229
  def parts
236
230
  {host_name: host_name, dns_name: dns_name, subdomain: subdomains,
237
231
  registration_name: registration_name, domain_name: domain_name,
238
- tld2: tld2, tld: tld, ip_address: ip_address}
232
+ tld2: tld2, tld: tld, ip_address: ip_address,}
233
+ end
234
+
235
+ def hosted_provider
236
+ Exchanger.cached(dns_name).provider
239
237
  end
240
238
 
241
239
  ############################################################################
@@ -286,7 +284,7 @@ module EmailAddress
286
284
 
287
285
  # Does "example." match any tld?
288
286
  def registration_name_matches?(rule)
289
- "#{registration_name}." == rule
287
+ rule == "#{registration_name}."
290
288
  end
291
289
 
292
290
  # Does "sub.example.com" match ".com" and ".example.com" top level names?
@@ -340,11 +338,11 @@ module EmailAddress
340
338
  @_dns_a_record ||= []
341
339
  end
342
340
 
343
- # Returns an array of EmailAddress::Exchanger hosts configured in DNS.
341
+ # Returns an array of Exchanger hosts configured in DNS.
344
342
  # The array will be empty if none are configured.
345
343
  def exchangers
346
344
  # return nil if @config[:host_type] != :email || !self.dns_enabled?
347
- @_exchangers ||= EmailAddress::Exchanger.cached(dns_name, @config)
345
+ @_exchangers ||= Exchanger.cached(dns_name, @config)
348
346
  end
349
347
 
350
348
  # Returns a DNS TXT Record
@@ -450,9 +448,9 @@ module EmailAddress
450
448
  if !@config[:host_allow_ip]
451
449
  bool = set_error(:ip_address_forbidden)
452
450
  elsif ip_address.include?(":")
453
- bool = Resolv::IPv6::Regex.match?(ip_address) ? true : set_error(:ipv6_address_invalid)
451
+ bool = ip_address.match(Resolv::IPv6::Regex) ? true : set_error(:ipv6_address_invalid)
454
452
  elsif ip_address.include?(".")
455
- bool = Resolv::IPv4::Regex.match?(ip_address) ? true : set_error(:ipv4_address_invalid)
453
+ bool = ip_address.match(Resolv::IPv4::Regex) ? true : set_error(:ipv4_address_invalid)
456
454
  end
457
455
  if bool && (localhost? && !@config[:host_local])
458
456
  bool = set_error(:ip_address_no_localhost)
@@ -499,7 +497,7 @@ module EmailAddress
499
497
  def set_error(err, reason = nil)
500
498
  @error = err
501
499
  @reason = reason
502
- @error_message = EmailAddress::Config.error_message(err)
500
+ @error_message = Config.error_message(err)
503
501
  false
504
502
  end
505
503
 
@@ -107,7 +107,7 @@ module EmailAddress
107
107
  %r/^([\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+)$/i.freeze
108
108
 
109
109
  def initialize(local, config={}, host=nil)
110
- self.config = config.empty? ? EmailAddress::Config.all_settings : 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
@@ -130,10 +130,10 @@ module EmailAddress
130
130
  def parse(raw)
131
131
  if raw =~ /\A\"(.*)\"\z/ # Quoted
132
132
  raw = $1
133
- raw.gsub!(/\\(.)/, '\1') # Unescape
133
+ raw = raw.gsub(/\\(.)/, '\1') # Unescape
134
134
  elsif @config[:local_fix] && @config[:local_format] != :standard
135
- raw.gsub!(' ','')
136
- raw.gsub!(',','.')
135
+ raw = raw.gsub(' ','')
136
+ raw = raw.gsub(',','.')
137
137
  #raw.gsub!(/([^\p{L}\p{N}]{2,10})/) {|s| s[0] } # Stutter punctuation typo
138
138
  end
139
139
  raw, comment = self.parse_comment(raw)
@@ -226,7 +226,7 @@ module EmailAddress
226
226
  def relax
227
227
  form = self.mailbox
228
228
  form += @config[:tag_separator] + self.tag if self.tag
229
- form.gsub!(/[ \"\(\),:<>@\[\]\\]/,'')
229
+ form = form.gsub(/[ \"\(\),:<>@\[\]\\]/,'')
230
230
  form
231
231
  end
232
232
 
@@ -235,7 +235,7 @@ module EmailAddress
235
235
  form = self.mailbox
236
236
  form += @config[:tag_separator] + self.tag if self.tag
237
237
  form += "(" + self.comment + ")" if self.comment
238
- form.gsub!(/([\\\"])/, '\\\1') # Escape \ and "
238
+ form = form.gsub(/([\\\"])/, '\\\1') # Escape \ and "
239
239
  if form =~ /[ \"\(\),:<>@\[\\\]]/ # Space and "(),:;<>@[\]
240
240
  form = %Q("#{form}")
241
241
  end
@@ -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.14"
2
+ VERSION = "0.1.19"
3
3
  end
@@ -37,6 +37,11 @@ class TestAddress < Minitest::Test
37
37
  assert_equal "6bdd00c53645790ad9bbcb50caa93880", EmailAddress.reference("Gmail.User+tag@gmail.com")
38
38
  end
39
39
 
40
+ def test_google_hosted
41
+ a = EmailAddress.new("Ex.am.ple+tag@boomer.com")
42
+ assert_equal a.canonical, "ex.am.ple@boomer.com"
43
+ end
44
+
40
45
  # COMPARISON & MATCHING
41
46
  def test_compare
42
47
  a = ("User+tag@example.com")
@@ -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.14
4
+ version: 0.1.19
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-03-17 00:00:00.000000000 Z
11
+ date: 2020-12-21 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
@@ -183,8 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
184
  - !ruby/object:Gem::Version
184
185
  version: '0'
185
186
  requirements: []
186
- rubygems_version: 3.0.6
187
- signing_key:
187
+ rubygems_version: 3.1.4
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