validates_simple 0.0.2 → 0.0.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.
- checksums.yaml +4 -4
- data/README.md +45 -0
- data/lib/validates_simple.rb +1 -1
- data/lib/validation/rules.rb +1 -1
- data/spec/validation_spec.rb +6 -3
- metadata +4 -3
- data/README +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08fcb5de3cf9ef6dadd9d4c51960683c0430e58c
|
4
|
+
data.tar.gz: 5e204a2105312c35704f3302b5ad7c53f0db8139
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bdaa68f65acc4498af7b52424a47cd272fa93439bd60622f9c6f88527531bee11fa008135aa864bff5bb85d241d15e7f44e13d542322991d598e3020ae991af
|
7
|
+
data.tar.gz: 60fdc95d3a5531ed5569cbc38b644ecc0d2f7e1db39d5714e5918f3ec7edecd6539015ba6c73cb554562d5ee1d71b6419429ec4c07fbeef32fbe5bb730096a7e
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Simple validator that validates hashes
|
2
|
+
|
3
|
+
I needed a simple validation utility that i can use to validate params,
|
4
|
+
json etc. So i am creating one.
|
5
|
+
|
6
|
+
1. It should provide an easy way to add additional validations
|
7
|
+
|
8
|
+
module Validation
|
9
|
+
module Rules
|
10
|
+
def my_custom_validation(field, message='')
|
11
|
+
callback = lambda do | data |
|
12
|
+
if data[field] == something_special
|
13
|
+
true
|
14
|
+
else
|
15
|
+
false
|
16
|
+
end
|
17
|
+
validates(field, callback, message)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
2. It can reuse defined validations when defining one
|
23
|
+
|
24
|
+
module Validation
|
25
|
+
module Rules
|
26
|
+
def validates_numericality_of(field, message='')
|
27
|
+
validates_presence_of(field)
|
28
|
+
validates_format_of(field, /^\d+(\.\d+)?$/
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
3. It should provide some predefined validations
|
34
|
+
* validates_presence_of - checks if the field is present and it is not nil or empty string
|
35
|
+
* validates_confirmation_of - checks if a field is confirmed by checking filed\_confirmation value
|
36
|
+
* validates_format_of - checks if a field is in a given format
|
37
|
+
* validates_numericality_of - checks if a field is a correct number format
|
38
|
+
* validates_greather_then - checks if a field is greather then some value
|
39
|
+
* validates_less_then - checks if a field is less then some value
|
40
|
+
* etc
|
41
|
+
|
42
|
+
For additional info check the specs for usage [validates simple specs](https://github.com/sirfilip/validates_simple/blob/master/spec/validation_spec.rb)
|
43
|
+
|
44
|
+
|
45
|
+
License: MIT
|
data/lib/validates_simple.rb
CHANGED
data/lib/validation/rules.rb
CHANGED
data/spec/validation_spec.rb
CHANGED
@@ -18,10 +18,13 @@ describe Validation do
|
|
18
18
|
validator.should_not be_valid
|
19
19
|
end
|
20
20
|
|
21
|
-
it "succeeds if field is inside the hash" do
|
21
|
+
it "succeeds if field is inside the hash and it is a non blank string or nil" do
|
22
22
|
validator.validates_presence_of('fieldname', ':field is required')
|
23
|
-
validator.validate({'fieldname' => ''}).should be_true
|
24
|
-
validator.should
|
23
|
+
validator.validate({'fieldname' => 'someval'}).should be_true
|
24
|
+
validator.validate({'fieldname' => 123}).should be_true
|
25
|
+
validator.validate({'fieldname' => nil}).should be_false
|
26
|
+
validator.validate({'fieldname' => ''}).should be_false
|
27
|
+
validator.validate({'fieldname' => ' '}).should be_false
|
25
28
|
end
|
26
29
|
|
27
30
|
it "returns the correct error message" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filip Kostovski
|
@@ -30,7 +30,7 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
-
- README
|
33
|
+
- README.md
|
34
34
|
- lib/validates_simple.rb
|
35
35
|
- lib/validation/error.rb
|
36
36
|
- lib/validation/rules.rb
|
@@ -61,4 +61,5 @@ rubygems_version: 2.1.11
|
|
61
61
|
signing_key:
|
62
62
|
specification_version: 4
|
63
63
|
summary: makes validation simple
|
64
|
-
test_files:
|
64
|
+
test_files:
|
65
|
+
- spec/validation_spec.rb
|