anchormodel 0.3.0 → 0.4.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 +4 -4
- data/.gitignore +3 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +19 -0
- data/EXAMPLES.md +408 -0
- data/Gemfile.lock +8 -8
- data/README.md +43 -1
- data/VERSION +1 -1
- data/anchormodel.gemspec +4 -4
- data/bin/test +9 -0
- data/doc/Anchormodel/ActiveModelTypeValueMulti.html +204 -42
- data/doc/Anchormodel/ActiveModelTypeValueSingle.html +245 -92
- data/doc/Anchormodel/Attribute.html +60 -37
- data/doc/Anchormodel/ModelMixin.html +166 -16
- data/doc/Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html +82 -21
- data/doc/Anchormodel/SimpleFormInputs/Helpers.html +2 -11
- data/doc/Anchormodel/SimpleFormInputs.html +2 -11
- data/doc/Anchormodel/Util.html +497 -38
- data/doc/Anchormodel/Version.html +2 -20
- data/doc/Anchormodel.html +536 -129
- data/doc/AnchormodelCheckBoxesInput.html +22 -1
- data/doc/AnchormodelGenerator.html +64 -13
- data/doc/AnchormodelInput.html +24 -1
- data/doc/AnchormodelRadioButtonsInput.html +22 -1
- data/doc/_index.html +16 -1
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +40 -2
- data/doc/index.html +40 -2
- data/doc/method_list.html +57 -17
- data/doc/top-level-namespace.html +1 -1
- data/lib/anchormodel/active_model_type_value_multi.rb +31 -5
- data/lib/anchormodel/active_model_type_value_single.rb +51 -13
- data/lib/anchormodel/attribute.rb +20 -8
- data/lib/anchormodel/model_mixin.rb +43 -8
- data/lib/anchormodel/simple_form_inputs/anchormodel_check_boxes_input.rb +7 -0
- data/lib/anchormodel/simple_form_inputs/anchormodel_input.rb +9 -0
- data/lib/anchormodel/simple_form_inputs/anchormodel_radio_buttons_input.rb +7 -0
- data/lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.rb +14 -0
- data/lib/anchormodel/util.rb +102 -17
- data/lib/anchormodel.rb +109 -15
- data/lib/generators/anchormodel/anchormodel_generator.rb +8 -0
- data/test/active_record_model/user_test.rb +256 -6
- data/test/dummy/app/anchormodels/animal.rb +1 -0
- metadata +4 -2
|
@@ -104,6 +104,10 @@
|
|
|
104
104
|
<h2>Overview</h2><div class="docstring">
|
|
105
105
|
<div class="discussion">
|
|
106
106
|
|
|
107
|
+
<p>ActiveModel type adapter for single-value anchormodel attributes.</p>
|
|
108
|
+
|
|
109
|
+
<p>Translates between the in-memory Ruby form (an <code>Anchormodel</code> instance or <code>nil</code>) and the on-disk form (a String key in the DB column). Registered with AR via <code>model_class.attribute(name, ActiveModelTypeValueSingle.new(attribute))</code> by <span class='object_link'><a href="Util.html#install_methods_in_model-class_method" title="Anchormodel::Util.install_methods_in_model (method)">Util.install_methods_in_model</a></span>.</p>
|
|
110
|
+
|
|
107
111
|
|
|
108
112
|
</div>
|
|
109
113
|
</div>
|
|
@@ -113,7 +117,7 @@
|
|
|
113
117
|
<p class="tag_title">See Also:</p>
|
|
114
118
|
<ul class="see">
|
|
115
119
|
|
|
116
|
-
<li><a href="https://www.rubydoc.info/docs/rails/ActiveModel/Type/Value" target="_parent" title="
|
|
120
|
+
<li><a href="https://www.rubydoc.info/docs/rails/ActiveModel/Type/Value" target="_parent" title="Rails type interface">Rails type interface</a></li>
|
|
117
121
|
|
|
118
122
|
</ul>
|
|
119
123
|
|
|
@@ -150,7 +154,9 @@
|
|
|
150
154
|
|
|
151
155
|
|
|
152
156
|
|
|
153
|
-
<span class="summary_desc"><div class='inline'
|
|
157
|
+
<span class="summary_desc"><div class='inline'>
|
|
158
|
+
<p>Returns the value of attribute attribute.</p>
|
|
159
|
+
</div></span>
|
|
154
160
|
|
|
155
161
|
</li>
|
|
156
162
|
|
|
@@ -171,7 +177,7 @@
|
|
|
171
177
|
<li class="public ">
|
|
172
178
|
<span class="summary_signature">
|
|
173
179
|
|
|
174
|
-
<a href="#cast-instance_method" title="#cast (instance method)">#<strong>cast</strong>(value) ⇒
|
|
180
|
+
<a href="#cast-instance_method" title="#cast (instance method)">#<strong>cast</strong>(value) ⇒ Anchormodel<sup>?</sup> </a>
|
|
175
181
|
|
|
176
182
|
|
|
177
183
|
|
|
@@ -186,7 +192,7 @@
|
|
|
186
192
|
|
|
187
193
|
|
|
188
194
|
<span class="summary_desc"><div class='inline'>
|
|
189
|
-
<p>
|
|
195
|
+
<p>Coerces an input value into an Anchormodel instance (or nil).</p>
|
|
190
196
|
</div></span>
|
|
191
197
|
|
|
192
198
|
</li>
|
|
@@ -206,10 +212,12 @@
|
|
|
206
212
|
|
|
207
213
|
|
|
208
214
|
|
|
209
|
-
|
|
215
|
+
<span class="private note title">private</span>
|
|
210
216
|
|
|
211
217
|
|
|
212
|
-
<span class="summary_desc"><div class='inline'
|
|
218
|
+
<span class="summary_desc"><div class='inline'>
|
|
219
|
+
<p>Used by AR’s dirty tracking to detect in-place mutation.</p>
|
|
220
|
+
</div></span>
|
|
213
221
|
|
|
214
222
|
</li>
|
|
215
223
|
|
|
@@ -257,7 +265,9 @@
|
|
|
257
265
|
|
|
258
266
|
|
|
259
267
|
|
|
260
|
-
<span class="summary_desc"><div class='inline'
|
|
268
|
+
<span class="summary_desc"><div class='inline'>
|
|
269
|
+
<p>Reports whether <code>value</code> is a shape that <span class='object_link'><a href="#serialize-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#serialize (method)">#serialize</a></span> would accept.</p>
|
|
270
|
+
</div></span>
|
|
261
271
|
|
|
262
272
|
</li>
|
|
263
273
|
|
|
@@ -265,7 +275,7 @@
|
|
|
265
275
|
<li class="public ">
|
|
266
276
|
<span class="summary_signature">
|
|
267
277
|
|
|
268
|
-
<a href="#serialize-instance_method" title="#serialize (instance method)">#<strong>serialize</strong>(value) ⇒
|
|
278
|
+
<a href="#serialize-instance_method" title="#serialize (instance method)">#<strong>serialize</strong>(value) ⇒ String<sup>?</sup> </a>
|
|
269
279
|
|
|
270
280
|
|
|
271
281
|
|
|
@@ -280,7 +290,7 @@
|
|
|
280
290
|
|
|
281
291
|
|
|
282
292
|
<span class="summary_desc"><div class='inline'>
|
|
283
|
-
<p>
|
|
293
|
+
<p>Converts an Anchormodel-shaped value into the String key stored in the DB.</p>
|
|
284
294
|
</div></span>
|
|
285
295
|
|
|
286
296
|
</li>
|
|
@@ -289,7 +299,7 @@
|
|
|
289
299
|
<li class="public ">
|
|
290
300
|
<span class="summary_signature">
|
|
291
301
|
|
|
292
|
-
<a href="#type-instance_method" title="#type (instance method)">#<strong>type</strong> ⇒
|
|
302
|
+
<a href="#type-instance_method" title="#type (instance method)">#<strong>type</strong> ⇒ Symbol </a>
|
|
293
303
|
|
|
294
304
|
|
|
295
305
|
|
|
@@ -303,7 +313,9 @@
|
|
|
303
313
|
|
|
304
314
|
|
|
305
315
|
|
|
306
|
-
<span class="summary_desc"><div class='inline'
|
|
316
|
+
<span class="summary_desc"><div class='inline'>
|
|
317
|
+
<p><code>:anchormodel</code> — the type identifier.</p>
|
|
318
|
+
</div></span>
|
|
307
319
|
|
|
308
320
|
</li>
|
|
309
321
|
|
|
@@ -333,7 +345,22 @@
|
|
|
333
345
|
</div>
|
|
334
346
|
</div>
|
|
335
347
|
<div class="tags">
|
|
348
|
+
<p class="tag_title">Parameters:</p>
|
|
349
|
+
<ul class="param">
|
|
336
350
|
|
|
351
|
+
<li>
|
|
352
|
+
|
|
353
|
+
<span class='name'>attribute</span>
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
<span class='type'>(<tt><span class='object_link'><a href="Attribute.html" title="Anchormodel::Attribute (class)">Anchormodel::Attribute</a></span></tt>)</span>
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
</li>
|
|
361
|
+
|
|
362
|
+
</ul>
|
|
363
|
+
|
|
337
364
|
|
|
338
365
|
</div><table class="source_code">
|
|
339
366
|
<tr>
|
|
@@ -341,13 +368,13 @@
|
|
|
341
368
|
<pre class="lines">
|
|
342
369
|
|
|
343
370
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
371
|
+
15
|
|
372
|
+
16
|
|
373
|
+
17
|
|
374
|
+
18</pre>
|
|
348
375
|
</td>
|
|
349
376
|
<td>
|
|
350
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line
|
|
377
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line 15</span>
|
|
351
378
|
|
|
352
379
|
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute'>attribute</span><span class='rparen'>)</span>
|
|
353
380
|
<span class='kw'>super</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
|
@@ -377,6 +404,8 @@
|
|
|
377
404
|
</h3><div class="docstring">
|
|
378
405
|
<div class="discussion">
|
|
379
406
|
|
|
407
|
+
<p>Returns the value of attribute attribute.</p>
|
|
408
|
+
|
|
380
409
|
|
|
381
410
|
</div>
|
|
382
411
|
</div>
|
|
@@ -389,12 +418,12 @@
|
|
|
389
418
|
<pre class="lines">
|
|
390
419
|
|
|
391
420
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
421
|
+
12
|
|
422
|
+
13
|
|
423
|
+
14</pre>
|
|
395
424
|
</td>
|
|
396
425
|
<td>
|
|
397
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line
|
|
426
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line 12</span>
|
|
398
427
|
|
|
399
428
|
<span class='kw'>def</span> <span class='id identifier rubyid_attribute'>attribute</span>
|
|
400
429
|
<span class='ivar'>@attribute</span>
|
|
@@ -414,7 +443,7 @@
|
|
|
414
443
|
<div class="method_details first">
|
|
415
444
|
<h3 class="signature first" id="cast-instance_method">
|
|
416
445
|
|
|
417
|
-
#<strong>cast</strong>(value) ⇒ <tt>
|
|
446
|
+
#<strong>cast</strong>(value) ⇒ <tt><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></tt><sup>?</sup>
|
|
418
447
|
|
|
419
448
|
|
|
420
449
|
|
|
@@ -423,13 +452,69 @@
|
|
|
423
452
|
</h3><div class="docstring">
|
|
424
453
|
<div class="discussion">
|
|
425
454
|
|
|
426
|
-
<p>
|
|
455
|
+
<p>Coerces an input value into an Anchormodel instance (or nil). Used by Rails when reading from the DB, when assigning via mass-assignment, and for dirty-tracking.</p>
|
|
427
456
|
|
|
428
457
|
|
|
429
458
|
</div>
|
|
430
459
|
</div>
|
|
431
460
|
<div class="tags">
|
|
461
|
+
<p class="tag_title">Parameters:</p>
|
|
462
|
+
<ul class="param">
|
|
463
|
+
|
|
464
|
+
<li>
|
|
465
|
+
|
|
466
|
+
<span class='name'>value</span>
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>, <tt><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></tt>, <tt>nil</tt>)</span>
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
—
|
|
474
|
+
<div class='inline'>
|
|
475
|
+
<p>DB value, user input, or already-cast instance.</p>
|
|
476
|
+
</div>
|
|
477
|
+
|
|
478
|
+
</li>
|
|
432
479
|
|
|
480
|
+
</ul>
|
|
481
|
+
|
|
482
|
+
<p class="tag_title">Returns:</p>
|
|
483
|
+
<ul class="return">
|
|
484
|
+
|
|
485
|
+
<li>
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
<span class='type'>(<tt><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></tt>, <tt>nil</tt>)</span>
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
—
|
|
493
|
+
<div class='inline'>
|
|
494
|
+
<p>The matching Anchormodel instance, or <code>nil</code> for blank input.</p>
|
|
495
|
+
</div>
|
|
496
|
+
|
|
497
|
+
</li>
|
|
498
|
+
|
|
499
|
+
</ul>
|
|
500
|
+
<p class="tag_title">Raises:</p>
|
|
501
|
+
<ul class="raise">
|
|
502
|
+
|
|
503
|
+
<li>
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
<span class='type'>(<tt><span class='object_link'><a href="InvalidKey.html" title="Anchormodel::InvalidKey (class)">Anchormodel::InvalidKey</a></span></tt>)</span>
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
—
|
|
511
|
+
<div class='inline'>
|
|
512
|
+
<p>if a String/Symbol is not a registered key.</p>
|
|
513
|
+
</div>
|
|
514
|
+
|
|
515
|
+
</li>
|
|
516
|
+
|
|
517
|
+
</ul>
|
|
433
518
|
|
|
434
519
|
</div><table class="source_code">
|
|
435
520
|
<tr>
|
|
@@ -437,14 +522,14 @@
|
|
|
437
522
|
<pre class="lines">
|
|
438
523
|
|
|
439
524
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
525
|
+
31
|
|
526
|
+
32
|
|
527
|
+
33
|
|
528
|
+
34
|
|
529
|
+
35</pre>
|
|
445
530
|
</td>
|
|
446
531
|
<td>
|
|
447
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line
|
|
532
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line 31</span>
|
|
448
533
|
|
|
449
534
|
<span class='kw'>def</span> <span class='id identifier rubyid_cast'>cast</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
|
450
535
|
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_presence'>presence</span>
|
|
@@ -467,7 +552,13 @@
|
|
|
467
552
|
|
|
468
553
|
</h3><div class="docstring">
|
|
469
554
|
<div class="discussion">
|
|
470
|
-
|
|
555
|
+
<p class="note private">
|
|
556
|
+
<strong>This method is part of a private API.</strong>
|
|
557
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
558
|
+
</p>
|
|
559
|
+
|
|
560
|
+
<p>Used by AR’s dirty tracking to detect in-place mutation.</p>
|
|
561
|
+
|
|
471
562
|
|
|
472
563
|
</div>
|
|
473
564
|
</div>
|
|
@@ -493,13 +584,13 @@
|
|
|
493
584
|
<pre class="lines">
|
|
494
585
|
|
|
495
586
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
587
|
+
60
|
|
588
|
+
61
|
|
589
|
+
62
|
|
590
|
+
63</pre>
|
|
500
591
|
</td>
|
|
501
592
|
<td>
|
|
502
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line
|
|
593
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line 60</span>
|
|
503
594
|
|
|
504
595
|
<span class='kw'>def</span> <span class='id identifier rubyid_changed_in_place?'>changed_in_place?</span><span class='lparen'>(</span><span class='id identifier rubyid_raw_old_value'>raw_old_value</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
|
505
596
|
<span class='id identifier rubyid_old_value'>old_value</span> <span class='op'>=</span> <span class='id identifier rubyid_deserialize'>deserialize</span><span class='lparen'>(</span><span class='id identifier rubyid_raw_old_value'>raw_old_value</span><span class='rparen'>)</span>
|
|
@@ -522,11 +613,28 @@
|
|
|
522
613
|
</h3><div class="docstring">
|
|
523
614
|
<div class="discussion">
|
|
524
615
|
|
|
616
|
+
<p>Reports whether <code>value</code> is a shape that <span class='object_link'><a href="#serialize-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#serialize (method)">#serialize</a></span> would accept. Used by AR’s <code>Arel::Nodes::HomogeneousIn</code> to gate which array elements get bound into IN clauses. Returns true for any String/Symbol/<code>nil</code>/Anchormodel instance — actual key validation is deferred to <span class='object_link'><a href="#serialize-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#serialize (method)">#serialize</a></span>.</p>
|
|
617
|
+
|
|
525
618
|
|
|
526
619
|
</div>
|
|
527
620
|
</div>
|
|
528
621
|
<div class="tags">
|
|
622
|
+
<p class="tag_title">Parameters:</p>
|
|
623
|
+
<ul class="param">
|
|
624
|
+
|
|
625
|
+
<li>
|
|
626
|
+
|
|
627
|
+
<span class='name'>value</span>
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
</li>
|
|
529
635
|
|
|
636
|
+
</ul>
|
|
637
|
+
|
|
530
638
|
<p class="tag_title">Returns:</p>
|
|
531
639
|
<ul class="return">
|
|
532
640
|
|
|
@@ -547,29 +655,15 @@
|
|
|
547
655
|
<pre class="lines">
|
|
548
656
|
|
|
549
657
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
42
|
|
554
|
-
43
|
|
555
|
-
44
|
|
556
|
-
45
|
|
557
|
-
46
|
|
558
|
-
47
|
|
559
|
-
48</pre>
|
|
658
|
+
54
|
|
659
|
+
55
|
|
660
|
+
56</pre>
|
|
560
661
|
</td>
|
|
561
662
|
<td>
|
|
562
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line
|
|
663
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line 54</span>
|
|
563
664
|
|
|
564
665
|
<span class='kw'>def</span> <span class='id identifier rubyid_serializable?'>serializable?</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
|
565
|
-
<span class='
|
|
566
|
-
<span class='kw'>when</span> <span class='const'>Symbol</span><span class='comma'>,</span> <span class='const'>String</span>
|
|
567
|
-
<span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_valid_keys'>valid_keys</span><span class='period'>.</span><span class='id identifier rubyid_exclude?'>exclude?</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rparen'>)</span>
|
|
568
|
-
<span class='kw'>when</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span>
|
|
569
|
-
<span class='kw'>true</span>
|
|
570
|
-
<span class='kw'>else</span>
|
|
571
|
-
<span class='kw'>false</span>
|
|
572
|
-
<span class='kw'>end</span>
|
|
666
|
+
<span class='id identifier rubyid_scalar_serializable?'>scalar_serializable?</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
|
573
667
|
<span class='kw'>end</span></pre>
|
|
574
668
|
</td>
|
|
575
669
|
</tr>
|
|
@@ -579,7 +673,7 @@
|
|
|
579
673
|
<div class="method_details ">
|
|
580
674
|
<h3 class="signature " id="serialize-instance_method">
|
|
581
675
|
|
|
582
|
-
#<strong>serialize</strong>(value) ⇒ <tt>
|
|
676
|
+
#<strong>serialize</strong>(value) ⇒ <tt>String</tt><sup>?</sup>
|
|
583
677
|
|
|
584
678
|
|
|
585
679
|
|
|
@@ -588,13 +682,78 @@
|
|
|
588
682
|
</h3><div class="docstring">
|
|
589
683
|
<div class="discussion">
|
|
590
684
|
|
|
591
|
-
<p>
|
|
685
|
+
<p>Converts an Anchormodel-shaped value into the String key stored in the DB.</p>
|
|
592
686
|
|
|
593
687
|
|
|
594
688
|
</div>
|
|
595
689
|
</div>
|
|
596
690
|
<div class="tags">
|
|
691
|
+
<p class="tag_title">Parameters:</p>
|
|
692
|
+
<ul class="param">
|
|
597
693
|
|
|
694
|
+
<li>
|
|
695
|
+
|
|
696
|
+
<span class='name'>value</span>
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>, <tt><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></tt>, <tt>nil</tt>)</span>
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
</li>
|
|
704
|
+
|
|
705
|
+
</ul>
|
|
706
|
+
|
|
707
|
+
<p class="tag_title">Returns:</p>
|
|
708
|
+
<ul class="return">
|
|
709
|
+
|
|
710
|
+
<li>
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
<span class='type'>(<tt>String</tt>, <tt>nil</tt>)</span>
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
—
|
|
718
|
+
<div class='inline'>
|
|
719
|
+
<p>The key as a String, or <code>nil</code> for blank input.</p>
|
|
720
|
+
</div>
|
|
721
|
+
|
|
722
|
+
</li>
|
|
723
|
+
|
|
724
|
+
</ul>
|
|
725
|
+
<p class="tag_title">Raises:</p>
|
|
726
|
+
<ul class="raise">
|
|
727
|
+
|
|
728
|
+
<li>
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
<span class='type'>(<tt><span class='object_link'><a href="InvalidKey.html" title="Anchormodel::InvalidKey (class)">Anchormodel::InvalidKey</a></span></tt>)</span>
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
—
|
|
736
|
+
<div class='inline'>
|
|
737
|
+
<p>for unknown String/Symbol keys.</p>
|
|
738
|
+
</div>
|
|
739
|
+
|
|
740
|
+
</li>
|
|
741
|
+
|
|
742
|
+
<li>
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
<span class='type'>(<tt>RuntimeError</tt>)</span>
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
—
|
|
750
|
+
<div class='inline'>
|
|
751
|
+
<p>for any other input type (e.g. Array, Integer).</p>
|
|
752
|
+
</div>
|
|
753
|
+
|
|
754
|
+
</li>
|
|
755
|
+
|
|
756
|
+
</ul>
|
|
598
757
|
|
|
599
758
|
</div><table class="source_code">
|
|
600
759
|
<tr>
|
|
@@ -602,41 +761,15 @@
|
|
|
602
761
|
<pre class="lines">
|
|
603
762
|
|
|
604
763
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
25
|
|
609
|
-
26
|
|
610
|
-
27
|
|
611
|
-
28
|
|
612
|
-
29
|
|
613
|
-
30
|
|
614
|
-
31
|
|
615
|
-
32
|
|
616
|
-
33
|
|
617
|
-
34
|
|
618
|
-
35
|
|
619
|
-
36
|
|
620
|
-
37</pre>
|
|
764
|
+
43
|
|
765
|
+
44
|
|
766
|
+
45</pre>
|
|
621
767
|
</td>
|
|
622
768
|
<td>
|
|
623
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line
|
|
769
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line 43</span>
|
|
624
770
|
|
|
625
771
|
<span class='kw'>def</span> <span class='id identifier rubyid_serialize'>serialize</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
|
626
|
-
<span class='id identifier
|
|
627
|
-
<span class='kw'>return</span> <span class='kw'>case</span> <span class='id identifier rubyid_value'>value</span>
|
|
628
|
-
<span class='kw'>when</span> <span class='const'>Symbol</span><span class='comma'>,</span> <span class='const'>String</span>
|
|
629
|
-
<span class='kw'>unless</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_valid_keys'>valid_keys</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rparen'>)</span>
|
|
630
|
-
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Attempt to set </span><span class='embexpr_beg'>#{</span><span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> to unsupported key </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
631
|
-
<span class='kw'>end</span>
|
|
632
|
-
<span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
|
633
|
-
<span class='kw'>when</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span>
|
|
634
|
-
<span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
|
635
|
-
<span class='kw'>when</span> <span class='kw'>nil</span>
|
|
636
|
-
<span class='kw'>nil</span>
|
|
637
|
-
<span class='kw'>else</span>
|
|
638
|
-
<span class='id identifier rubyid_fail'>fail</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Attempt to set </span><span class='embexpr_beg'>#{</span><span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> to unsupported type </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
|
639
|
-
<span class='kw'>end</span>
|
|
772
|
+
<span class='id identifier rubyid_serialize_scalar'>serialize_scalar</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
|
640
773
|
<span class='kw'>end</span></pre>
|
|
641
774
|
</td>
|
|
642
775
|
</tr>
|
|
@@ -646,7 +779,7 @@
|
|
|
646
779
|
<div class="method_details ">
|
|
647
780
|
<h3 class="signature " id="type-instance_method">
|
|
648
781
|
|
|
649
|
-
#<strong>type</strong> ⇒ <tt>
|
|
782
|
+
#<strong>type</strong> ⇒ <tt>Symbol</tt>
|
|
650
783
|
|
|
651
784
|
|
|
652
785
|
|
|
@@ -655,11 +788,31 @@
|
|
|
655
788
|
</h3><div class="docstring">
|
|
656
789
|
<div class="discussion">
|
|
657
790
|
|
|
791
|
+
<p>Returns <code>:anchormodel</code> — the type identifier.</p>
|
|
792
|
+
|
|
658
793
|
|
|
659
794
|
</div>
|
|
660
795
|
</div>
|
|
661
796
|
<div class="tags">
|
|
662
797
|
|
|
798
|
+
<p class="tag_title">Returns:</p>
|
|
799
|
+
<ul class="return">
|
|
800
|
+
|
|
801
|
+
<li>
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
—
|
|
809
|
+
<div class='inline'>
|
|
810
|
+
<p><code>:anchormodel</code> — the type identifier.</p>
|
|
811
|
+
</div>
|
|
812
|
+
|
|
813
|
+
</li>
|
|
814
|
+
|
|
815
|
+
</ul>
|
|
663
816
|
|
|
664
817
|
</div><table class="source_code">
|
|
665
818
|
<tr>
|
|
@@ -667,12 +820,12 @@
|
|
|
667
820
|
<pre class="lines">
|
|
668
821
|
|
|
669
822
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
823
|
+
21
|
|
824
|
+
22
|
|
825
|
+
23</pre>
|
|
673
826
|
</td>
|
|
674
827
|
<td>
|
|
675
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line
|
|
828
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_single.rb', line 21</span>
|
|
676
829
|
|
|
677
830
|
<span class='kw'>def</span> <span class='id identifier rubyid_type'>type</span>
|
|
678
831
|
<span class='symbol'>:anchormodel</span>
|
|
@@ -687,7 +840,7 @@
|
|
|
687
840
|
</div>
|
|
688
841
|
|
|
689
842
|
<div id="footer">
|
|
690
|
-
Generated on
|
|
843
|
+
Generated on Wed May 13 15:48:25 2026 by
|
|
691
844
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
692
845
|
0.9.28 (ruby-3.3.5).
|
|
693
846
|
</div>
|