lab42_diggy_methods 0.1.4 → 0.1.6

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
  SHA256:
3
- metadata.gz: d8cbaf0bd7f78a40b8b5a1583c0bf075877e7158c04c7f7295661e497cfbc42d
4
- data.tar.gz: 425adc58abfa6e92a3d1e4a599db1b5f39df7da1aa4f40b025e25c71b48a86ad
3
+ metadata.gz: 3052880cc5f39b51c1ee8264afb99d24ddf2dc6625a8a50131c22a3511a3f6f4
4
+ data.tar.gz: 466ec786a0722d71c35d7bda70525c0f277c008e4b6d86d23fa1e666ec3953a3
5
5
  SHA512:
6
- metadata.gz: 331c2a205746618e0e868b110da0128296ab63b5f8047a1935f0fee27cf22a0b25d8da7760324f8e350f984a8044378ff194f7853d7152a2c3b7d76c6f29da3b
7
- data.tar.gz: 577292e722386233c97d435cf6bfbac4fbcb3111179facf7dda176c45638dae6d962d8141d1af9f8363b38e2d64c971a9f50a1e9fcf2d1b7ed5191eeabd544a1
6
+ metadata.gz: caef67120413bd91d84630ab0414e0c598d2d00908579b4050a6f15b4833baaf5ca81bdec5c11c6f6ecdb4f70a7ce1b97619262e1b26028315130499b0e33534
7
+ data.tar.gz: e795c99a9d373a9effe7a41554d0c0e796f2c823a94bad7c97d436f5ee5c3c8144fcb011b8c1d22dec1488a4b9299a6f9f3226440f24ae9d0dccf5c2f74cbabd
data/README.md CHANGED
@@ -63,6 +63,12 @@ And in case of missing keys
63
63
  expect{ diggy.b.d.f }.to raise_error(KeyError, "key not found: b.d.f")
64
64
  ```
65
65
 
66
+ And this works for arrays too:
67
+ ```ruby
68
+ with_array = Diggy(a: [b: {}])
69
+ expect { with_array.a.first.b.c }.to raise_error(KeyError, "key not found: a.b.c")
70
+ ```
71
+
66
72
  If we access unknown keys we get the usual `KeyError` error, however we must not pass, nonhashable data
67
73
 
68
74
  But if we pass an array
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lab42
4
4
  class DiggyMethods
5
- VERSION = "0.1.4"
5
+ VERSION = "0.1.6"
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
@@ -14,7 +14,7 @@ module Lab42
14
14
 
15
15
  def initialize(a=nil, __key_chain__: [], **data_)
16
16
  @data = _make_data_from_args(a, data_)
17
- @keychain = __key_chain__
17
+ @key_chain = __key_chain__
18
18
  end
19
19
 
20
20
  def _make_data_from_args(a, data_)
@@ -47,20 +47,20 @@ module Lab42
47
47
  end
48
48
 
49
49
  def _make_diggy_array(found)
50
- found.map { self.class.new(_1) }
50
+ found.map { self.class.new(_1, __key_chain__: @key_chain) }
51
51
  end
52
52
 
53
53
  def _maybe_make_diggy(found)
54
54
  if found.respond_to?(:to_h)
55
- self.class.new(**found, __key_chain__: @keychain)
55
+ self.class.new(**found, __key_chain__: @key_chain)
56
56
  else
57
57
  found
58
58
  end
59
59
  end
60
60
 
61
61
  def _method_missing_try_descend(name)
62
- @keychain << name
63
- found = @data.fetch(name) { raise KeyError, "key not found: #{@keychain.join(".")}" }
62
+ @key_chain << name
63
+ found = @data.fetch(name) { raise KeyError, "key not found: #{@key_chain.join(".")}" }
64
64
  if Array === found
65
65
  _make_diggy_array(found)
66
66
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_diggy_methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
@@ -25,7 +25,7 @@ files:
25
25
  - lib/lab42/diggy_methods.rb
26
26
  - lib/lab42/diggy_methods/kernel.rb
27
27
  - lib/lab42/diggy_methods/version.rb
28
- homepage: https://github.com/robertdober/lab42_diggy_methods
28
+ homepage: https://github.com/robertdober/diggy_methods
29
29
  licenses:
30
30
  - Apache-2.0
31
31
  metadata: {}