validators 2.4.0 → 2.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/Gemfile.lock +1 -1
- data/lib/validators/validates_cnpj_format_of.rb +3 -0
- data/lib/validators/validates_cpf_format_of.rb +3 -0
- data/lib/validators/validates_datetime.rb +3 -0
- data/lib/validators/validates_email_format_of.rb +3 -0
- data/lib/validators/validates_hostname_format_of.rb +3 -0
- data/lib/validators/validates_ssh_private_key.rb +3 -0
- data/lib/validators/validates_ssh_public_key.rb +3 -0
- data/lib/validators/validates_url_format_of.rb +2 -0
- data/lib/validators/version.rb +1 -1
- data/spec/validators/validates_hostname_format_of_spec.rb +10 -0
- data/spec/validators/validates_url_format_of_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a52bd8c6c0154e31767455e8a2e1037c6e6a8c2e
|
4
|
+
data.tar.gz: 22b34fe94029f994f37a2d8165ec377567d16c3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2468097e60de4e9296bbe3271ce78390f303b73252a5982e32e2af084fe34b9d49b63f2b0dacc19e6a5edd33870456efeb8730a1e3bed48ef30bdaa86646f7b1
|
7
|
+
data.tar.gz: 1213ca2a3b9472dbf599d005de080dc62b158ec416e09a18bd46855063120541116d24ffa3d9abacf22f07715821527e8e2683c358f149a832808ced8d2c1a1f
|
data/Gemfile.lock
CHANGED
@@ -2,6 +2,9 @@ module ActiveModel
|
|
2
2
|
module Validations
|
3
3
|
class CnpjValidator < EachValidator
|
4
4
|
def validate_each(record, attribute, value)
|
5
|
+
return if value.blank? && options[:allow_blank]
|
6
|
+
return if value.nil? && options[:allow_nil]
|
7
|
+
|
5
8
|
record.errors.add(attribute, :invalid_cnpj,
|
6
9
|
message: options[:message],
|
7
10
|
value: value
|
@@ -2,6 +2,9 @@ module ActiveModel
|
|
2
2
|
module Validations
|
3
3
|
class CpfValidator < EachValidator
|
4
4
|
def validate_each(record, attribute, value)
|
5
|
+
return if value.blank? && options[:allow_blank]
|
6
|
+
return if value.nil? && options[:allow_nil]
|
7
|
+
|
5
8
|
record.errors.add(attribute, :invalid_cpf,
|
6
9
|
message: options[:message],
|
7
10
|
value: value
|
@@ -6,6 +6,9 @@ module ActiveModel
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def validate_each(record, attribute, value)
|
9
|
+
return if value.blank? && options[:allow_blank]
|
10
|
+
return if value.nil? && options[:allow_nil]
|
11
|
+
|
9
12
|
unless date?(value)
|
10
13
|
record.errors.add(attribute, :invalid_date,
|
11
14
|
:message => options[:message], :value => value
|
@@ -2,6 +2,9 @@ module ActiveModel
|
|
2
2
|
module Validations
|
3
3
|
class EmailValidator < EachValidator
|
4
4
|
def validate_each(record, attribute, value)
|
5
|
+
return if value.blank? && options[:allow_blank]
|
6
|
+
return if value.nil? && options[:allow_nil]
|
7
|
+
|
5
8
|
if value.to_s !~ Validators::EMAIL_FORMAT
|
6
9
|
record.errors.add(
|
7
10
|
attribute, :invalid_email,
|
@@ -3,6 +3,8 @@ module ActiveModel
|
|
3
3
|
class HostnameValidator < EachValidator
|
4
4
|
# Rules taken from http://www.zytrax.com/books/dns/apa/names.html
|
5
5
|
def validate_each(record, attribute, value)
|
6
|
+
return if value.blank? && options[:allow_blank]
|
7
|
+
return if value.nil? && options[:allow_nil]
|
6
8
|
return if valid_hostname?(value.to_s)
|
7
9
|
|
8
10
|
record.errors.add(attribute, :invalid_hostname,
|
@@ -15,6 +17,7 @@ module ActiveModel
|
|
15
17
|
host = host.to_s
|
16
18
|
uri = URI(host)
|
17
19
|
|
20
|
+
host.present? &&
|
18
21
|
uri.host.nil? &&
|
19
22
|
uri.scheme.nil? &&
|
20
23
|
uri.fragment.nil? &&
|
@@ -2,6 +2,9 @@ module ActiveModel
|
|
2
2
|
module Validations
|
3
3
|
class SshPrivateKeyValidator < EachValidator
|
4
4
|
def validate_each(record, attribute, value)
|
5
|
+
return if value.blank? && options[:allow_blank]
|
6
|
+
return if value.nil? && options[:allow_nil]
|
7
|
+
|
5
8
|
sshkey = SSHKey.new(value.to_s)
|
6
9
|
validate_type(record, attribute, sshkey)
|
7
10
|
validate_bits(record, attribute, sshkey)
|
@@ -2,6 +2,9 @@ module ActiveModel
|
|
2
2
|
module Validations
|
3
3
|
class SshPublicKeyValidator < EachValidator
|
4
4
|
def validate_each(record, attribute, value)
|
5
|
+
return if value.blank? && options[:allow_blank]
|
6
|
+
return if value.nil? && options[:allow_nil]
|
7
|
+
|
5
8
|
record.errors.add(attribute, :invalid_ssh_public_key,
|
6
9
|
message: options[:message],
|
7
10
|
value: value
|
data/lib/validators/version.rb
CHANGED
@@ -34,5 +34,15 @@ describe ".validates_hostname_format_of" do
|
|
34
34
|
expect(server).not_to be_valid
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
it 'rejects nil hostname' do
|
39
|
+
server = ServerWithoutTLD.new(nil)
|
40
|
+
expect(server).not_to be_valid
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'rejects blank hostname' do
|
44
|
+
server = ServerWithoutTLD.new('')
|
45
|
+
expect(server).not_to be_valid
|
46
|
+
end
|
37
47
|
end
|
38
48
|
end
|
@@ -51,5 +51,15 @@ describe ".validates_url_format_of" do
|
|
51
51
|
expect(user).not_to be_valid
|
52
52
|
expect(user.errors[:url]).to eq(["não parece ser uma URL válida"])
|
53
53
|
end
|
54
|
+
|
55
|
+
it "rejects nil urls" do
|
56
|
+
user = User.new(url: nil)
|
57
|
+
expect(user).not_to be_valid
|
58
|
+
end
|
59
|
+
|
60
|
+
it "rejects blank urls" do
|
61
|
+
user = User.new(url: '')
|
62
|
+
expect(user).not_to be_valid
|
63
|
+
end
|
54
64
|
end
|
55
65
|
end
|