hash_validator 0.2.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcfb909853b164442c3070897b294b05aad88a35
4
- data.tar.gz: 6168c0b13dac5c47959bd9d8b98edaa82710857a
3
+ metadata.gz: 09fcad8b45bef6d76eff9d52feec81e116383136
4
+ data.tar.gz: 0be312504f4b8365d39cf4641a9533c2d010c209
5
5
  SHA512:
6
- metadata.gz: ee681f842e79645713cc7775eaf2e4d57cda92a90b52052e34d8a1b92717328a227b09f5c272d633753f3363e47f3cad899c24ffb9751836caf6cda75bdbb99c
7
- data.tar.gz: e053babc5e9091973d04680c5a64e5aa11365701cfe1fc3e164a174341f3079bb48e6b9965009e2c58d988fdbb491c674a4f2b5ea28f6b09bf9ba15c0ccb669d
6
+ metadata.gz: 1c2f78699dddc2bd3652ae9ef371cebdf0ad560b361621c882c8c06bc7ebdd89ad3588f18fc29f9aa7348119ea0f02b588c6cf71eff58dc9da357d04301eadc4
7
+ data.tar.gz: fb82f77a46c71ca978b19919aa511e467d9ea45265bb652f4fadbf069b5f47801582e8372f1ccd382602582375d871ffd7782e92fae7121fbc2c8b881a0c5f80
data/README.md CHANGED
@@ -64,9 +64,16 @@ validator.errors
64
64
 
65
65
  Define a validation hash which will be used to validate. This has can be nested as deeply as required using the following values to validate specific value types:
66
66
 
67
- * `string`
68
- * `numeric`
69
67
  * `array`
68
+ * `complex`
69
+ * `float`
70
+ * `integer`
71
+ * `numeric`
72
+ * `range`
73
+ * `rational`
74
+ * `regexp`
75
+ * `string`
76
+ * `symbol`
70
77
  * `time`
71
78
  * `required`: just requires any value to be present for the designated key.
72
79
  * hashes are validates by nesting validations, or if just the presence of a hash is required `{}` can be used.
@@ -1,8 +1,16 @@
1
1
  [
2
- [ 'array', Array ],
3
- [ 'numeric', Numeric ],
4
- [ 'string', String ],
5
- [ 'time', Time ]
6
- ].each do |name, klass|
7
- HashValidator.append_validator(HashValidator::Validator::SimpleValidator.new(name, lambda { |v| v.is_a?(klass) }))
2
+ Array,
3
+ Complex,
4
+ Float,
5
+ Integer,
6
+ Numeric,
7
+ Range,
8
+ Rational,
9
+ Regexp,
10
+ String,
11
+ Symbol,
12
+ Time
13
+ ].each do |type|
14
+ name = type.to_s.gsub(/(.)([A-Z])/,'\1_\2').downcase # ActiveSupport/Inflector#underscore behaviour
15
+ HashValidator.append_validator(HashValidator::Validator::SimpleValidator.new(name, lambda { |v| v.is_a?(type) }))
8
16
  end
@@ -1,3 +1,3 @@
1
1
  module HashValidator
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -5,17 +5,45 @@ describe 'Simple validator types' do
5
5
 
6
6
  # Simple types
7
7
  {
8
- string: {
9
- valid: [ '', 'Hello World', '12345' ],
10
- invalid: [ nil, 12345, Time.now ]
8
+ array: {
9
+ valid: [ [], [1], ['foo'], [1,['foo'],Time.now] ],
10
+ invalid: [ nil, '', 123, '123', Time.now, '[1]' ]
11
+ },
12
+ complex: {
13
+ valid: [ Complex(1), Complex(2, 3), Complex('2/3+3/4i'), 0.3.to_c ],
14
+ invalid: [ nil, '', 123, '123', Time.now, '[1]', [1], '2/3+3/4i', Rational(2, 3) ]
15
+ },
16
+ float: {
17
+ valid: [ 0.0, 1.1, 1.23, Float::INFINITY, Float::EPSILON ],
18
+ invalid: [ nil, '', 0, 123, '123', Time.now, '[1]', '2013-03-04' ]
19
+ },
20
+ integer: {
21
+ valid: [ 0, -1000000, 1000000 ],
22
+ invalid: [ nil, '', 1.1, '123', Time.now, '[1]', '2013-03-04' ]
11
23
  },
12
24
  numeric: {
13
25
  valid: [ 0, 123, 123.45 ],
14
26
  invalid: [ nil, '', '123', Time.now ]
15
27
  },
16
- array: {
17
- valid: [ [], [1], ['foo'], [1,['foo'],Time.now] ],
18
- invalid: [ nil, '', 123, '123', Time.now, '[1]' ]
28
+ range: {
29
+ valid: [ 0..10, 'a'..'z', 5..0 ],
30
+ invalid: [ nil, '', '123', Time.now ]
31
+ },
32
+ rational: {
33
+ valid: [ Rational(1), Rational(2, 3), 3.to_r ],
34
+ invalid: [ nil, '', 123, '123', Time.now, '[1]', [1], Complex(2, 3) ]
35
+ },
36
+ regexp: {
37
+ valid: [ /[a-z]+/, //, //i, Regexp.new('.*') ],
38
+ invalid: [ nil, '', 123, '123', Time.now, '.*' ]
39
+ },
40
+ string: {
41
+ valid: [ '', 'Hello World', '12345' ],
42
+ invalid: [ nil, 12345, Time.now ]
43
+ },
44
+ symbol: {
45
+ valid: [ :foo, :'', 'bar'.to_sym ],
46
+ invalid: [ nil, '', 1.1, '123', Time.now, '[1]', '2013-03-04' ]
19
47
  },
20
48
  time: {
21
49
  valid: [ Time.now ],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Brooks