crazy_hash_filter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,6 +14,24 @@ Add this line to your application's Gemfile:
14
14
 
15
15
  ## Usage
16
16
 
17
+ You can use hash filter like this:
18
+
19
+ ```ruby
20
+ filtered_hash = CrazyHashFilter.process(hash, rules)
21
+ ```
22
+
23
+ Or shorthand versions:
24
+
25
+ ```ruby
26
+ filtered_hash = hash.crazy_filter(rules)
27
+ ```
28
+
29
+ Filtering in place:
30
+
31
+ ```ruby
32
+ hash.crazy_filter!(rules)
33
+ ```
34
+
17
35
  ### Sample hash
18
36
 
19
37
  ```ruby
@@ -1,5 +1,6 @@
1
1
  require "crazy_hash_filter/version"
2
2
  require "active_support/core_ext/hash/indifferent_access.rb"
3
+ require "crazy_hash_filter/core_ext/hash"
3
4
 
4
5
  module CrazyHashFilter
5
6
 
@@ -0,0 +1,11 @@
1
+ class Hash
2
+
3
+ def crazy_filter(rules)
4
+ CrazyHashFilter.process(self, rules)
5
+ end
6
+
7
+ def crazy_filter!(rules)
8
+ self.replace(self.crazy_filter(rules))
9
+ end
10
+
11
+ end
@@ -1,3 +1,3 @@
1
1
  module CrazyHashFilter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -227,4 +227,28 @@ describe CrazyHashFilter do
227
227
  result[:items].collect { |i| i[:id] }.should include(1)
228
228
  end
229
229
 
230
+ describe "Extending Hash" do
231
+
232
+ it "should define crazy_filter method" do
233
+ rules = { :select => [ :code ] }
234
+
235
+ result = @sample.crazy_filter(rules)
236
+ result[:code].should == 0
237
+ result[:items].should be_nil
238
+ end
239
+
240
+ it "should define crazy_filter! method" do
241
+ rules = { :select => [ :code ] }
242
+
243
+ sample = @sample.clone
244
+
245
+ sample.crazy_filter!(rules)
246
+ sample[:code].should == 0
247
+ sample[:items].should be_nil
248
+ end
249
+
250
+ end
251
+
252
+
253
+
230
254
  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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -33,6 +33,7 @@ files:
33
33
  - Rakefile
34
34
  - crazy_hash_filter.gemspec
35
35
  - lib/crazy_hash_filter.rb
36
+ - lib/crazy_hash_filter/core_ext/hash.rb
36
37
  - lib/crazy_hash_filter/version.rb
37
38
  - spec/crazy_hash_filter_spec.rb
38
39
  - spec/spec_helper.rb