hash_params 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -2
  3. data/lib/hash_params.rb +1 -10
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9139c3fc879993adc169ef1d17d5c5041e9485ee
4
- data.tar.gz: 7d1b1803fa43616a4c413b4b0712d1a2e6d435ba
3
+ metadata.gz: abdd09167a6fd3901a89dffde275cd74b5e5a826
4
+ data.tar.gz: 5b08703d583b1cbe23dd78a31f79394a237aebf4
5
5
  SHA512:
6
- metadata.gz: e4cc43d988d6884e450e80829a67feb2eeb19cc48a9b3bb71dff91dde41e2db68db625ed68b05a9ec3234a496bad7c6d7164426061df2c1d8da4d26e2bb6ee7b
7
- data.tar.gz: 103591043e96fae420e6c5457fdf91e519633bf27b3ab9025a2ff4372adb09c445ec8060ad87f70ac023c78a5462a419c3d83dc67a752abac2ae065d6cd785b5
6
+ metadata.gz: 6e8d8e6e267c324e6dced4200cad1e4d5540cd0cd73f192f3b66a634c096a436a5d6afd100e7349f37c5442c40dc97ae2155f0cb31cbc4b2684fda6478086aa6
7
+ data.tar.gz: 4f1c4ea78c5a726d4d37401235941efa4a09f568301e84ab82396056b3bef8dd958d24e9621714405e81b435fe0018fd8cbd432f1c64702525d23b31c65bc917
data/README.md CHANGED
@@ -26,6 +26,7 @@ describe HashParams do
26
26
  some_string: 'this is a test string' ,
27
27
  is_true: 'true',
28
28
  is_false: 'f',
29
+ recursive: {}
29
30
  }
30
31
  ) do
31
32
  param :doesnt_exist, required: true
@@ -47,6 +48,10 @@ describe HashParams do
47
48
  param :missing_with_validation, coerce: Integer, :default => 60 * 60, :validate => lambda { |v| v >= 60 * 60 }
48
49
  param :is_true, coerce: :boolean
49
50
  param :is_false, coerce: :boolean
51
+ #recursive
52
+ param :recursive do
53
+ param :wasnt_here_before, default: true
54
+ end
50
55
  end
51
56
  }
52
57
 
@@ -59,13 +64,16 @@ describe HashParams do
59
64
  r[:renamed].must_equal :to_be_renamed
60
65
  r[:integer_coercion].must_equal 1
61
66
  r[:bad_number].must_equal 12.0
62
- #no deep coersion
67
+
63
68
  r[:array_with_delim].must_equal ["1", "2", "3"]
64
69
  r[:hash_as_string].must_equal ({ "a" => "1", "b" => "2", "c" => "d" })
65
70
  r[:missing_with_validation].must_equal 60 * 60
66
71
  r[:is_true].must_equal true
67
72
  r[:is_false].must_equal false
68
73
 
74
+ #recursive checking
75
+ r[:recursive][:wasnt_here_before].must_equal true
76
+
69
77
  #failed items don't show up
70
78
  r.errors.size.must_equal 2
71
79
  r[:doesnt_exist].must_be_nil
@@ -86,7 +94,6 @@ describe HashParams do
86
94
 
87
95
  end
88
96
 
89
-
90
97
  ```
91
98
 
92
99
 
data/lib/hash_params.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  class HashParams < Hash
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  attr :valid, :errors
4
4
 
5
- def self.ping
6
- 'ping'
7
- end
8
5
  def initialize(opts={}, injection_target =nil, &code)
9
6
  @incoming_hash = opts
10
7
  @errors =[]
@@ -16,10 +13,6 @@ class HashParams < Hash
16
13
 
17
14
  def param(key, h = {})
18
15
 
19
-
20
-
21
-
22
-
23
16
  #What happens if value is FalseClass ? Need something a little better
24
17
  val = @incoming_hash[key] || @incoming_hash[key.to_sym] || @incoming_hash[key.to_s]
25
18
  if val.nil? && h[:default]
@@ -34,7 +27,6 @@ class HashParams < Hash
34
27
  val = coerce(val, c, h)
35
28
  end
36
29
 
37
-
38
30
  #coersion could return a nil which won't validate, it could return a false which will attempt to validate
39
31
  if validate!(val, h)
40
32
  #The value is valid add it
@@ -153,5 +145,4 @@ class HashParams < Hash
153
145
  return true if object.respond_to?(:empty) && object.empty
154
146
  return false
155
147
  end
156
-
157
148
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Uckun