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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eab46da124d8b557aba990b551706b502c783ba2
4
- data.tar.gz: 3f987b3c7df58d46b4706c7c065fa9f28039f9ec
3
+ metadata.gz: 3378211ad8e81066fc271f8d05f210aadca6d4b6
4
+ data.tar.gz: b3a26e7f50598d6230fb941a97a968a594f4b94e
5
5
  SHA512:
6
- metadata.gz: e2941168595f835f2f151cf7776443f758a46a42a04ee81c6fe28b50818ce69cb1acc551253dcdb58ebbdacd3fe74acc80e11d1fe6e2e81d85e6501a5235c5a1
7
- data.tar.gz: 864af824911a22758af38807ec0d7f2881c241feda3f19ffab93f0f3f0f0b0ca0eabb55e65d399a06fc4667b53555b6425522f23f42bc9c04f68cd0a5dbf4ca9
6
+ metadata.gz: 0f4f749dbfab4333630fd286b314ae1a80409bb12b09630630468826338b80c0ac721758e890055a4fdce2bd9dac5ba84c98ace12bfe2a7b3a2913798236b488
7
+ data.tar.gz: 43124db5a290ca64bf03c91c1af8c1b5c89a31561914f503bad4fb00394d6c1a977e0886ce77270346664da1dfcb65aaf4ef140dc84cb6c4b196af6e35eeb10d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deep_fetch (0.0.3)
4
+ deep_fetch (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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) }
@@ -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 value.kind_of?(Hash) && args.size > 0
7
- value.deep_fetch(*args, &block)
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
- value
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
@@ -1,3 +1,3 @@
1
1
  module DeepFetch
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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
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: []