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 +4 -4
- data/README.md +6 -0
- data/lib/lab42/diggy_methods/version.rb +1 -1
- data/lib/lab42/diggy_methods.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3052880cc5f39b51c1ee8264afb99d24ddf2dc6625a8a50131c22a3511a3f6f4
|
4
|
+
data.tar.gz: 466ec786a0722d71c35d7bda70525c0f277c008e4b6d86d23fa1e666ec3953a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/lab42/diggy_methods.rb
CHANGED
@@ -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
|
-
@
|
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__: @
|
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
|
-
@
|
63
|
-
found = @data.fetch(name) { raise KeyError, "key not found: #{@
|
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
|
+
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/
|
28
|
+
homepage: https://github.com/robertdober/diggy_methods
|
29
29
|
licenses:
|
30
30
|
- Apache-2.0
|
31
31
|
metadata: {}
|