crazy_hash_filter 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.
- data/README.md +18 -0
- data/lib/crazy_hash_filter.rb +1 -0
- data/lib/crazy_hash_filter/core_ext/hash.rb +11 -0
- data/lib/crazy_hash_filter/version.rb +1 -1
- data/spec/crazy_hash_filter_spec.rb +24 -0
- metadata +2 -1
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
|
data/lib/crazy_hash_filter.rb
CHANGED
|
@@ -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.
|
|
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
|