inline_transforms 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69650094317116d52d29eaaebdc3237dcf2c014d6447b2ad52631a4eabb11837
4
- data.tar.gz: 2729df1b7e99479a4101a9c53782b32a4d736e1756008f0da8fa976722799bd2
3
+ metadata.gz: ff2ee8053b8af9abd8a87c51f631c41e50f487816a86061107cbc09731df311f
4
+ data.tar.gz: 3583bf28d21bf28654f8dd37a404ca1118a279c90a819be5e72f03c00c6190db
5
5
  SHA512:
6
- metadata.gz: e1432ee3d677412d5aa6bcd9b014f2b7e5c093b7e495b760335dac315d312825890e1e26759a977639a7c69fdce09f6e9309b8b57f3bb2bcb4d06291ac1ee62c
7
- data.tar.gz: 462d39e0cf06278f6bf757ceec642496b22a7b2d06f9e8bf6d66c0fc0d4993e4c493eaea2cad25258e9c1f72549f7eb25e7925dd04b3af7a0d918a1f47d4c914
6
+ metadata.gz: 4d4e62ff7f0b687407d47b5887715805e3c86ec645027c53c75ae70ecca2102ff49e508aaac815a5fc4f1bdb33aca1f2967c006e363a8ac57bea71f04e3919dd
7
+ data.tar.gz: d4eca27ab651c2f31dd93f60a261f1087407eabe9258e0981a9bf53bced6a6da646222afa78e3f9d907697905a792ce97e35b574c25647791b6ebde5d91a9672
data/README.md CHANGED
@@ -91,6 +91,9 @@ final_value = original_value.transform true => 'success',
91
91
  `only_if` lets you specify a "good" value and an `else` replacement.
92
92
 
93
93
  - If your `else` replacement is a `Proc`, it is resolved (via `call`) before being returned.
94
+ - If it has arity 0, it is `call`ed with no params.
95
+ - If it has arity 1, it is `call`ed with the original value.
96
+ - If it has arity -1 (a `lambda` with optional param), it is `call`ed with the original value.
94
97
  - This method uses **case comparison** (`===`), so you can check for range inclusion or class.
95
98
 
96
99
  ```ruby
@@ -105,6 +108,9 @@ final = value.only_if good_value, else: -> { some_method_call with_params }
105
108
  `unless` lets you specify a "bad" value and a `then` replacement.
106
109
 
107
110
  - If your `then` replacement is a `Proc`, it is resolved (via `call`) before being returned.
111
+ - If it has arity 0, it is `call`ed with no params.
112
+ - If it has arity 1, it is `call`ed with the original value.
113
+ - If it has arity -1 (a `lambda` with optional param), it is `call`ed with the original value.
108
114
  - This method uses **case comparison** (`===`), so you can check for range inclusion or class.
109
115
 
110
116
  ```ruby
@@ -119,6 +125,9 @@ final = value.unless bad_value, then: -> { some_method_call with_params }
119
125
  `transform` lets you specify a transformation hash and will return the value for the first matching key, or (if no matching key is found) the `:else` value.
120
126
 
121
127
  - Any `Proc` values in the transform hash are resolved (via `call`) before being returned.
128
+ - Values with arity 0 are `call`ed with no params.
129
+ - Values with arity 1 are `call`ed with the original value.
130
+ - Values with arity -1 (`lambda`s with an optional param) are `call`ed with the original value.
122
131
  - This method uses **case comparison** (`===`), so range and class keys work as you expect.
123
132
 
124
133
  ```ruby
@@ -114,7 +114,7 @@
114
114
  <dt id="VERSION-constant" class="">VERSION =
115
115
 
116
116
  </dt>
117
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>0.2.0</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
117
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>0.3.0</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
118
118
 
119
119
  </dl>
120
120
 
@@ -292,10 +292,7 @@
292
292
  27
293
293
  28
294
294
  29
295
- 30
296
- 31
297
- 32
298
- 33</pre>
295
+ 30</pre>
299
296
  </td>
300
297
  <td>
301
298
  <pre class="code"><span class="info file"># File 'lib/inline_transforms.rb', line 26</span>
@@ -303,10 +300,7 @@
303
300
  <span class='kw'>def</span> <span class='id identifier rubyid_only_if'>only_if</span><span class='lparen'>(</span><span class='id identifier rubyid_good_value'>good_value</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
304
301
  <span class='kw'>return</span> <span class='kw'>self</span> <span class='kw'>if</span> <span class='id identifier rubyid_inline_transforms_equality?'>inline_transforms_equality?</span> <span class='id identifier rubyid_good_value'>good_value</span>
305
302
 
306
- <span class='id identifier rubyid_alt_value'>alt_value</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:else</span><span class='rbracket'>]</span>
307
- <span class='kw'>return</span> <span class='id identifier rubyid_alt_value'>alt_value</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='kw'>if</span> <span class='id identifier rubyid_alt_value'>alt_value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Proc</span>
308
-
309
- <span class='id identifier rubyid_alt_value'>alt_value</span>
303
+ <span class='id identifier rubyid_inline_transforms_response_processor'>inline_transforms_response_processor</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:else</span><span class='rbracket'>]</span>
310
304
  <span class='kw'>end</span></pre>
311
305
  </td>
312
306
  </tr>
@@ -391,21 +385,21 @@ corresponding hash value is returned. If no matching hash key is found, this ret
391
385
  <pre class="lines">
392
386
 
393
387
 
394
- 74
395
- 75
396
- 76
397
- 77
398
- 78
399
- 79</pre>
388
+ 68
389
+ 69
390
+ 70
391
+ 71
392
+ 72
393
+ 73</pre>
400
394
  </td>
401
395
  <td>
402
- <pre class="code"><span class="info file"># File 'lib/inline_transforms.rb', line 74</span>
396
+ <pre class="code"><span class="info file"># File 'lib/inline_transforms.rb', line 68</span>
403
397
 
404
398
  <span class='kw'>def</span> <span class='id identifier rubyid_transform'>transform</span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
405
399
  <span class='id identifier rubyid_default'>default</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span> <span class='symbol'>:else</span>
406
400
 
407
- <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_unless'>unless</span> <span class='const'>Proc</span><span class='comma'>,</span> <span class='label'>then:</span> <span class='tlambda'>-&gt;</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='rbrace'>}</span> <span class='kw'>if</span> <span class='id identifier rubyid_inline_transforms_equality?'>inline_transforms_equality?</span> <span class='id identifier rubyid_key'>key</span> <span class='rbrace'>}</span>
408
- <span class='id identifier rubyid_default'>default</span>
401
+ <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='kw'>return</span> <span class='id identifier rubyid_inline_transforms_response_processor'>inline_transforms_response_processor</span> <span class='id identifier rubyid_value'>value</span> <span class='kw'>if</span> <span class='id identifier rubyid_inline_transforms_equality?'>inline_transforms_equality?</span> <span class='id identifier rubyid_key'>key</span> <span class='rbrace'>}</span>
402
+ <span class='id identifier rubyid_inline_transforms_response_processor'>inline_transforms_response_processor</span> <span class='id identifier rubyid_default'>default</span>
409
403
  <span class='kw'>end</span></pre>
410
404
  </td>
411
405
  </tr>
@@ -491,25 +485,19 @@ corresponding hash value is returned. If no matching hash key is found, this ret
491
485
  <pre class="lines">
492
486
 
493
487
 
488
+ 47
489
+ 48
490
+ 49
494
491
  50
495
- 51
496
- 52
497
- 53
498
- 54
499
- 55
500
- 56
501
- 57</pre>
492
+ 51</pre>
502
493
  </td>
503
494
  <td>
504
- <pre class="code"><span class="info file"># File 'lib/inline_transforms.rb', line 50</span>
495
+ <pre class="code"><span class="info file"># File 'lib/inline_transforms.rb', line 47</span>
505
496
 
506
497
  <span class='kw'>def</span> <span class='kw'>unless</span><span class='lparen'>(</span><span class='id identifier rubyid_bad_value'>bad_value</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
507
498
  <span class='kw'>return</span> <span class='kw'>self</span> <span class='kw'>unless</span> <span class='id identifier rubyid_inline_transforms_equality?'>inline_transforms_equality?</span> <span class='id identifier rubyid_bad_value'>bad_value</span>
508
499
 
509
- <span class='id identifier rubyid_alt_value'>alt_value</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:then</span><span class='rbracket'>]</span>
510
- <span class='kw'>return</span> <span class='id identifier rubyid_alt_value'>alt_value</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='kw'>if</span> <span class='id identifier rubyid_alt_value'>alt_value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Proc</span>
511
-
512
- <span class='id identifier rubyid_alt_value'>alt_value</span>
500
+ <span class='id identifier rubyid_inline_transforms_response_processor'>inline_transforms_response_processor</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:then</span><span class='rbracket'>]</span>
513
501
  <span class='kw'>end</span></pre>
514
502
  </td>
515
503
  </tr>
@@ -521,7 +509,7 @@ corresponding hash value is returned. If no matching hash key is found, this ret
521
509
  </div>
522
510
 
523
511
  <div id="footer">
524
- Generated on Tue Aug 25 16:11:47 2026 by
512
+ Generated on Wed Aug 26 23:26:19 2026 by
525
513
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
526
514
  0.9.45 (ruby-3.4.8).
527
515
  </div>
data/docs/Object.html CHANGED
@@ -138,7 +138,7 @@
138
138
  </div>
139
139
 
140
140
  <div id="footer">
141
- Generated on Tue Aug 25 16:11:47 2026 by
141
+ Generated on Wed Aug 26 23:26:20 2026 by
142
142
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
143
143
  0.9.45 (ruby-3.4.8).
144
144
  </div>
data/docs/_index.html CHANGED
@@ -112,7 +112,7 @@
112
112
  </div>
113
113
 
114
114
  <div id="footer">
115
- Generated on Tue Aug 25 16:11:47 2026 by
115
+ Generated on Wed Aug 26 23:26:19 2026 by
116
116
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
117
117
  0.9.45 (ruby-3.4.8).
118
118
  </div>
@@ -142,7 +142,13 @@
142
142
  <h3 id="Object_only_if">Object#only_if</h3>
143
143
  <p><code>only_if</code> lets you specify a &quot;good&quot; value and an <code>else</code> replacement.</p>
144
144
  <ul>
145
- <li>If your <code>else</code> replacement is a <code>Proc</code>, it is resolved (via <code>call</code>) before being returned.</li>
145
+ <li>If your <code>else</code> replacement is a <code>Proc</code>, it is resolved (via <code>call</code>) before being returned.
146
+ <ul>
147
+ <li>If it has arity 0, it is <code>call</code>ed with no params.</li>
148
+ <li>If it has arity 1, it is <code>call</code>ed with the original value.</li>
149
+ <li>If it has arity -1 (a <code>lambda</code> with optional param), it is <code>call</code>ed with the original value.</li>
150
+ </ul>
151
+ </li>
146
152
  <li>This method uses <strong>case comparison</strong> (<code>===</code>), so you can check for range inclusion or class.</li>
147
153
  </ul>
148
154
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_final'>final</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_only_if'>only_if</span> <span class='id identifier rubyid_good_value'>good_value</span><span class='comma'>,</span> <span class='label'>else:</span> <span class='id identifier rubyid_fallback_value'>fallback_value</span>
@@ -152,7 +158,13 @@
152
158
  <h3 id="Object_unless">Object#unless</h3>
153
159
  <p><code>unless</code> lets you specify a &quot;bad&quot; value and a <code>then</code> replacement.</p>
154
160
  <ul>
155
- <li>If your <code>then</code> replacement is a <code>Proc</code>, it is resolved (via <code>call</code>) before being returned.</li>
161
+ <li>If your <code>then</code> replacement is a <code>Proc</code>, it is resolved (via <code>call</code>) before being returned.
162
+ <ul>
163
+ <li>If it has arity 0, it is <code>call</code>ed with no params.</li>
164
+ <li>If it has arity 1, it is <code>call</code>ed with the original value.</li>
165
+ <li>If it has arity -1 (a <code>lambda</code> with optional param), it is <code>call</code>ed with the original value.</li>
166
+ </ul>
167
+ </li>
156
168
  <li>This method uses <strong>case comparison</strong> (<code>===</code>), so you can check for range inclusion or class.</li>
157
169
  </ul>
158
170
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_final'>final</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_unless'>unless</span> <span class='id identifier rubyid_bad_value'>bad_value</span><span class='comma'>,</span> <span class='label'>then:</span> <span class='id identifier rubyid_fallback_value'>fallback_value</span>
@@ -162,7 +174,13 @@
162
174
  <h3 id="Object_transform">Object#transform</h3>
163
175
  <p><code>transform</code> lets you specify a transformation hash and will return the value for the first matching key, or (if no matching key is found) the <code>:else</code> value.</p>
164
176
  <ul>
165
- <li>Any <code>Proc</code> values in the transform hash are resolved (via <code>call</code>) before being returned.</li>
177
+ <li>Any <code>Proc</code> values in the transform hash are resolved (via <code>call</code>) before being returned.
178
+ <ul>
179
+ <li>Values with arity 0 are <code>call</code>ed with no params.</li>
180
+ <li>Values with arity 1 are <code>call</code>ed with the original value.</li>
181
+ <li>Values with arity -1 (<code>lambda</code>s with an optional param) are <code>call</code>ed with the original value.</li>
182
+ </ul>
183
+ </li>
166
184
  <li>This method uses <strong>case comparison</strong> (<code>===</code>), so range and class keys work as you expect.</li>
167
185
  </ul>
168
186
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_final'>final</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_transform'>transform</span> <span class='id identifier rubyid_key_1'>key_1</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_value_1'>value_1</span><span class='comma'>,</span>
@@ -229,7 +247,7 @@
229
247
  <p>The <code>inline_transforms</code> gem is available as open source under the terms of the <a href="https://tldrlegal.com/license/mit-license">MIT License</a>.</p></div></div>
230
248
 
231
249
  <div id="footer">
232
- Generated on Tue Aug 25 16:11:47 2026 by
250
+ Generated on Wed Aug 26 23:26:19 2026 by
233
251
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
234
252
  0.9.45 (ruby-3.4.8).
235
253
  </div>
data/docs/index.html CHANGED
@@ -142,7 +142,13 @@
142
142
  <h3 id="Object_only_if">Object#only_if</h3>
143
143
  <p><code>only_if</code> lets you specify a &quot;good&quot; value and an <code>else</code> replacement.</p>
144
144
  <ul>
145
- <li>If your <code>else</code> replacement is a <code>Proc</code>, it is resolved (via <code>call</code>) before being returned.</li>
145
+ <li>If your <code>else</code> replacement is a <code>Proc</code>, it is resolved (via <code>call</code>) before being returned.
146
+ <ul>
147
+ <li>If it has arity 0, it is <code>call</code>ed with no params.</li>
148
+ <li>If it has arity 1, it is <code>call</code>ed with the original value.</li>
149
+ <li>If it has arity -1 (a <code>lambda</code> with optional param), it is <code>call</code>ed with the original value.</li>
150
+ </ul>
151
+ </li>
146
152
  <li>This method uses <strong>case comparison</strong> (<code>===</code>), so you can check for range inclusion or class.</li>
147
153
  </ul>
148
154
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_final'>final</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_only_if'>only_if</span> <span class='id identifier rubyid_good_value'>good_value</span><span class='comma'>,</span> <span class='label'>else:</span> <span class='id identifier rubyid_fallback_value'>fallback_value</span>
@@ -152,7 +158,13 @@
152
158
  <h3 id="Object_unless">Object#unless</h3>
153
159
  <p><code>unless</code> lets you specify a &quot;bad&quot; value and a <code>then</code> replacement.</p>
154
160
  <ul>
155
- <li>If your <code>then</code> replacement is a <code>Proc</code>, it is resolved (via <code>call</code>) before being returned.</li>
161
+ <li>If your <code>then</code> replacement is a <code>Proc</code>, it is resolved (via <code>call</code>) before being returned.
162
+ <ul>
163
+ <li>If it has arity 0, it is <code>call</code>ed with no params.</li>
164
+ <li>If it has arity 1, it is <code>call</code>ed with the original value.</li>
165
+ <li>If it has arity -1 (a <code>lambda</code> with optional param), it is <code>call</code>ed with the original value.</li>
166
+ </ul>
167
+ </li>
156
168
  <li>This method uses <strong>case comparison</strong> (<code>===</code>), so you can check for range inclusion or class.</li>
157
169
  </ul>
158
170
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_final'>final</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_unless'>unless</span> <span class='id identifier rubyid_bad_value'>bad_value</span><span class='comma'>,</span> <span class='label'>then:</span> <span class='id identifier rubyid_fallback_value'>fallback_value</span>
@@ -162,7 +174,13 @@
162
174
  <h3 id="Object_transform">Object#transform</h3>
163
175
  <p><code>transform</code> lets you specify a transformation hash and will return the value for the first matching key, or (if no matching key is found) the <code>:else</code> value.</p>
164
176
  <ul>
165
- <li>Any <code>Proc</code> values in the transform hash are resolved (via <code>call</code>) before being returned.</li>
177
+ <li>Any <code>Proc</code> values in the transform hash are resolved (via <code>call</code>) before being returned.
178
+ <ul>
179
+ <li>Values with arity 0 are <code>call</code>ed with no params.</li>
180
+ <li>Values with arity 1 are <code>call</code>ed with the original value.</li>
181
+ <li>Values with arity -1 (<code>lambda</code>s with an optional param) are <code>call</code>ed with the original value.</li>
182
+ </ul>
183
+ </li>
166
184
  <li>This method uses <strong>case comparison</strong> (<code>===</code>), so range and class keys work as you expect.</li>
167
185
  </ul>
168
186
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_final'>final</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_transform'>transform</span> <span class='id identifier rubyid_key_1'>key_1</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_value_1'>value_1</span><span class='comma'>,</span>
@@ -229,7 +247,7 @@
229
247
  <p>The <code>inline_transforms</code> gem is available as open source under the terms of the <a href="https://tldrlegal.com/license/mit-license">MIT License</a>.</p></div></div>
230
248
 
231
249
  <div id="footer">
232
- Generated on Tue Aug 25 16:11:47 2026 by
250
+ Generated on Wed Aug 26 23:26:19 2026 by
233
251
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
234
252
  0.9.45 (ruby-3.4.8).
235
253
  </div>
@@ -104,7 +104,7 @@
104
104
  </div>
105
105
 
106
106
  <div id="footer">
107
- Generated on Tue Aug 25 16:11:47 2026 by
107
+ Generated on Wed Aug 26 23:26:19 2026 by
108
108
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
109
109
  0.9.45 (ruby-3.4.8).
110
110
  </div>
@@ -1,3 +1,3 @@
1
1
  module InlineTransforms
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -26,10 +26,7 @@ module InlineTransforms
26
26
  def only_if(good_value, **options)
27
27
  return self if inline_transforms_equality? good_value
28
28
 
29
- alt_value = options[:else]
30
- return alt_value.call if alt_value.is_a? Proc
31
-
32
- alt_value
29
+ inline_transforms_response_processor options[:else]
33
30
  end
34
31
 
35
32
  # Returns `self` ... unless it matches a "bad" value, in which case it returns an alternate (`then:`) value.
@@ -50,10 +47,7 @@ module InlineTransforms
50
47
  def unless(bad_value, **options)
51
48
  return self unless inline_transforms_equality? bad_value
52
49
 
53
- alt_value = options[:then]
54
- return alt_value.call if alt_value.is_a? Proc
55
-
56
- alt_value
50
+ inline_transforms_response_processor options[:then]
57
51
  end
58
52
 
59
53
  # Returns `self` ... unless it matches one of the keys in the given "transformation hash", in which case the
@@ -74,8 +68,8 @@ module InlineTransforms
74
68
  def transform(**options)
75
69
  default = options.delete :else
76
70
 
77
- options.each { |key, value| return value.unless Proc, then: -> { value.call } if inline_transforms_equality? key }
78
- default
71
+ options.each { |key, value| return inline_transforms_response_processor value if inline_transforms_equality? key }
72
+ inline_transforms_response_processor default
79
73
  end
80
74
 
81
75
  private
@@ -94,6 +88,27 @@ module InlineTransforms
94
88
  value === self
95
89
  end
96
90
 
91
+ # We want to pass fallback values through as-is **except for `Proc`s**,
92
+ # which we must resolve by passing `self` _or not_, as dictated by its arity.
93
+ #
94
+ # @param response_value [Object]
95
+ # The `then`, `else`, or matching transform value from one of the above.
96
+ #
97
+ # @return [Object]
98
+ # The given `response_value`, unless it's a `Proc`, in which case we want to resolve it first.
99
+ #
100
+ # @raise [ArgumentError]
101
+ #
102
+ def inline_transforms_response_processor(response_value)
103
+ return response_value unless response_value.is_a? Proc
104
+
105
+ case response_value.arity
106
+ when 0 then response_value.call
107
+ when 1, -1 then response_value.call self
108
+ else raise ArgumentError, 'fallback Proc must be of arity 0 or 1'
109
+ end
110
+ end
111
+
97
112
  # rubocop:enable Style/CaseEquality
98
113
  end
99
114
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_transforms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nestor Custodio