more_validators 0.1.2 → 0.1.3
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.
- data/CHANGELOG +3 -0
- data/README +11 -6
- data/lib/validates_as_cep.rb +2 -1
- data/lib/validates_as_cnpj.rb +3 -1
- data/lib/validates_as_cpf.rb +3 -2
- data/lib/validates_as_email.rb +2 -1
- data/lib/validates_as_phonenumber_br.rb +2 -1
- data/lib/validates_as_uf_br.rb +1 -0
- data/lib/validates_as_website.rb +2 -1
- data/test/validates_as_cep_test.rb +2 -0
- data/test/validates_as_cnpj_test.rb +2 -0
- data/test/validates_as_cpf_test.rb +2 -0
- data/test/validates_as_email_test.rb +3 -0
- data/test/validates_as_phonenumber_br_test.rb +2 -0
- data/test/validates_as_uf_br_test.rb +3 -1
- data/test/validates_as_website_test.rb +2 -0
- metadata +3 -3
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -19,6 +19,11 @@ gem install more_validators
|
|
19
19
|
Add to environment.rb initializer block:
|
20
20
|
config.gem 'more_validators', :lib => 'validates_as_'
|
21
21
|
|
22
|
+
LatestVersion
|
23
|
+
--------------
|
24
|
+
Version: 0.1.3
|
25
|
+
--------------
|
26
|
+
|
22
27
|
Usage:
|
23
28
|
======
|
24
29
|
In your model file do something like:
|
@@ -26,22 +31,22 @@ In your model file do something like:
|
|
26
31
|
class MyClass < ActiveRecord::Base
|
27
32
|
|
28
33
|
# Email validation
|
29
|
-
validates_as_email :email, :message => 'Invalid', :allow_nil => true
|
34
|
+
validates_as_email :email, :message => 'Invalid', :allow_nil => true, :allow_blank => true
|
30
35
|
|
31
36
|
# Brazilian postal code validation
|
32
|
-
validates_as_cep :cep, :message => 'Invalid', :allow_nil => true
|
37
|
+
validates_as_cep :cep, :message => 'Invalid', :allow_nil => true, :allow_blank => true
|
33
38
|
|
34
39
|
# Brazilian phone number validation
|
35
|
-
validates_as_phonenumber_br :phonenumber, :message => 'Invalid', :allow_nil => true
|
40
|
+
validates_as_phonenumber_br :phonenumber, :message => 'Invalid', :allow_nil => true, :allow_blank => true
|
36
41
|
|
37
42
|
# CPF validation
|
38
|
-
validates_as_cpf :cpf, :message => 'Invalid', :allow_nil => true
|
43
|
+
validates_as_cpf :cpf, :message => 'Invalid', :allow_nil => true, :allow_blank => true
|
39
44
|
|
40
45
|
# CNPJ validation
|
41
|
-
validates_as_cnpj :cnpj, :message => 'Invalid', :allow_nil => true
|
46
|
+
validates_as_cnpj :cnpj, :message => 'Invalid', :allow_nil => true, :allow_blank => true
|
42
47
|
|
43
48
|
# Brazilian UF validation, both upcase and downcase are allowed by default
|
44
|
-
validates_as_uf_br :uf, :
|
49
|
+
validates_as_uf_br :uf, :allow_up => true, :allow_down => true
|
45
50
|
|
46
51
|
end
|
47
52
|
|
data/lib/validates_as_cep.rb
CHANGED
@@ -5,7 +5,8 @@ module ActiveRecord
|
|
5
5
|
configuration = {
|
6
6
|
:message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
|
7
7
|
:with => /\A(\d{5})([-]{0,1})(\d{3})\Z/,
|
8
|
-
:allow_nil => true
|
8
|
+
:allow_nil => true,
|
9
|
+
:allow_blank => true }
|
9
10
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
10
11
|
|
11
12
|
validates_format_of attr_names, configuration
|
data/lib/validates_as_cnpj.rb
CHANGED
@@ -4,6 +4,7 @@ module CNPJ
|
|
4
4
|
88888888888888 99999999999999)
|
5
5
|
|
6
6
|
def self.valid?(cnpj)
|
7
|
+
|
7
8
|
cnpj = cnpj.to_s
|
8
9
|
|
9
10
|
# could be 13 or 14 digits or with mask 99.999.999/9999-99
|
@@ -57,7 +58,8 @@ module ActiveRecord
|
|
57
58
|
def validates_as_cnpj(*attr_names)
|
58
59
|
configuration = {
|
59
60
|
:message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
|
60
|
-
:allow_nil => true
|
61
|
+
:allow_nil => true,
|
62
|
+
:allow_blank => true }
|
61
63
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
62
64
|
|
63
65
|
validates_each attr_names, configuration do |record, attribute, value|
|
data/lib/validates_as_cpf.rb
CHANGED
@@ -3,7 +3,7 @@ module CPF
|
|
3
3
|
55555555555 66666666666 77777777777 88888888888 99999999999
|
4
4
|
00000000000)
|
5
5
|
|
6
|
-
def self.valid?(cpf)
|
6
|
+
def self.valid?(cpf)
|
7
7
|
cpf = cpf.to_s
|
8
8
|
|
9
9
|
# could be 10 or 11 digits or with mask 999.999.999-99
|
@@ -55,7 +55,8 @@ module ActiveRecord
|
|
55
55
|
def validates_as_cpf(*attr_names)
|
56
56
|
configuration = {
|
57
57
|
:message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
|
58
|
-
:allow_nil => true
|
58
|
+
:allow_nil => true,
|
59
|
+
:allow_blank => true }
|
59
60
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
60
61
|
|
61
62
|
validates_each attr_names, configuration do |record, attribute, value|
|
data/lib/validates_as_email.rb
CHANGED
@@ -48,7 +48,8 @@ module ActiveRecord
|
|
48
48
|
configuration = {
|
49
49
|
:message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
|
50
50
|
:with => RFC822::EmailAddress,
|
51
|
-
:allow_nil => true
|
51
|
+
:allow_nil => true,
|
52
|
+
:allow_blank => true }
|
52
53
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
53
54
|
|
54
55
|
validates_format_of attr_names, configuration
|
@@ -5,7 +5,8 @@ module ActiveRecord
|
|
5
5
|
configuration = {
|
6
6
|
:message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
|
7
7
|
:with => /\A([1-9]{2})([- ]{0,1})(\d{3}|\d{4})([- ]{0,1})(\d{4})\Z/,
|
8
|
-
:allow_nil => true
|
8
|
+
:allow_nil => true,
|
9
|
+
:allow_blank => true }
|
9
10
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
10
11
|
|
11
12
|
validates_format_of attr_names, configuration
|
data/lib/validates_as_uf_br.rb
CHANGED
@@ -18,6 +18,7 @@ module ActiveRecord
|
|
18
18
|
configuration = {
|
19
19
|
:message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
|
20
20
|
:allow_nil => true,
|
21
|
+
:allow_blank => true,
|
21
22
|
:allow_down => true,
|
22
23
|
:allow_up => true }
|
23
24
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
data/lib/validates_as_website.rb
CHANGED
@@ -5,7 +5,8 @@ module ActiveRecord
|
|
5
5
|
configuration = {
|
6
6
|
:message => I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid' ),
|
7
7
|
:with => /\A(http|https)[:]\/{2}[^\/.]+([.][^\/.]+)+.*\Z/i,
|
8
|
-
:allow_nil => true
|
8
|
+
:allow_nil => true,
|
9
|
+
:allow_blank => true }
|
9
10
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
10
11
|
|
11
12
|
validates_format_of attr_names, configuration
|
@@ -35,7 +35,9 @@ class ValidatesAsUFBRTest < Test::Unit::TestCase
|
|
35
35
|
def test_legal_uf_br
|
36
36
|
values = %w(ac al am ap ba ce df es go ma mg ms mt pa pb pe pi pr rj rn ro rr rs sc se sp to
|
37
37
|
AC AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO)
|
38
|
-
|
38
|
+
|
39
|
+
values.push('')
|
40
|
+
|
39
41
|
values.each do |value|
|
40
42
|
assert TestRecord.new(:uf_br => value).valid?, "#{value} should be legal."
|
41
43
|
end
|
@@ -40,6 +40,8 @@ class ValidatesAsWebsiteTest < Test::Unit::TestCase
|
|
40
40
|
'https://test.com/',
|
41
41
|
'http://www.test.com/test/test/test.html',
|
42
42
|
'https://www.test.com/test/test/test.html?test=test']
|
43
|
+
|
44
|
+
values.push('')
|
43
45
|
|
44
46
|
values.each do |value|
|
45
47
|
assert TestRecord.new(:website => value).valid?, "#{value} should be legal."
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Rafael Barbolo
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-05-
|
20
|
+
date: 2010-05-14 00:00:00 -03:00
|
21
21
|
default_executable:
|
22
22
|
dependencies: []
|
23
23
|
|