email_assessor 0.2.1 → 0.3

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
  SHA1:
3
- metadata.gz: 0b062226fbe0f1a213b49179aaf6e986f5dfed6f
4
- data.tar.gz: 3f46d3807934367d3762aa7e163b314a52bf2d2a
3
+ metadata.gz: 8e6bbdf20e2b76943db2c9957b2b3e689c6d4956
4
+ data.tar.gz: 744a37974466b6c82744821b93bc7ec66362482c
5
5
  SHA512:
6
- metadata.gz: 93a11b96ec1a773e71f76299ae61f729a40b71d6a5bda59fe35fbcea10fcc7e93828a33d0a0e25b94640b77fae0d4ed7f8854676e133a2f7ad381a67ace2b0d7
7
- data.tar.gz: f1597c569b67261bab09298eb40f3c2e1ab5db514fe5f1a0e99c46e0e57be5dadd9732b39eefe85f4ca712aa76476725f3d7707e43d80a032389ae2ced074aab
6
+ metadata.gz: 1712d4c2ed8d66046fc707830954c3b1a406e2f27e7a6f7f0eb089e3fe2cc2c24d19fe8e5f7ed0bc171e3b0ef5d800b36f40e2bf276ca838d3223e9012092904
7
+ data.tar.gz: 5ce7e6899e887a555d654defcf2429aa9bbc3b4a6da102baeed3d120c5c932d7075374bf9016396c499a90237c20506f03ec9d0e9240f0b2aa238f481e77f480
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
+ ## Version 0.3
2
+ - Refactored the logic in `EmailAssessor.domain_in_file?` to be simpler
3
+ - Removed configurability in favor of convention over configuration
4
+
1
5
  ## Version 0.1
2
6
  Gave this fork its very own name: EmailAssessor
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # ValidEmail2
1
+ # EmailAssessor
2
2
  [![Build Status](https://travis-ci.org/wolfemm/email_assessor.png?branch=master)](https://travis-ci.org/wolfemm/email_assessor)
3
3
  [![Gem Version](https://badge.fury.io/rb/email_assessor.png)](http://badge.fury.io/rb/email_assessor)
4
4
 
5
- A fork of of the wonderful [ValidEmail2](https://github.com/lisinge/valid_email2) by [Micke Lisinge](https://github.com/lisinge).
5
+ A fork of [Micke Lisinge](https://github.com/lisinge)'s [ValidEmail2](https://github.com/lisinge/valid_email2).
6
6
 
7
7
  ValidEmail2:
8
8
 
@@ -36,6 +36,30 @@ Or install it yourself as:
36
36
 
37
37
  $ gem install email_assessor
38
38
 
39
+ ## Domain List Files
40
+
41
+ Domain list files, used for blacklisting and blocking disposable emails, are plain-text files with one **lower case** domain per line.
42
+
43
+ Valid domain list file:
44
+ ```
45
+ example.com
46
+ subdomain.example.org
47
+ ```
48
+
49
+ Invalid domain list file:
50
+ ```
51
+ http://example.com
52
+ example.com/mail
53
+ ```
54
+
55
+ Be careful with subdomains. Given the following domain list file:
56
+
57
+ ```
58
+ sub.example.com
59
+ ```
60
+
61
+ A user would be able to register with the email `jake@example.com` but not `tom@sub.example.com` or `jerry@deep.sub.example.com`.
62
+
39
63
  ## Usage
40
64
 
41
65
  ### Use with ActiveModel
@@ -57,14 +81,14 @@ To validate that the domain is not a disposable email:
57
81
  validates :email, email: { disposable: true }
58
82
  ```
59
83
 
60
- To validate that the domain is not blacklisted (under vendor/blacklisted_domains.txt):
84
+ To validate that the domain is not blacklisted (via `vendor/blacklisted_domains.txt`):
61
85
  ```ruby
62
86
  validates :email, email: { blacklist: true }
63
87
  ```
64
88
 
65
89
  All together:
66
90
  ```ruby
67
- validates :email, email: { mx: true, disposable: true }
91
+ validates :email, email: { mx: true, disposable: true, blacklist: true }
68
92
  ```
69
93
 
70
94
  > Note that this gem will let an empty email pass through so you will need to
@@ -1,46 +1,23 @@
1
1
  require "email_assessor/email_validator"
2
2
 
3
3
  module EmailAssessor
4
+ DISPOSABLE_DOMAINS_FILE_NAME = File.expand_path("../../vendor/disposable_domains.txt", __FILE__)
5
+ BLACKLISTED_DOMAINS_FILE_NAME = File.expand_path("vendor/blacklisted_domains.txt")
6
+
4
7
  def self.domain_is_disposable?(domain)
5
- domain_in_file?(domain, configuration.disposable_domains_file_name)
8
+ domain_in_file?(domain, DISPOSABLE_DOMAINS_FILE_NAME)
6
9
  end
7
10
 
8
11
  def self.domain_is_blacklisted?(domain)
9
- domain_in_file?(domain, configuration.blacklisted_domains_file_name)
10
- end
11
-
12
- def self.configuration
13
- @configuration ||= Configuration.new
14
- end
15
-
16
- def self.configure
17
- yield(configuration) if block_given?
18
- end
19
-
20
- class Configuration
21
- attr_accessor :disposable_domains_file_name, :blacklisted_domains_file_name
22
-
23
- def initialize
24
- @disposable_domains_file_name = File.expand_path("../../vendor/disposable_domains.txt", __FILE__)
25
- @blacklisted_domains_file_name = File.expand_path("vendor/blacklisted_domains.txt")
26
- end
12
+ domain_in_file?(domain, BLACKLISTED_DOMAINS_FILE_NAME)
27
13
  end
28
14
 
29
15
  protected
30
16
 
31
17
  def self.domain_in_file?(domain, file_name)
32
- return false unless file_name.present? && File.exists?(file_name)
33
-
18
+ file_name ||= ""
34
19
  domain = domain.downcase
35
- domain_matched = false
36
-
37
- File.open(file_name).each do |line|
38
- if domain.end_with?(line.chomp)
39
- domain_matched = true
40
- break
41
- end
42
- end
43
20
 
44
- domain_matched
21
+ File.open(file_name).each_line.any? { |line| domain.end_with?(line) }
45
22
  end
46
23
  end
@@ -1,3 +1,3 @@
1
1
  module EmailAssessor
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3"
3
3
  end
@@ -5,7 +5,7 @@ require "yaml"
5
5
  require "json"
6
6
  require "net/http"
7
7
 
8
- whitelisted_domains = %w(poczta.onet.pl fastmail.fm hushmail.com naver.com)
8
+ whitelisted_domains = %w(poczta.onet.pl fastmail.fm hushmail.com naver.com qq.com)
9
9
 
10
10
  existing_domains = File.readlines("vendor/disposable_domains.txt")
11
11
 
@@ -22,10 +22,10 @@ describe EmailAssessor do
22
22
  let(:blacklist_user) { TestUserDisallowBlacklisted.new(email: "foo@gmail.com") }
23
23
  let(:mx_user) { TestUserMX.new(email: "foo@gmail.com") }
24
24
 
25
- let(:blacklisted_domains_file_name) { described_class.configuration.blacklisted_domains_file_name }
25
+ let(:blacklisted_domains_file_name) { described_class::BLACKLISTED_DOMAINS_FILE_NAME }
26
26
  let(:blacklisted_domain) { File.open(blacklisted_domains_file_name, &:readline) }
27
27
 
28
- let(:disposable_domains_file_name) { described_class.configuration.disposable_domains_file_name }
28
+ let(:disposable_domains_file_name) { described_class::DISPOSABLE_DOMAINS_FILE_NAME }
29
29
  let(:disposable_domain) { File.open(disposable_domains_file_name, &:readline) }
30
30
 
31
31
  describe "basic validation" do
@@ -110,35 +110,4 @@ describe EmailAssessor do
110
110
  is_expected.to be_invalid
111
111
  end
112
112
  end
113
-
114
- describe "configuration" do
115
- subject(:configuration) { described_class.configuration }
116
- let(:disposable_domains_file_name) { File.expand_path("../fixtures/disposable_domains.txt", __FILE__) }
117
- let(:blacklisted_domains_file_name) { File.expand_path("../fixtures/blacklisted_domains.txt", __FILE__) }
118
-
119
- before do
120
- described_class.configure do |config|
121
- config.disposable_domains_file_name = disposable_domains_file_name
122
- config.blacklisted_domains_file_name = blacklisted_domains_file_name
123
- end
124
- end
125
-
126
- it "sets the disposable domains file" do
127
- is_expected.to have_attributes disposable_domains_file_name: disposable_domains_file_name
128
- end
129
-
130
- it "sets the blacklisted domains file" do
131
- is_expected.to have_attributes blacklisted_domains_file_name: blacklisted_domains_file_name
132
- end
133
-
134
- it "uses the configured disposable domains file" do
135
- disposable_user.email = disposable_domain
136
- expect(disposable_user).to be_invalid
137
- end
138
-
139
- it "uses the configured blacklisted domains file" do
140
- blacklist_user.email = blacklisted_domain
141
- expect(blacklist_user).to be_invalid
142
- end
143
- end
144
113
  end
@@ -1 +1 @@
1
- blacklisted-test.com
1
+ blacklist.example.com
@@ -1306,7 +1306,6 @@ qipmail.net
1306
1306
  qisdo.com
1307
1307
  qisoa.com
1308
1308
  qoika.com
1309
- qq.com
1310
1309
  quadrafit.com
1311
1310
  quickinbox.com
1312
1311
  quickmail.nl
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_assessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Wolfe Millard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,8 +103,6 @@ files:
103
103
  - lib/email_assessor/version.rb
104
104
  - pull_mailchecker_emails.rb
105
105
  - spec/email_assessor_spec.rb
106
- - spec/fixtures/blacklisted_domains.txt
107
- - spec/fixtures/disposable_domains.txt
108
106
  - spec/spec_helper.rb
109
107
  - vendor/blacklisted_domains.txt
110
108
  - vendor/disposable_domains.txt
@@ -134,6 +132,4 @@ specification_version: 4
134
132
  summary: Advanced ActiveModel email validation
135
133
  test_files:
136
134
  - spec/email_assessor_spec.rb
137
- - spec/fixtures/blacklisted_domains.txt
138
- - spec/fixtures/disposable_domains.txt
139
135
  - spec/spec_helper.rb
@@ -1 +0,0 @@
1
- rspec-blacklisted.txt
@@ -1 +0,0 @@
1
- rspec-disposable.txt