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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c7c506c170e95600888b44e102b565f4c6fa3fe52bf7dcd34c935d204e9980a
4
- data.tar.gz: df9c49145cd0780be53b8e1fbc4c568d53064cb35200839d3f80baace035b0b3
3
+ metadata.gz: 7f9642e13d0932c3f95de27b981501ef89e4f73f02cb2befaee5ef583294b5eb
4
+ data.tar.gz: 6677dde97b01b2a652a06ceb755371ddc13eb6ce6c935eb38a123518c7da37ad
5
5
  SHA512:
6
- metadata.gz: f316245eed051450bd831d7b378376ba4e9fbd515b4efad4b670aeed2949a98de239d2ec2d81db5067272c446b067a86ab805b90779cd73afc412ec9539b93a1
7
- data.tar.gz: c7965c692a9ce203a079482a939b6f3f6ff16a60fcc2307fd4fcfeb40224a5a20c42c4c687f64c6e1f6375e5bff5ebe07ae995111e660e08fd255095c3d2fd3d
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lab42
4
4
  class DiggyMethods
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
@@ -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.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-31 00:00:00.000000000 Z
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