validation_rules 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -1
- data/lib/validation_rules/validation_rules.rb +10 -0
- data/lib/validation_rules/version.rb +1 -1
- data/spec/validation_rules_spec.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjM3M2UyODU5MjM1MjQ0NWQ1NDZiNTQwZjJiMmM1NTE1NzM4ZTBiNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDAxZTdlNDdmYTg3OTMxZDJiYmVlNDAyZWUxYzI0YWExNTlkYjg3Yg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmY4Yzc3M2RkMmE4ZDJhNDQwYWYwMWJhNDdjN2MwNTFhODRkYmRmOTQ1MjMw
|
10
|
+
MGYwMjJmZDQ4NTExMjZmYjQxZjc3MTk4MzE3YWZjYTQzNTg5ZTM1ZDU5OTI1
|
11
|
+
MTQ3YTg5MDQxY2JjNGM3MTY0NGI4ZmQ4MGI3MDc1YmZkNzM4MTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzlmNjgwOTQwNmNkNDUzZmUzMjFlMTM2NTA1ZTQzMDVjMTRjYzg5ZGRiOWEy
|
14
|
+
YWUwMDI5YjM4ZTZhZmM1ZmI3NzZlNDA1NGJlOWZjMjI3MTc0NGVkZjg4MDdm
|
15
|
+
YjU4YmNhZjljZTMwZDg1NWNkMzUzMjJmYWM4YWIxMmIzYjA0ODM=
|
data/README.md
CHANGED
@@ -14,6 +14,8 @@ module ValidationRules
|
|
14
14
|
NUMERIC_REGEX = /^[0-9]+$/
|
15
15
|
DATE_REGEX = /^((?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])$/
|
16
16
|
ISO8601_REGEX = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?)?$/
|
17
|
+
IP_REGEX = /^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/
|
18
|
+
UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
17
19
|
|
18
20
|
def self.alpha(value)
|
19
21
|
value =~ ALPHA_REGEX
|
@@ -161,4 +163,12 @@ module ValidationRules
|
|
161
163
|
false
|
162
164
|
end
|
163
165
|
end
|
166
|
+
|
167
|
+
def self.ip_address(value)
|
168
|
+
value =~ IP_REGEX
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.uuid(value)
|
172
|
+
value =~ UUID_REGEX
|
173
|
+
end
|
164
174
|
end
|
@@ -403,4 +403,28 @@ describe ValidationRules do
|
|
403
403
|
subject.url('example.com/some path').should be_false
|
404
404
|
end
|
405
405
|
end
|
406
|
+
|
407
|
+
describe '.ip_address' do
|
408
|
+
it 'allows valid IP addresses' do
|
409
|
+
subject.ip_address('1.1.1.1').should be_true
|
410
|
+
subject.ip_address('255.255.255.255').should be_true
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'rejects invalud IP addresses' do
|
414
|
+
subject.ip_address('localhost').should be_false
|
415
|
+
subject.ip_address('a.b.c.d').should be_false
|
416
|
+
subject.ip_address('255.255.255.256').should be_false
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
describe '.uuid' do
|
421
|
+
it 'allows valid UUIDs' do
|
422
|
+
subject.uuid('01234567-9ABC-DEF0-1234-56789ABCDEF0').should be_true
|
423
|
+
end
|
424
|
+
|
425
|
+
it 'rejects invalid UUIDs' do
|
426
|
+
subject.uuid('invalid').should be_false
|
427
|
+
subject.uuid('ABCD-EFG-HIJ-KLM-NOP').should be_false
|
428
|
+
end
|
429
|
+
end
|
406
430
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_rules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Gotterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|