validators 3.4.0 → 3.4.1
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 +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +29 -24
- data/lib/validators.rb +7 -0
- data/lib/validators/disposable_domains.rb +2 -3
- data/lib/validators/disposable_emails.rb +2 -3
- data/lib/validators/tld.rb +1 -3
- data/lib/validators/validates_cnpj_format_of.rb +1 -2
- data/lib/validators/validates_cpf_format_of.rb +1 -2
- data/lib/validators/validates_email_format_of.rb +2 -2
- data/lib/validators/validates_ssh_private_key.rb +1 -3
- data/lib/validators/validates_ssh_public_key.rb +1 -3
- data/lib/validators/version.rb +1 -1
- data/test/validators/validates_cnpj_format_of_test.rb +3 -3
- data/test/validators/validates_cpf_format_of_test.rb +3 -3
- data/test/validators/validates_email_format_of_test.rb +23 -0
- data/test/validators/validates_ssh_private_key/common_test.rb +3 -3
- data/test/validators/validates_ssh_public_key_test.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a736f1025396b9890dbee7e6b132b4614171ea40fb40dae7b2328c46041450b0
|
4
|
+
data.tar.gz: 99b1a2f3ad91b27c2da61e0041e9fc467bdce72e4d4e74ceb9f94966535d8c1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aae5016154a43eb9ce819edb9c89174235bbd1d16999f66b03a27d220f1ee94f22d4fa537cdb5ea860552252ae12ff0595a9a306799c00216eab5676ad6a709d
|
7
|
+
data.tar.gz: a832a6d26868df4dcf0d53b456318adb79d40d604006bf14ed926ed027407bfbf8023af5257edcf9ca62e9cf6a41a1a77c5cf5f32697a8624ae9db695afe84f5
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/fnando/validators)
|
4
4
|
[](https://codeclimate.com/github/fnando/validators)
|
5
|
-
[](https://rubygems.org/gems/validators)
|
6
|
+
[](https://rubygems.org/gems/validators)
|
6
7
|
|
7
8
|
Add some nice ActiveModel/ActiveRecord validators.
|
8
9
|
|
@@ -20,6 +21,11 @@ gem "validators"
|
|
20
21
|
|
21
22
|
## Usage
|
22
23
|
|
24
|
+
**Notice**: Some validators will require additional dependencies; whenever you
|
25
|
+
get a message like
|
26
|
+
`gem-name is not part of the bundle. Add it to your project's Gemfile.`, all you
|
27
|
+
have to do is adding that gem to your own project's Gemfile.
|
28
|
+
|
23
29
|
### validates_email_format_of
|
24
30
|
|
25
31
|
```ruby
|
@@ -32,7 +38,9 @@ class User < ActiveRecord::Base
|
|
32
38
|
end
|
33
39
|
```
|
34
40
|
|
35
|
-
By default, it rejects disposable e-mails (e.g. mailinator). This loads a lot of
|
41
|
+
By default, it rejects disposable e-mails (e.g. mailinator). This loads a lot of
|
42
|
+
data (~1.7MB), but you can disable this validation by setting
|
43
|
+
`disposable: true`.
|
36
44
|
|
37
45
|
```ruby
|
38
46
|
class User < ActiveRecord::Base
|
@@ -135,7 +143,6 @@ Rules:
|
|
135
143
|
- labels do not consist of numeric values only
|
136
144
|
- TLD validation (optional)
|
137
145
|
|
138
|
-
|
139
146
|
```ruby
|
140
147
|
class Server < ActiveRecord::Base
|
141
148
|
validates_hostname :hostname
|
@@ -152,8 +159,8 @@ A valid username/subdomain follows the hostname label validation:
|
|
152
159
|
- cannot begin or end with a hyphen
|
153
160
|
- cannot consist of numeric values only
|
154
161
|
|
155
|
-
The compiled list will be used for both username and subdomain validations.
|
156
|
-
|
162
|
+
The compiled list will be used for both username and subdomain validations. This
|
163
|
+
validation loads ~20KB of text.
|
157
164
|
|
158
165
|
```ruby
|
159
166
|
class Server < ActiveRecord::Base
|
@@ -189,27 +196,25 @@ end
|
|
189
196
|
|
190
197
|
## Maintainer
|
191
198
|
|
192
|
-
|
199
|
+
- [Nando Vieira](http://nandovieira.com)
|
193
200
|
|
194
201
|
## License
|
195
202
|
|
196
203
|
(The MIT License)
|
197
204
|
|
198
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
IN
|
213
|
-
|
214
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
215
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
205
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
206
|
+
this software and associated documentation files (the 'Software'), to deal in
|
207
|
+
the Software without restriction, including without limitation the rights to
|
208
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
209
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
210
|
+
subject to the following conditions:
|
211
|
+
|
212
|
+
The above copyright notice and this permission notice shall be included in all
|
213
|
+
copies or substantial portions of the Software.
|
214
|
+
|
215
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
216
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
217
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
218
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
219
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
220
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/validators.rb
CHANGED
@@ -25,4 +25,11 @@ module Validators
|
|
25
25
|
require "validators/validates_username"
|
26
26
|
|
27
27
|
I18n.load_path += Dir[File.join(__dir__, "validators/locale/*.yml")]
|
28
|
+
|
29
|
+
def self.require_dependency!(dep)
|
30
|
+
require dep
|
31
|
+
rescue LoadError
|
32
|
+
raise "#{dep} is not part of the bundle. " \
|
33
|
+
"Add it to your project's Gemfile."
|
34
|
+
end
|
28
35
|
end
|
@@ -5,10 +5,9 @@ module Validators
|
|
5
5
|
def self.all
|
6
6
|
@all ||=
|
7
7
|
begin
|
8
|
-
|
8
|
+
Validators.require_dependency! "root_domain"
|
9
|
+
Validators.require_dependency! "email_data"
|
9
10
|
EmailData.disposable_domains
|
10
|
-
rescue LoadError
|
11
|
-
raise "email_data is not part of the bundle. Add it to Gemfile."
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
@@ -5,10 +5,9 @@ module Validators
|
|
5
5
|
def self.all
|
6
6
|
@all ||=
|
7
7
|
begin
|
8
|
-
|
8
|
+
Validators.require_dependency! "root_domain"
|
9
|
+
Validators.require_dependency! "email_data"
|
9
10
|
EmailData.disposable_emails
|
10
|
-
rescue LoadError
|
11
|
-
raise "email_data is not part of the bundle. Add it to Gemfile."
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
data/lib/validators/tld.rb
CHANGED
@@ -25,10 +25,9 @@ module ActiveModel
|
|
25
25
|
# end
|
26
26
|
#
|
27
27
|
def validates_cnpj_format_of(*attr_names)
|
28
|
+
Validators.require_dependency! "cpf_cnpj"
|
28
29
|
require "cnpj"
|
29
30
|
validates_with CnpjValidator, _merge_attributes(attr_names)
|
30
|
-
rescue LoadError
|
31
|
-
raise "cpf_cnpj is not part of the bundle. Add it to Gemfile."
|
32
31
|
end
|
33
32
|
|
34
33
|
alias_method :validates_cnpj, :validates_cnpj_format_of
|
@@ -25,10 +25,9 @@ module ActiveModel
|
|
25
25
|
# end
|
26
26
|
#
|
27
27
|
def validates_cpf_format_of(*attr_names)
|
28
|
+
Validators.require_dependency! "cpf_cnpj"
|
28
29
|
require "cpf"
|
29
30
|
validates_with CpfValidator, _merge_attributes(attr_names)
|
30
|
-
rescue LoadError
|
31
|
-
raise "cpf_cnpj is not part of the bundle. Add it to Gemfile."
|
32
31
|
end
|
33
32
|
|
34
33
|
alias_method :validates_cpf, :validates_cpf_format_of
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "root_domain"
|
4
|
-
|
5
3
|
module ActiveModel
|
6
4
|
module Validations
|
7
5
|
class EmailValidator < EachValidator
|
@@ -79,6 +77,8 @@ module ActiveModel
|
|
79
77
|
# end
|
80
78
|
#
|
81
79
|
def validates_email_format_of(*attr_names)
|
80
|
+
Validators.require_dependency! "root_domain"
|
81
|
+
Validators.require_dependency! "email_data"
|
82
82
|
validates_with EmailValidator, _merge_attributes(attr_names)
|
83
83
|
end
|
84
84
|
|
@@ -56,10 +56,8 @@ module ActiveModel
|
|
56
56
|
# end
|
57
57
|
#
|
58
58
|
def validates_ssh_private_key(*attr_names)
|
59
|
-
|
59
|
+
Validators.require_dependency! "sshkey"
|
60
60
|
validates_with SshPrivateKeyValidator, _merge_attributes(attr_names)
|
61
|
-
rescue LoadError
|
62
|
-
raise "sshkey is not part of the bundle. Add it to Gemfile."
|
63
61
|
end
|
64
62
|
end
|
65
63
|
end
|
@@ -25,10 +25,8 @@ module ActiveModel
|
|
25
25
|
# end
|
26
26
|
#
|
27
27
|
def validates_ssh_public_key(*attr_names)
|
28
|
-
|
28
|
+
Validators.require_dependency! "sshkey"
|
29
29
|
validates_with SshPublicKeyValidator, _merge_attributes(attr_names)
|
30
|
-
rescue LoadError
|
31
|
-
raise "sshkey is not part of the bundle. Add it to Gemfile."
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
data/lib/validators/version.rb
CHANGED
@@ -15,10 +15,10 @@ class ValidatesCnpjFormatOfTest < Minitest::Test
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
test "fails when
|
19
|
-
assert_raises do
|
18
|
+
test "fails when cpf_cnpj is not available" do
|
19
|
+
assert_raises(StandardError, /cpf_cnpj is not part of the bundle/) do
|
20
20
|
Class.new do
|
21
|
-
expects(:require).with("
|
21
|
+
Validators.expects(:require).with("cpf_cnpj").raises(LoadError, "-- cpf_cnpj")
|
22
22
|
|
23
23
|
include ActiveModel::Model
|
24
24
|
validates_cnpj_format_of :document
|
@@ -15,10 +15,10 @@ class ValidatesCpfFormatOfTest < Minitest::Test
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
test "fails when
|
19
|
-
assert_raises do
|
18
|
+
test "fails when cpf_cnpj is not available" do
|
19
|
+
assert_raises(StandardError, /cpf_cnpj is not part of the bundle/) do
|
20
20
|
Class.new do
|
21
|
-
expects(:require).with("
|
21
|
+
Validators.expects(:require).with("cpf_cnpj").raises(LoadError, "-- cpf_cnpj")
|
22
22
|
|
23
23
|
include ActiveModel::Model
|
24
24
|
validates_cpf_format_of :document
|
@@ -9,6 +9,29 @@ class ValidatesEmailFormatOfTest < Minitest::Test
|
|
9
9
|
Person.validates :email, email: true
|
10
10
|
end
|
11
11
|
|
12
|
+
test "fails when email_data is not available" do
|
13
|
+
assert_raises(StandardError, /email_data is not part of the bundle/) do
|
14
|
+
Class.new do
|
15
|
+
Validators.expects(:require).with("root_domain")
|
16
|
+
Validators.expects(:require).with("email_data").raises(LoadError, "-- email_data")
|
17
|
+
|
18
|
+
include ActiveModel::Model
|
19
|
+
validates_email :email
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
test "fails when root_domain is not available" do
|
25
|
+
assert_raises(StandardError, /root_domain is not part of the bundle/) do
|
26
|
+
Class.new do
|
27
|
+
Validators.expects(:require).with("root_domain").raises(LoadError, "-- root_domain")
|
28
|
+
|
29
|
+
include ActiveModel::Model
|
30
|
+
validates_email :email
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
12
35
|
VALID_EMAILS.each do |email|
|
13
36
|
test "accepts #{email.inspect} as a valid email" do
|
14
37
|
user = User.new(email: email, corporate_email: email)
|
@@ -15,10 +15,10 @@ class ValidatesSshPrivateKeyCommonTest < Minitest::Test
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
test "fails when
|
19
|
-
assert_raises do
|
18
|
+
test "fails when sshkey is not available" do
|
19
|
+
assert_raises(StandardError, /sshkey is not part of the bundle/) do
|
20
20
|
Class.new do
|
21
|
-
expects(:require).with("sshkey").raises(LoadError)
|
21
|
+
Validators.expects(:require).with("sshkey").raises(LoadError.new("-- sshkey"))
|
22
22
|
|
23
23
|
include ActiveModel::Model
|
24
24
|
validates_ssh_private_key :key
|
@@ -15,10 +15,10 @@ class ValidatesSsshPublicKeyCommonTest < Minitest::Test
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
test "fails when
|
19
|
-
assert_raises do
|
18
|
+
test "fails when sshkey is not available" do
|
19
|
+
assert_raises(StandardError, /sshkey is not part of the bundle/) do
|
20
20
|
Class.new do
|
21
|
-
expects(:require).with("sshkey").raises(LoadError)
|
21
|
+
Validators.expects(:require).with("sshkey").raises(LoadError, "-- sshkey")
|
22
22
|
|
23
23
|
include ActiveModel::Model
|
24
24
|
validates_ssh_public_key :key
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.
|
4
|
+
version: 3.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|