lab42_diggy_methods 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/lab42/diggy_methods/version.rb +1 -1
- data/lib/lab42/diggy_methods.rb +8 -0
- 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: 7f9642e13d0932c3f95de27b981501ef89e4f73f02cb2befaee5ef583294b5eb
|
4
|
+
data.tar.gz: 6677dde97b01b2a652a06ceb755371ddc13eb6ce6c935eb38a123518c7da37ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93bf1546ea98a27bf88a16180be58b32616af3c70f8418a1a9978f76b2cdd14083acf144c8f215441a1fa81fdb1a7ed7484f941103a62a25f37748161255c61f
|
7
|
+
data.tar.gz: 649f3fb72dea384c11a2f86d17c09836dd4b88cfc8762876aa180f0897466f9a01219942e0c99228a36eae5a31b2c24c5d4f9428c217bd2bfb301c695f93ecfe
|
data/README.md
CHANGED
@@ -48,6 +48,16 @@ Then we can access its fields as follows
|
|
48
48
|
expect(diggy.b.d.e).to eq(3)
|
49
49
|
```
|
50
50
|
|
51
|
+
And we can use a shortcut for `key.__data__` by using `key!`A
|
52
|
+
```ruby
|
53
|
+
expect(diggy.b.d!).to eq(e: 3)
|
54
|
+
```
|
55
|
+
|
56
|
+
And that works for leave nodes too of course
|
57
|
+
```ruby
|
58
|
+
expect(diggy.a!).to eq(1)
|
59
|
+
```
|
60
|
+
|
51
61
|
And in case of missing keys
|
52
62
|
```ruby
|
53
63
|
expect{ diggy.b.d.f }.to raise_error(KeyError, "key not found: :f")
|
@@ -79,6 +89,7 @@ Then we can pass the binding to the template
|
|
79
89
|
```ruby
|
80
90
|
expect(ERB.new(template_text).result(data.__binding__)).to eq("YHS")
|
81
91
|
```
|
92
|
+
|
82
93
|
# LICENSE
|
83
94
|
|
84
95
|
Copyright 2022 Robert Dober robert.dober@gmail.com
|
data/lib/lab42/diggy_methods.rb
CHANGED
@@ -38,6 +38,14 @@ module Lab42
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def method_missing(name)
|
41
|
+
if name.to_s.end_with?"!"
|
42
|
+
@data.fetch(name.to_s.sub(/!\z/, "").to_sym)
|
43
|
+
else
|
44
|
+
_method_missing_try_descend(name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def _method_missing_try_descend(name)
|
41
49
|
found = @data.fetch(name)
|
42
50
|
if found.respond_to?(:to_h)
|
43
51
|
self.class.new(**found)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01
|
11
|
+
date: 2022-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Create an instance of me with a Hash and access the (nested) values
|