crazy_hash_filter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,10 @@ require "active_support/core_ext/hash/indifferent_access.rb"
4
4
  module CrazyHashFilter
5
5
 
6
6
  def self.process(hash, rules)
7
+ return nil if hash.nil?
8
+
9
+ raise "Is not a Hash" unless hash.is_a?(Hash)
10
+
7
11
  rules = HashWithIndifferentAccess.new(rules || {}) unless rules.is_a?(HashWithIndifferentAccess)
8
12
  child_rules = rules[:child_rules] || {}
9
13
  result = {}
@@ -1,3 +1,3 @@
1
1
  module CrazyHashFilter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -185,4 +185,46 @@ describe CrazyHashFilter do
185
185
  result[:items].collect { |i| i[:id] }.should_not include(2)
186
186
  end
187
187
 
188
+ it "should deal with nil values" do
189
+ sample = {
190
+ :code => 0,
191
+ :items => [
192
+ { :id => 1,
193
+ :title => nil,
194
+ :thumbs => nil
195
+ },
196
+ { :id => 2,
197
+ :title => 'Second item',
198
+ :thumbs => [
199
+ { :code => '50', :url => 'http://some-url/2/50' },
200
+ { :code => '100', :url => 'http://some-url/2/100' },
201
+ { :code => '150', :url => 'http://some-url/2/150' }
202
+ ]
203
+ },
204
+ ]
205
+ }
206
+
207
+ rules = {
208
+ :select => [ :code, :items ],
209
+
210
+ :child_rules => {
211
+ :items => {
212
+ :select => [ :id, :thumbs ],
213
+
214
+ :child_rules => {
215
+ :thumbs => {
216
+ :conditions => {
217
+ :code => '50'
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+
225
+ result = CrazyHashFilter.process(sample, rules)
226
+
227
+ result[:items].collect { |i| i[:id] }.should include(1)
228
+ end
229
+
188
230
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crazy_hash_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-08-07 00:00:00.000000000 Z
15
+ date: 2012-08-17 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description: Hash filtering by advanced rules
18
18
  email: