validators 3.4.0 → 3.4.1

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: 49077fb99da3c1c92a3b981cdfd0354acb5a62a9b433512658bfc5c1e4df649b
4
- data.tar.gz: 9d48b1cf25f3782afeaa00c0fa7f51ecf5581ea7e6bb49ebd5796ab914aecb50
3
+ metadata.gz: a736f1025396b9890dbee7e6b132b4614171ea40fb40dae7b2328c46041450b0
4
+ data.tar.gz: 99b1a2f3ad91b27c2da61e0041e9fc467bdce72e4d4e74ceb9f94966535d8c1d
5
5
  SHA512:
6
- metadata.gz: 1b307ad09f0e26c9e1db7766a15512aab5c87eb5cbd6217e9da489a45abce98bad30c4c320d0042d46fbf92d1d2c061487736f45d723d569a04cf26fb27bc453
7
- data.tar.gz: b72f412e65628ac2d4b1e14160e2fcc855383ff3e40641d78e77cfa99f3f9b781e82d9cc4ca269ecd45493f4b199d918102b713d7860c99bf73e88b73ab6e060
6
+ metadata.gz: aae5016154a43eb9ce819edb9c89174235bbd1d16999f66b03a27d220f1ee94f22d4fa537cdb5ea860552252ae12ff0595a9a306799c00216eab5676ad6a709d
7
+ data.tar.gz: a832a6d26868df4dcf0d53b456318adb79d40d604006bf14ed926ed027407bfbf8023af5257edcf9ca62e9cf6a41a1a77c5cf5f32697a8624ae9db695afe84f5
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.6
6
+ TargetRubyVersion: 2.5
7
7
  Exclude:
8
8
  - vendor/**/*
9
9
 
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/fnando/validators.svg)](https://travis-ci.org/fnando/validators)
4
4
  [![Code Climate](https://codeclimate.com/github/fnando/validators/badges/gpa.svg)](https://codeclimate.com/github/fnando/validators)
5
- [![Test Coverage](https://codeclimate.com/github/fnando/validators/badges/coverage.svg)](https://codeclimate.com/github/fnando/validators)
5
+ [![Gem](https://img.shields.io/gem/v/validators.svg)](https://rubygems.org/gems/validators)
6
+ [![Gem](https://img.shields.io/gem/dt/validators.svg)](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 data (~1.7MB), but you can disable this validation by setting `disposable: true`.
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
- This validation loads ~20KB of text.
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
- * [Nando Vieira](http://nandovieira.com)
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
- a copy of this software and associated documentation files (the
200
- 'Software'), to deal in the Software without restriction, including
201
- without limitation the rights to use, copy, modify, merge, publish,
202
- distribute, sublicense, and/or sell copies of the Software, and to
203
- permit persons to whom the Software is furnished to do so, subject to
204
- the following conditions:
205
-
206
- The above copyright notice and this permission notice shall be
207
- included in all copies or substantial portions of the Software.
208
-
209
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
210
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
211
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
212
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
213
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
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.
@@ -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
- require "email_data"
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
- require "email_data"
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
 
@@ -5,10 +5,8 @@ module Validators
5
5
  def self.all
6
6
  @all ||=
7
7
  begin
8
- require "email_data"
8
+ Validators.require_dependency! "email_data"
9
9
  EmailData.tlds
10
- rescue LoadError
11
- raise "email_data is not part of the bundle. Add it to Gemfile."
12
10
  end
13
11
  end
14
12
 
@@ -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
- require "sshkey"
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
- require "sshkey"
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
@@ -4,7 +4,7 @@ module Validators
4
4
  module Version
5
5
  MAJOR = 3
6
6
  MINOR = 4
7
- PATCH = 0
7
+ PATCH = 1
8
8
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
9
9
  end
10
10
  end
@@ -15,10 +15,10 @@ class ValidatesCnpjFormatOfTest < Minitest::Test
15
15
  end
16
16
  end
17
17
 
18
- test "fails when gem is not available" do
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("cnpj").raises(LoadError)
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 gem is not available" do
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("cpf").raises(LoadError)
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 gem is not available" do
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 gem is not available" do
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.0
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-26 00:00:00.000000000 Z
11
+ date: 2020-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord