deep_fetch 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +3 -0
- data/deep_fetch.gemspec +2 -0
- data/lib/deep_fetch/core_ext.rb +4 -1
- data/lib/deep_fetch/version.rb +1 -1
- data/spec/deep_fetch_spec.rb +53 -38
- metadata +20 -4
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# DeepFetch
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/pewniak747/deep_fetch.png?branch=master)](http://travis-ci.org/pewniak747/deep_fetch)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/pewniak747/deep_fetch/badge.png?branch=master)](https://coveralls.io/r/pewniak747/deep_fetch)
|
5
|
+
[![Dependency Status](https://gemnasium.com/pewniak747/deep_fetch.png)](https://gemnasium.com/pewniak747/deep_fetch)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/deep_fetch.png)](http://badge.fury.io/rb/deep_fetch)
|
4
7
|
|
5
8
|
Easily fetch values from nested ruby hashes.
|
6
9
|
|
data/deep_fetch.gemspec
CHANGED
data/lib/deep_fetch/core_ext.rb
CHANGED
data/lib/deep_fetch/version.rb
CHANGED
data/spec/deep_fetch_spec.rb
CHANGED
@@ -2,62 +2,77 @@ require 'minitest/spec'
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
|
4
4
|
require_relative '../lib/deep_fetch'
|
5
|
+
require 'coveralls'
|
6
|
+
|
7
|
+
Coveralls.wear!
|
5
8
|
|
6
9
|
describe Hash do
|
7
10
|
describe "deep_fetch" do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
describe "must return value" do
|
12
|
+
it "from shallow hash" do
|
13
|
+
{:foo => :bar}.deep_fetch(:foo).must_equal :bar
|
14
|
+
end
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
it "from block if key was not found" do
|
17
|
+
{:foo => :bar}.deep_fetch(:baz) { :boo } .must_equal :boo
|
18
|
+
end
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end.must_raise(KeyError)
|
20
|
-
end
|
20
|
+
it "from deep hash" do
|
21
|
+
{:foo => {:bar => :baz}}.deep_fetch(:foo, :bar).must_equal :baz
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
it "from block if key not found in deep hash" do
|
25
|
+
{:foo => {:bar => :baz}}.deep_fetch(:foo, :baz) { :boo } .must_equal :boo
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
it "from arrays in deep hash" do
|
29
|
+
{:foo => [nil, {:bar => :baz}]}.deep_fetch(:foo, 1, :bar).must_equal :baz
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end.must_raise(KeyError)
|
34
|
-
end
|
32
|
+
it "of hash from deep hash" do
|
33
|
+
{:foo => {:bar => :baz}}.deep_fetch(:foo).must_equal({:bar => :baz})
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
it "of array from deep hash" do
|
37
|
+
{:foo => {:bar => [:baz]}}.deep_fetch(:foo, :bar).must_equal [:baz]
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
it "of hash from deeper hash" do
|
41
|
+
{:foo => {:bar => {:baz => :boo}}}.deep_fetch(:foo, :bar).must_equal({:baz => :boo})
|
42
|
+
end
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
-
|
45
|
+
describe "must rise KeyError" do
|
46
|
+
it "if key not found in hash and no block provided" do
|
47
|
+
lambda do
|
48
|
+
{:foo => :bar}.deep_fetch(:baz).must_equal
|
49
|
+
end.must_raise(KeyError)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "if key not found in deep hash and no block provided" do
|
53
|
+
lambda do
|
54
|
+
{:foo => {:bar => :baz}}.deep_fetch(:foo, :baz)
|
55
|
+
end.must_raise(KeyError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "must raise KeyError when deep key does not exist" do
|
59
|
+
lambda do
|
60
|
+
{:foo => :bar}.deep_fetch(:foo, :foo)
|
61
|
+
end.must_raise(KeyError)
|
62
|
+
end
|
46
63
|
end
|
47
64
|
|
48
|
-
|
49
|
-
|
65
|
+
describe "must rise ArgumentError" do
|
66
|
+
it "if invoked without arguments" do
|
67
|
+
lambda do
|
68
|
+
{}.deep_fetch
|
69
|
+
end.must_raise(ArgumentError)
|
70
|
+
end
|
50
71
|
end
|
51
72
|
|
52
|
-
it "
|
73
|
+
it "must not evaluate a default block when fetching from deep hash" do
|
53
74
|
bomb = ->() { raise "BOOM" }
|
54
75
|
{:foo => {:bar => :baz}}.deep_fetch(:foo, :bar, &bomb).must_equal :baz
|
55
76
|
end
|
56
|
-
|
57
|
-
it "must raise ArgumentError if invoked without arguments" do
|
58
|
-
lambda do
|
59
|
-
{}.deep_fetch
|
60
|
-
end.must_raise(ArgumentError)
|
61
|
-
end
|
62
77
|
end
|
63
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_fetch
|
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:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: coveralls
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: easily fetch values from nested ruby hashes
|
15
31
|
email:
|
16
32
|
- pewniak747@gmail.com
|
@@ -48,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
64
|
version: '0'
|
49
65
|
requirements: []
|
50
66
|
rubyforge_project:
|
51
|
-
rubygems_version: 1.8.
|
67
|
+
rubygems_version: 1.8.23
|
52
68
|
signing_key:
|
53
69
|
specification_version: 3
|
54
70
|
summary: easily fetch values from nested ruby hashes
|