lab42_diggy_methods 0.1.0 → 0.1.1

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: a830d7be026a2a9d2d71c16d0a1c0b515e2ddcbc43b6a9511dc1746cc5f1bd37
4
- data.tar.gz: 51b16cbf743a665c67fd3a3e5856139bc2aea48e860daef4d41274efb66b4842
3
+ metadata.gz: 7c7c506c170e95600888b44e102b565f4c6fa3fe52bf7dcd34c935d204e9980a
4
+ data.tar.gz: df9c49145cd0780be53b8e1fbc4c568d53064cb35200839d3f80baace035b0b3
5
5
  SHA512:
6
- metadata.gz: 5cc260531aea413f7cbb7d80b87e8e6580a297852a9c8caf8bfc0b2195d9e9dabc826aa80d6367f8b70906427aa57de45ea1210994d791234c9d00188aa1ffac
7
- data.tar.gz: 33fd3fec59836489cb4e66a9192055c30d37aa1bbfc264984409c844f409d2458e08be1325b81a3568b8f7ff015115ea58f9fd9a906b9d129806339deb395779
6
+ metadata.gz: f316245eed051450bd831d7b378376ba4e9fbd515b4efad4b670aeed2949a98de239d2ec2d81db5067272c446b067a86ab805b90779cd73afc412ec9539b93a1
7
+ data.tar.gz: c7965c692a9ce203a079482a939b6f3f6ff16a60fcc2307fd4fcfeb40224a5a20c42c4c687f64c6e1f6375e5bff5ebe07ae995111e660e08fd255095c3d2fd3d
data/README.md CHANGED
@@ -60,6 +60,25 @@ But if we pass an array
60
60
  expect{ Diggy([:a]) }.to raise_error(ArgumentError)
61
61
  ```
62
62
 
63
+ ### Context: Using in ERB
64
+
65
+ In order to take advantage of this syntax we want to pass the binding of a `Diggy` object to `ERB`
66
+
67
+ Given an `ERB` template
68
+ ```ruby
69
+ require 'erb'
70
+ let(:template_text) { "<%= data.person.name %>" }
71
+ ```
72
+
73
+ And a `Lab42::DiggyMethod` instance
74
+ ```ruby
75
+ let(:data) { Diggy(data: {person: {name: "YHS"}}) }
76
+ ```
77
+
78
+ Then we can pass the binding to the template
79
+ ```ruby
80
+ expect(ERB.new(template_text).result(data.__binding__)).to eq("YHS")
81
+ ```
63
82
  # LICENSE
64
83
 
65
84
  Copyright 2022 Robert Dober robert.dober@gmail.com
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Lab42
4
4
  class DiggyMethods
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
8
+ # SPDX-License-Identifier: Apache-2.0
@@ -3,7 +3,9 @@
3
3
  require_relative 'diggy_methods/kernel'
4
4
  module Lab42
5
5
  class DiggyMethods
6
- attr_reader :data
6
+
7
+ # Expose for ERB
8
+ def __binding__; binding end
7
9
 
8
10
  # In case data has key :data (often the case)
9
11
  def __data__; @data end
@@ -36,7 +38,7 @@ module Lab42
36
38
  end
37
39
 
38
40
  def method_missing(name)
39
- found = data.fetch(name)
41
+ found = @data.fetch(name)
40
42
  if found.respond_to?(:to_h)
41
43
  self.class.new(**found)
42
44
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober