rails_validations 1.1.1 → 1.1.2
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/README.markdown +45 -14
- data/config/locales/nl.yml +1 -1
- data/lib/validators/date_validator.rb +12 -0
- data/lib/validators/domain_validator.rb +8 -0
- data/lib/validators/iban_validator.rb +1 -1
- data/lib/validators/phone_validator.rb +2 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc1dd77a7c0210226a3a1d51326400739d74839b
|
4
|
+
data.tar.gz: a6d84e924ef157d550e5a1d560eebb69d6801902
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 354295b2cd7f84d48ac1cc619da220cf79ae65205f876118da20bb626fa69f8304d3808836ebc6dcbeb012c165417cceedddf3282bbe8234a7a373d6eaa38d02
|
7
|
+
data.tar.gz: 05fd3b1468787d6252cc663b0fafe84ed6986142133cb523f755bc9d8aabba9661651e3efaacff55eff9cb0b7c5bdc055da629b811e34ba36162e42a03928cf6
|
data/README.markdown
CHANGED
@@ -1,10 +1,24 @@
|
|
1
|
-
|
1
|
+
[](http://badge.fury.io/rb/rails_validations)
|
2
|
+
[](https://travis-ci.org/bluerail/rails_validations)
|
3
|
+
[](https://gemnasium.com/bluerail/rails_validations)
|
4
|
+
[](http://inch-ci.org/github/bluerail/rails_validations)
|
5
|
+
|
6
|
+
|
7
|
+
A few extra validations for Rails.
|
8
|
+
|
9
|
+
We try to do the ‘sane’ thing by not being too strict, when in doubt, we accept
|
10
|
+
input as being valid. We never want to reject valid input as invalid.
|
11
|
+
|
12
|
+
For many formats doing a 100% foolproof check is not trivial, email addresses
|
13
|
+
are a famous example, but it also applies to other formats.
|
14
|
+
Regardless, you can never be sure it’s what the user *intended* anyway. For
|
15
|
+
example, email validators will accept `artin@ico.nl` as being ‘valid’, even
|
16
|
+
though my email address is `martin@lico.nl.`.
|
2
17
|
|
3
|
-
[RubyGems.org entry](http://rubygems.org/gems/rails_validations)
|
4
18
|
|
5
19
|
date
|
6
20
|
----
|
7
|
-
Validate if a column is a valid date, and if it
|
21
|
+
Validate if a column is a valid date, and if it’s before or after another date.
|
8
22
|
|
9
23
|
validates :date_column, date: true
|
10
24
|
validates :date_column, date: { after: Date.today }
|
@@ -13,28 +27,36 @@ Validate if a column is a valid date, and if it's before or after another date.
|
|
13
27
|
validates :date_column, date: { before: Date.today }
|
14
28
|
validates :date_column, date: { before_or_equal_to: Date.today }
|
15
29
|
|
16
|
-
|
30
|
+
Check if the column `enddate` is after the value of the column `begindate`:
|
31
|
+
|
17
32
|
validates :begindate, date: true
|
18
33
|
validates :enddate, date: { after: :begindate }
|
19
34
|
|
20
35
|
|
21
36
|
domain
|
22
37
|
------
|
23
|
-
Validate if a string
|
38
|
+
Validate if a string looks like a valid domain. This should work with [IDN](idn).
|
39
|
+
|
40
|
+
This will accept `lico.nl`, but rejects `martin@lico.nl`:
|
24
41
|
|
25
42
|
validates :domain_column, domain: true
|
26
43
|
|
27
|
-
|
44
|
+
Set a minimum/maximum number of domain parts (aka. labels), this will accept
|
45
|
+
`lico.nl`, but rejects `lico`:
|
46
|
+
|
28
47
|
validates :domain_column, domain: { min_domain_parts: 2 }
|
48
|
+
|
49
|
+
Accept `lico.nl`, but reject `www.lico.nl`:
|
50
|
+
|
29
51
|
validates :domain_column, domain: { max_domain_parts: 2 }
|
30
52
|
|
31
53
|
|
32
54
|
email
|
33
55
|
-----
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
56
|
+
Validate if a string looks liek an email address. This should work with unicode
|
57
|
+
addresses ([RFC 6531][rfc6531], [IDN][idn]).
|
58
|
+
|
59
|
+
Accepts `martin@lico.nl`, but rejects `martinlico.nl` or `martin@lico`
|
38
60
|
|
39
61
|
validates :email_column, email: true
|
40
62
|
|
@@ -49,8 +71,10 @@ Check if this is a valid IBAN account number. This uses the
|
|
49
71
|
|
50
72
|
phone
|
51
73
|
-----
|
52
|
-
Check if this is a valid phone number.
|
53
|
-
|
74
|
+
Check if this is a valid phone number. This should work with most, if not all,
|
75
|
+
writing conventions. We consider a phone to be valid if it consists of numbers &
|
76
|
+
any number of ` \-.()`; a country code at the start indicated with `+` is also
|
77
|
+
accepted.
|
54
78
|
|
55
79
|
validates :phone_column, phone: true
|
56
80
|
|
@@ -73,10 +97,17 @@ Currently implemented countries:
|
|
73
97
|
ChangeLog
|
74
98
|
=========
|
75
99
|
|
100
|
+
version 1.1.2, 20141201
|
101
|
+
-----------------------
|
102
|
+
- Fix typo in Dutch translation.
|
103
|
+
- Update some docs.
|
104
|
+
|
105
|
+
|
76
106
|
version 1.1.1, 20141013
|
77
107
|
-----------------------
|
78
|
-
- Fix i18n key for `phone
|
79
|
-
- Allow passing a Proc to `date` without an argument
|
108
|
+
- Fix i18n key for `phone`.
|
109
|
+
- Allow passing a Proc to `date` without an argument.
|
110
|
+
|
80
111
|
|
81
112
|
version 1.1, 20141003
|
82
113
|
---------------------
|
data/config/locales/nl.yml
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# Validate if a column is a valid date, and if it's before or after another date.
|
2
|
+
#
|
3
|
+
# validates :date_column, date: true
|
4
|
+
# validates :date_column, date: { after: Date.today }
|
5
|
+
# validates :date_column, date: { after_or_equal_to: Date.today }
|
6
|
+
# validates :date_column, date: { equal_to: Date.today }
|
7
|
+
# validates :date_column, date: { before: Date.today }
|
8
|
+
# validates :date_column, date: { before_or_equal_to: Date.today }
|
9
|
+
#
|
10
|
+
# Check if the column `enddate` is after the value of the column `begindate`
|
11
|
+
# validates :begindate, date: true
|
12
|
+
# validates :enddate, date: { after: :begindate }
|
1
13
|
class DateValidator < ActiveModel::EachValidator
|
2
14
|
CHECKS = {
|
3
15
|
# These keys make the most sense for dates
|
@@ -1,3 +1,11 @@
|
|
1
|
+
# Validate if a string is a valid domain. This should work with [IDN](idn).
|
2
|
+
#
|
3
|
+
# validates :domain_column, domain: true
|
4
|
+
#
|
5
|
+
# Set a minimum/maximum number of domain parts (aka. labels)
|
6
|
+
#
|
7
|
+
# validates :domain_column, domain: { min_domain_parts: 2 }
|
8
|
+
# validates :domain_column, domain: { max_domain_parts: 2 }
|
1
9
|
class DomainValidator < ActiveModel::EachValidator
|
2
10
|
#\A[a-zA-Z\d-]{,63}\z
|
3
11
|
REGEXP = /
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Tournoij
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: iban-tools
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '1.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|