deep_fetch 0.0.1 → 0.0.2
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 +2 -0
- data/Rakefile +8 -1
- data/lib/deep_fetch/core_ext.rb +2 -2
- data/lib/deep_fetch/version.rb +1 -1
- data/spec/deep_fetch_spec.rb +10 -0
- data/travis.yml +9 -0
- metadata +4 -3
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/deep_fetch/core_ext.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class Hash
|
2
2
|
def deep_fetch *args, &block
|
3
|
-
|
3
|
+
raise ArgumentError.new("wrong number of arguments (0 for 1..n)") if args.empty?
|
4
4
|
|
5
5
|
value = fetch(args.shift, &block)
|
6
|
-
if value.kind_of?(Hash)
|
6
|
+
if value.kind_of?(Hash) && args.size > 0
|
7
7
|
value.deep_fetch(*args, &block)
|
8
8
|
elsif value.kind_of?(Array) && args.size > 0
|
9
9
|
value = value[args.shift]
|
data/lib/deep_fetch/version.rb
CHANGED
data/spec/deep_fetch_spec.rb
CHANGED
@@ -45,9 +45,19 @@ describe Hash do
|
|
45
45
|
{:foo => {:bar => [:baz]}}.deep_fetch(:foo, :bar).must_equal [:baz]
|
46
46
|
end
|
47
47
|
|
48
|
+
it "must_equal fetch hash from deeper hash" do
|
49
|
+
{:foo => {:bar => {:baz => :boo}}}.deep_fetch(:foo, :bar).must_equal({:baz => :boo})
|
50
|
+
end
|
51
|
+
|
48
52
|
it "must_equal not evaluate a default block when fetching from deep hash" do
|
49
53
|
bomb = ->() { raise "BOOM" }
|
50
54
|
{:foo => {:bar => :baz}}.deep_fetch(:foo, :bar, &bomb).must_equal :baz
|
51
55
|
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
|
52
62
|
end
|
53
63
|
end
|
data/travis.yml
ADDED
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: easily fetch values from nested ruby hashes
|
15
15
|
email:
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/deep_fetch/core_ext.rb
|
28
28
|
- lib/deep_fetch/version.rb
|
29
29
|
- spec/deep_fetch_spec.rb
|
30
|
+
- travis.yml
|
30
31
|
homepage: https://github.com/pewniak747/deep_fetch
|
31
32
|
licenses: []
|
32
33
|
post_install_message:
|
@@ -47,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
48
|
version: '0'
|
48
49
|
requirements: []
|
49
50
|
rubyforge_project:
|
50
|
-
rubygems_version: 1.8.
|
51
|
+
rubygems_version: 1.8.24
|
51
52
|
signing_key:
|
52
53
|
specification_version: 3
|
53
54
|
summary: easily fetch values from nested ruby hashes
|