deep_fetch 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/deep_fetch.gemspec +1 -0
- data/lib/deep_fetch/core_ext.rb +10 -8
- data/lib/deep_fetch/version.rb +1 -1
- data/spec/deep_fetch_spec.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3378211ad8e81066fc271f8d05f210aadca6d4b6
|
4
|
+
data.tar.gz: b3a26e7f50598d6230fb941a97a968a594f4b94e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f4f749dbfab4333630fd286b314ae1a80409bb12b09630630468826338b80c0ac721758e890055a4fdce2bd9dac5ba84c98ace12bfe2a7b3a2913798236b488
|
7
|
+
data.tar.gz: 43124db5a290ca64bf03c91c1af8c1b5c89a31561914f503bad4fb00394d6c1a977e0886ce77270346664da1dfcb65aaf4ef140dc84cb6c4b196af6e35eeb10d
|
data/Gemfile.lock
CHANGED
data/deep_fetch.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.description = %q{easily fetch values from nested ruby hashes}
|
12
12
|
gem.summary = %q{easily fetch values from nested ruby hashes}
|
13
13
|
gem.homepage = "https://github.com/pewniak747/deep_fetch"
|
14
|
+
gem.license = 'MIT'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/deep_fetch/core_ext.rb
CHANGED
@@ -3,17 +3,19 @@ class Hash
|
|
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
|
7
|
-
value.
|
8
|
-
elsif value.kind_of?(Array) && args.size > 0
|
9
|
-
value = value[args.shift]
|
10
|
-
if args.size > 0
|
6
|
+
if args.size > 0
|
7
|
+
if value.kind_of?(Hash)
|
11
8
|
value.deep_fetch(*args, &block)
|
9
|
+
elsif value.kind_of?(Array)
|
10
|
+
value = value[args.shift]
|
11
|
+
if args.size > 0
|
12
|
+
value.deep_fetch(*args, &block)
|
13
|
+
else
|
14
|
+
value
|
15
|
+
end
|
12
16
|
else
|
13
|
-
|
17
|
+
{}.fetch(args.shift, &block)
|
14
18
|
end
|
15
|
-
elsif args.size > 0
|
16
|
-
{}.fetch(args.shift, &block)
|
17
19
|
else
|
18
20
|
value
|
19
21
|
end
|
data/lib/deep_fetch/version.rb
CHANGED
data/spec/deep_fetch_spec.rb
CHANGED
@@ -44,6 +44,10 @@ describe Hash do
|
|
44
44
|
it "from nested array" do
|
45
45
|
{:foo => {:bar => [:baz]}}.deep_fetch(:foo, :bar, 0).must_equal(:baz)
|
46
46
|
end
|
47
|
+
|
48
|
+
it "of hash from deeper hash from nested array" do
|
49
|
+
{:foo => {:bar => [{:baz => :boo}]}}.deep_fetch(:foo, :bar, 0).must_equal({:baz => :boo})
|
50
|
+
end
|
47
51
|
end
|
48
52
|
|
49
53
|
describe "must rise KeyError" do
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Pewiński
|
@@ -30,7 +30,8 @@ files:
|
|
30
30
|
- lib/deep_fetch/version.rb
|
31
31
|
- spec/deep_fetch_spec.rb
|
32
32
|
homepage: https://github.com/pewniak747/deep_fetch
|
33
|
-
licenses:
|
33
|
+
licenses:
|
34
|
+
- MIT
|
34
35
|
metadata: {}
|
35
36
|
post_install_message:
|
36
37
|
rdoc_options: []
|