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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f9949fe996226194c61730616ea523a5f678fd2
4
- data.tar.gz: 296e5ff62981a94dab1be3ffb8e581e482c8a0ee
3
+ metadata.gz: 08fcb5de3cf9ef6dadd9d4c51960683c0430e58c
4
+ data.tar.gz: 5e204a2105312c35704f3302b5ad7c53f0db8139
5
5
  SHA512:
6
- metadata.gz: a8429e05ccdb090e998cbcb101cc27de6840d2ec6f23939c61ada894667466519dc3b558f0de530c4c1c18d3b4eaa3d7a26be80d4e14ddb8d4515fd729e7a980
7
- data.tar.gz: 57fe130c39e20a3d80c83927cdb523bec1dea3a623406b85e4f11d5484184952454fe9776b37202bf4b02fde2ce04d5ff35ff6061a1d1e988127f01b2e48d182
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
@@ -3,5 +3,5 @@ require File.expand_path('../validation/rules', __FILE__)
3
3
  require File.expand_path('../validation/validator', __FILE__)
4
4
 
5
5
  module Validation
6
- VERSION = '0.0.2'
6
+ VERSION = '0.0.3'
7
7
  end
@@ -7,7 +7,7 @@ module Validation
7
7
 
8
8
  def validates_presence_of(field, message='')
9
9
  callback = lambda do |data|
10
- if data.has_key? field
10
+ if data.has_key?(field) && data[field].to_s !~ /^\s*$/
11
11
  true
12
12
  else
13
13
  false
@@ -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 be_valid
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.2
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
data/README DELETED
@@ -1,6 +0,0 @@
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
- License: MIT