anchormodel 0.3.1 → 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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +14 -0
  4. data/EXAMPLES.md +408 -0
  5. data/Gemfile.lock +1 -1
  6. data/README.md +43 -1
  7. data/VERSION +1 -1
  8. data/anchormodel.gemspec +3 -3
  9. data/bin/test +9 -0
  10. data/doc/Anchormodel/ActiveModelTypeValueMulti.html +204 -42
  11. data/doc/Anchormodel/ActiveModelTypeValueSingle.html +243 -54
  12. data/doc/Anchormodel/Attribute.html +60 -37
  13. data/doc/Anchormodel/ModelMixin.html +166 -16
  14. data/doc/Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html +82 -21
  15. data/doc/Anchormodel/SimpleFormInputs/Helpers.html +2 -11
  16. data/doc/Anchormodel/SimpleFormInputs.html +2 -11
  17. data/doc/Anchormodel/Util.html +497 -38
  18. data/doc/Anchormodel/Version.html +2 -20
  19. data/doc/Anchormodel.html +536 -129
  20. data/doc/AnchormodelCheckBoxesInput.html +22 -1
  21. data/doc/AnchormodelGenerator.html +64 -13
  22. data/doc/AnchormodelInput.html +24 -1
  23. data/doc/AnchormodelRadioButtonsInput.html +22 -1
  24. data/doc/_index.html +16 -1
  25. data/doc/class_list.html +1 -1
  26. data/doc/file.README.html +40 -2
  27. data/doc/index.html +40 -2
  28. data/doc/method_list.html +57 -17
  29. data/doc/top-level-namespace.html +1 -1
  30. data/lib/anchormodel/active_model_type_value_multi.rb +31 -5
  31. data/lib/anchormodel/active_model_type_value_single.rb +34 -6
  32. data/lib/anchormodel/attribute.rb +20 -8
  33. data/lib/anchormodel/model_mixin.rb +43 -8
  34. data/lib/anchormodel/simple_form_inputs/anchormodel_check_boxes_input.rb +7 -0
  35. data/lib/anchormodel/simple_form_inputs/anchormodel_input.rb +9 -0
  36. data/lib/anchormodel/simple_form_inputs/anchormodel_radio_buttons_input.rb +7 -0
  37. data/lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.rb +14 -0
  38. data/lib/anchormodel/util.rb +102 -17
  39. data/lib/anchormodel.rb +109 -15
  40. data/lib/generators/anchormodel/anchormodel_generator.rb +8 -0
  41. data/test/active_record_model/user_test.rb +221 -10
  42. data/test/dummy/app/anchormodels/animal.rb +1 -0
  43. metadata +3 -1
data/doc/Anchormodel.html CHANGED
@@ -104,13 +104,50 @@
104
104
  <h2>Overview</h2><div class="docstring">
105
105
  <div class="discussion">
106
106
 
107
- <p>Inherit from this class and place your Anchormodel under <code>app/anchormodels/your_anchor_model.rb</code>. Use it like <code>YourAnchorModel</code>. Refer to the README for usage.</p>
107
+ <p>An Anchormodel is a registry of named constants that behave like first-class objects. It is a richer alternative to Rails Enums: each entry is a real Ruby instance that can carry behavior and per-key attributes while still being persistable to a String column in the database.</p>
108
+
109
+ <p>Place anchormodel subclasses under <code>app/anchormodels/your_anchor_model.rb</code> so Rails autoloading picks them up. Refer to the README for usage.</p>
108
110
 
109
111
 
110
112
  </div>
111
113
  </div>
112
114
  <div class="tags">
113
115
 
116
+ <div class="examples">
117
+ <p class="tag_title">Examples:</p>
118
+
119
+
120
+ <p class="example_title"><div class='inline'>
121
+ <p>Define an anchormodel</p>
122
+ </div></p>
123
+
124
+ <pre class="example code"><code><span class='kw'>class</span> <span class='const'>Role</span> <span class='op'>&lt;</span> <span class='const'>Anchormodel</span>
125
+ <span class='id identifier rubyid_include'>include</span> <span class='const'>Comparable</span>
126
+ <span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:privilege_level</span>
127
+
128
+ <span class='kw'>def</span> <span class='op'>&lt;=&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span> <span class='op'>=</span> <span class='id identifier rubyid_privilege_level'>privilege_level</span> <span class='op'>&lt;=&gt;</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_privilege_level'>privilege_level</span>
129
+
130
+ <span class='id identifier rubyid_new'>new</span> <span class='symbol'>:guest</span><span class='comma'>,</span> <span class='label'>privilege_level:</span> <span class='int'>0</span>
131
+ <span class='id identifier rubyid_new'>new</span> <span class='symbol'>:manager</span><span class='comma'>,</span> <span class='label'>privilege_level:</span> <span class='int'>1</span>
132
+ <span class='id identifier rubyid_new'>new</span> <span class='symbol'>:admin</span><span class='comma'>,</span> <span class='label'>privilege_level:</span> <span class='int'>2</span>
133
+ <span class='kw'>end</span></code></pre>
134
+
135
+
136
+ <p class="example_title"><div class='inline'>
137
+ <p>Use it from an ActiveRecord model</p>
138
+ </div></p>
139
+
140
+ <pre class="example code"><code><span class='kw'>class</span> <span class='const'>User</span> <span class='op'>&lt;</span> <span class='const'>ApplicationRecord</span>
141
+ <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span> <span class='symbol'>:role</span>
142
+ <span class='kw'>end</span>
143
+
144
+ <span class='id identifier rubyid_user'>user</span> <span class='op'>=</span> <span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_create!'>create!</span><span class='lparen'>(</span><span class='label'>role:</span> <span class='symbol'>:admin</span><span class='rparen'>)</span>
145
+ <span class='id identifier rubyid_user'>user</span><span class='period'>.</span><span class='id identifier rubyid_role'>role</span> <span class='comment'># =&gt; #&lt;Role&lt;admin&gt;:...&gt;
146
+ </span><span class='id identifier rubyid_user'>user</span><span class='period'>.</span><span class='id identifier rubyid_role'>role</span><span class='period'>.</span><span class='id identifier rubyid_privilege_level'>privilege_level</span> <span class='comment'># =&gt; 2
147
+ </span><span class='id identifier rubyid_user'>user</span><span class='period'>.</span><span class='id identifier rubyid_admin?'>admin?</span> <span class='comment'># =&gt; true</span></code></pre>
148
+
149
+ </div>
150
+
114
151
 
115
152
  </div><h2>Defined Under Namespace</h2>
116
153
  <p class="children">
@@ -120,7 +157,7 @@
120
157
 
121
158
 
122
159
 
123
- <strong class="classes">Classes:</strong> <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueMulti.html" title="Anchormodel::ActiveModelTypeValueMulti (class)">ActiveModelTypeValueMulti</a></span>, <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span>, <span class='object_link'><a href="Anchormodel/Attribute.html" title="Anchormodel::Attribute (class)">Attribute</a></span>
160
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueMulti.html" title="Anchormodel::ActiveModelTypeValueMulti (class)">ActiveModelTypeValueMulti</a></span>, <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span>, <span class='object_link'><a href="Anchormodel/Attribute.html" title="Anchormodel::Attribute (class)">Attribute</a></span>, <span class='object_link'><a href="Anchormodel/InvalidKey.html" title="Anchormodel::InvalidKey (class)">InvalidKey</a></span>
124
161
 
125
162
 
126
163
  </p>
@@ -153,7 +190,9 @@
153
190
 
154
191
 
155
192
 
156
- <span class="summary_desc"><div class='inline'></div></span>
193
+ <span class="summary_desc"><div class='inline'>
194
+ <p>Returns the value of attribute index.</p>
195
+ </div></span>
157
196
 
158
197
  </li>
159
198
 
@@ -180,7 +219,9 @@
180
219
 
181
220
 
182
221
 
183
- <span class="summary_desc"><div class='inline'></div></span>
222
+ <span class="summary_desc"><div class='inline'>
223
+ <p>Returns the value of attribute key.</p>
224
+ </div></span>
184
225
 
185
226
  </li>
186
227
 
@@ -201,7 +242,7 @@
201
242
  <li class="public ">
202
243
  <span class="summary_signature">
203
244
 
204
- <a href="#all-class_method" title="all (class method)">.<strong>all</strong> &#x21d2; Object </a>
245
+ <a href="#all-class_method" title="all (class method)">.<strong>all</strong> &#x21d2; Array&lt;Anchormodel&gt; </a>
205
246
 
206
247
 
207
248
 
@@ -216,7 +257,7 @@
216
257
 
217
258
 
218
259
  <span class="summary_desc"><div class='inline'>
219
- <p>Returns all possible values this Anchormodel can take.</p>
260
+ <p>All registered entries of this subclass, in declaration order.</p>
220
261
  </div></span>
221
262
 
222
263
  </li>
@@ -225,7 +266,7 @@
225
266
  <li class="public ">
226
267
  <span class="summary_signature">
227
268
 
228
- <a href="#find-class_method" title="find (class method)">.<strong>find</strong>(key) &#x21d2; Object </a>
269
+ <a href="#find-class_method" title="find (class method)">.<strong>find</strong>(key) &#x21d2; Anchormodel<sup>?</sup> </a>
229
270
 
230
271
 
231
272
 
@@ -240,7 +281,7 @@
240
281
 
241
282
 
242
283
  <span class="summary_desc"><div class='inline'>
243
- <p>Retrieves a particular value given the key.</p>
284
+ <p>Retrieves the entry registered under <code>key</code>.</p>
244
285
  </div></span>
245
286
 
246
287
  </li>
@@ -249,7 +290,7 @@
249
290
  <li class="public ">
250
291
  <span class="summary_signature">
251
292
 
252
- <a href="#first-class_method" title="first (class method)">.<strong>first</strong> &#x21d2; Object </a>
293
+ <a href="#first-class_method" title="first (class method)">.<strong>first</strong> &#x21d2; Anchormodel<sup>?</sup> </a>
253
294
 
254
295
 
255
296
 
@@ -264,7 +305,7 @@
264
305
 
265
306
 
266
307
  <span class="summary_desc"><div class='inline'>
267
- <p>Shorthand to satisfy rubocop.</p>
308
+ <p>Shorthand for <code>all.first</code>.</p>
268
309
  </div></span>
269
310
 
270
311
  </li>
@@ -273,7 +314,7 @@
273
314
  <li class="public ">
274
315
  <span class="summary_signature">
275
316
 
276
- <a href="#form_collection-class_method" title="form_collection (class method)">.<strong>form_collection</strong> &#x21d2; Object </a>
317
+ <a href="#form_collection-class_method" title="form_collection (class method)">.<strong>form_collection</strong> &#x21d2; Array&lt;Array(String,String)&gt; </a>
277
318
 
278
319
 
279
320
 
@@ -288,7 +329,7 @@
288
329
 
289
330
 
290
331
  <span class="summary_desc"><div class='inline'>
291
- <p>Returns an array of tuples [label, key] suitable for passing as a collection to some form input helpers.</p>
332
+ <p>Builds a <code>[label, key_string]</code> tuple list suitable for Rails form select helpers.</p>
292
333
  </div></span>
293
334
 
294
335
  </li>
@@ -297,7 +338,7 @@
297
338
  <li class="public ">
298
339
  <span class="summary_signature">
299
340
 
300
- <a href="#setup!-class_method" title="setup! (class method)">.<strong>setup!</strong> &#x21d2; Object </a>
341
+ <a href="#setup!-class_method" title="setup! (class method)">.<strong>setup!</strong> &#x21d2; void </a>
301
342
 
302
343
 
303
344
 
@@ -312,7 +353,7 @@
312
353
 
313
354
 
314
355
  <span class="summary_desc"><div class='inline'>
315
- <p>When a descendant of Anchormodel is first used, it must overwrite the class_attributes to prevent cross-class pollution.</p>
356
+ <p>Initializes the per-subclass registry on first use.</p>
316
357
  </div></span>
317
358
 
318
359
  </li>
@@ -330,10 +371,12 @@
330
371
  <li class="public ">
331
372
  <span class="summary_signature">
332
373
 
333
- <a href="#==-instance_method" title="#== (instance method)">#<strong>==</strong>(other) &#x21d2; Object </a>
374
+ <a href="#==-instance_method" title="#== (instance method)">#<strong>==</strong>(other) &#x21d2; Boolean </a>
334
375
 
335
376
 
336
377
 
378
+ (also: #eql?)
379
+
337
380
  </span>
338
381
 
339
382
 
@@ -344,7 +387,9 @@
344
387
 
345
388
 
346
389
 
347
- <span class="summary_desc"><div class='inline'></div></span>
390
+ <span class="summary_desc"><div class='inline'>
391
+ <p>Two anchormodels are equal iff they have the same concrete class and key.</p>
392
+ </div></span>
348
393
 
349
394
  </li>
350
395
 
@@ -352,7 +397,7 @@
352
397
  <li class="public ">
353
398
  <span class="summary_signature">
354
399
 
355
- <a href="#as_json-instance_method" title="#as_json (instance method)">#<strong>as_json</strong> &#x21d2; Object </a>
400
+ <a href="#as_json-instance_method" title="#as_json (instance method)">#<strong>as_json</strong> &#x21d2; String </a>
356
401
 
357
402
 
358
403
 
@@ -366,7 +411,33 @@
366
411
 
367
412
 
368
413
 
369
- <span class="summary_desc"><div class='inline'></div></span>
414
+ <span class="summary_desc"><div class='inline'>
415
+ <p>JSON serialization returns the key as a String so anchormodels round-trip cleanly through JSON (e.g. for API payloads).</p>
416
+ </div></span>
417
+
418
+ </li>
419
+
420
+
421
+ <li class="public ">
422
+ <span class="summary_signature">
423
+
424
+ <a href="#hash-instance_method" title="#hash (instance method)">#<strong>hash</strong> &#x21d2; Integer </a>
425
+
426
+
427
+
428
+ </span>
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+ <span class="summary_desc"><div class='inline'>
439
+ <p>Hash matches <code>==</code> (class + key) so <code>Set</code> and <code>Hash</code> membership work correctly even for copies (<code>dup</code>, Marshal round-trip) of the singleton entries.</p>
440
+ </div></span>
370
441
 
371
442
  </li>
372
443
 
@@ -391,7 +462,7 @@
391
462
 
392
463
 
393
464
  <span class="summary_desc"><div class='inline'>
394
- <p>Call this initializer directly in your Anchormodel class.</p>
465
+ <p>Registers a new entry.</p>
395
466
  </div></span>
396
467
 
397
468
  </li>
@@ -400,7 +471,7 @@
400
471
  <li class="public ">
401
472
  <span class="summary_signature">
402
473
 
403
- <a href="#inspect-instance_method" title="#inspect (instance method)">#<strong>inspect</strong> &#x21d2; Object </a>
474
+ <a href="#inspect-instance_method" title="#inspect (instance method)">#<strong>inspect</strong> &#x21d2; String </a>
404
475
 
405
476
 
406
477
 
@@ -414,7 +485,9 @@
414
485
 
415
486
 
416
487
 
417
- <span class="summary_desc"><div class='inline'></div></span>
488
+ <span class="summary_desc"><div class='inline'>
489
+ <p>Debug representation like <code>&quot;#&lt;Role&lt;admin&gt;:HASH&gt;&quot;</code>.</p>
490
+ </div></span>
418
491
 
419
492
  </li>
420
493
 
@@ -422,7 +495,7 @@
422
495
  <li class="public ">
423
496
  <span class="summary_signature">
424
497
 
425
- <a href="#label-instance_method" title="#label (instance method)">#<strong>label</strong> &#x21d2; Object </a>
498
+ <a href="#label-instance_method" title="#label (instance method)">#<strong>label</strong> &#x21d2; String </a>
426
499
 
427
500
 
428
501
 
@@ -437,7 +510,7 @@
437
510
 
438
511
 
439
512
  <span class="summary_desc"><div class='inline'>
440
- <p>Returns a Rails label that is compatible with the <a href="https://github.com/grosser/gettext_i18n_rails/">Rails FastGettext</a> gem.</p>
513
+ <p>Returns a translatable label for this entry, compatible with the <a href="https://github.com/grosser/gettext_i18n_rails/">Rails FastGettext</a> gem.</p>
441
514
  </div></span>
442
515
 
443
516
  </li>
@@ -446,7 +519,7 @@
446
519
  <li class="public ">
447
520
  <span class="summary_signature">
448
521
 
449
- <a href="#to_s-instance_method" title="#to_s (instance method)">#<strong>to_s</strong> &#x21d2; Object </a>
522
+ <a href="#to_s-instance_method" title="#to_s (instance method)">#<strong>to_s</strong> &#x21d2; String </a>
450
523
 
451
524
 
452
525
 
@@ -460,7 +533,9 @@
460
533
 
461
534
 
462
535
 
463
- <span class="summary_desc"><div class='inline'></div></span>
536
+ <span class="summary_desc"><div class='inline'>
537
+ <p>Same as <span class='object_link'><a href="#inspect-instance_method" title="Anchormodel#inspect (method)">#inspect</a></span>.</p>
538
+ </div></span>
464
539
 
465
540
  </li>
466
541
 
@@ -483,13 +558,24 @@
483
558
  </h3><div class="docstring">
484
559
  <div class="discussion">
485
560
 
486
- <p>Call this initializer directly in your Anchormodel class. To set <code>@foo=:bar</code> for anchor <code>:ter</code>, use <code>new(:ter, foo: :bar)</code></p>
561
+ <p>Registers a new entry. Called in the body of an Anchormodel subclass. All keyword arguments become instance attributes accessible via <code>attr_reader</code>.</p>
487
562
 
488
563
 
489
564
  </div>
490
565
  </div>
491
566
  <div class="tags">
492
- <p class="tag_title">Parameters:</p>
567
+
568
+ <div class="examples">
569
+ <p class="tag_title">Examples:</p>
570
+
571
+
572
+ <pre class="example code"><code><span class='kw'>class</span> <span class='const'>Role</span> <span class='op'>&lt;</span> <span class='const'><span class='object_link'><a href="" title="Anchormodel (class)">Anchormodel</a></span></span>
573
+ <span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:privilege_level</span>
574
+ <span class='id identifier rubyid_new'>new</span> <span class='symbol'>:guest</span><span class='comma'>,</span> <span class='label'>privilege_level:</span> <span class='int'>0</span>
575
+ <span class='kw'>end</span></code></pre>
576
+
577
+ </div>
578
+ <p class="tag_title">Parameters:</p>
493
579
  <ul class="param">
494
580
 
495
581
  <li>
@@ -503,7 +589,7 @@
503
589
 
504
590
  &mdash;
505
591
  <div class='inline'>
506
- <p>The key under which the entry should be stored.</p>
592
+ <p>The unique key under which the entry is registered.</p>
507
593
  </div>
508
594
 
509
595
  </li>
@@ -513,19 +599,37 @@
513
599
  <span class='name'>attributes</span>
514
600
 
515
601
 
516
- <span class='type'></span>
602
+ <span class='type'>(<tt>Hash</tt>)</span>
517
603
 
518
604
 
519
605
 
520
606
  &mdash;
521
607
  <div class='inline'>
522
- <p>All named arguments to Anchormodel are made available as instance attributes.</p>
608
+ <p>Arbitrary attributes exposed as instance variables.</p>
523
609
  </div>
524
610
 
525
611
  </li>
526
612
 
527
613
  </ul>
528
614
 
615
+ <p class="tag_title">Raises:</p>
616
+ <ul class="raise">
617
+
618
+ <li>
619
+
620
+
621
+ <span class='type'>(<tt>RuntimeError</tt>)</span>
622
+
623
+
624
+
625
+ &mdash;
626
+ <div class='inline'>
627
+ <p>if <code>key</code> is already registered for this subclass.</p>
628
+ </div>
629
+
630
+ </li>
631
+
632
+ </ul>
529
633
 
530
634
  </div><table class="source_code">
531
635
  <tr>
@@ -533,33 +637,33 @@
533
637
  <pre class="lines">
534
638
 
535
639
 
536
- 48
537
- 49
538
- 50
539
- 51
540
- 52
541
- 53
542
- 54
543
- 55
544
- 56
545
- 57
546
- 58
547
- 59
548
- 60
549
- 61
550
- 62
551
- 63
552
- 64
553
- 65
554
- 66
555
- 67
556
- 68
557
- 69
558
- 70
559
- 71</pre>
640
+ 115
641
+ 116
642
+ 117
643
+ 118
644
+ 119
645
+ 120
646
+ 121
647
+ 122
648
+ 123
649
+ 124
650
+ 125
651
+ 126
652
+ 127
653
+ 128
654
+ 129
655
+ 130
656
+ 131
657
+ 132
658
+ 133
659
+ 134
660
+ 135
661
+ 136
662
+ 137
663
+ 138</pre>
560
664
  </td>
561
665
  <td>
562
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 48</span>
666
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 115</span>
563
667
 
564
668
  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_attributes'>attributes</span><span class='rparen'>)</span>
565
669
  <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_setup!'>setup!</span> <span class='kw'>unless</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_setup_completed'>setup_completed</span>
@@ -609,6 +713,8 @@
609
713
  </h3><div class="docstring">
610
714
  <div class="discussion">
611
715
 
716
+ <p>Returns the value of attribute index.</p>
717
+
612
718
 
613
719
  </div>
614
720
  </div>
@@ -621,12 +727,12 @@
621
727
  <pre class="lines">
622
728
 
623
729
 
624
- 6
625
- 7
626
- 8</pre>
730
+ 37
731
+ 38
732
+ 39</pre>
627
733
  </td>
628
734
  <td>
629
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 6</span>
735
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 37</span>
630
736
 
631
737
  <span class='kw'>def</span> <span class='id identifier rubyid_index'>index</span>
632
738
  <span class='ivar'>@index</span>
@@ -650,6 +756,8 @@
650
756
  </h3><div class="docstring">
651
757
  <div class="discussion">
652
758
 
759
+ <p>Returns the value of attribute key.</p>
760
+
653
761
 
654
762
  </div>
655
763
  </div>
@@ -662,12 +770,12 @@
662
770
  <pre class="lines">
663
771
 
664
772
 
665
- 5
666
- 6
667
- 7</pre>
773
+ 33
774
+ 34
775
+ 35</pre>
668
776
  </td>
669
777
  <td>
670
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 5</span>
778
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 33</span>
671
779
 
672
780
  <span class='kw'>def</span> <span class='id identifier rubyid_key'>key</span>
673
781
  <span class='ivar'>@key</span>
@@ -687,7 +795,7 @@
687
795
  <div class="method_details first">
688
796
  <h3 class="signature first" id="all-class_method">
689
797
 
690
- .<strong>all</strong> &#x21d2; <tt>Object</tt>
798
+ .<strong>all</strong> &#x21d2; <tt>Array&lt;<span class='object_link'><a href="" title="Anchormodel (class)">Anchormodel</a></span>&gt;</tt>
691
799
 
692
800
 
693
801
 
@@ -696,13 +804,39 @@
696
804
  </h3><div class="docstring">
697
805
  <div class="discussion">
698
806
 
699
- <p>Returns all possible values this Anchormodel can take.</p>
807
+ <p>Returns All registered entries of this subclass, in declaration order.</p>
700
808
 
701
809
 
702
810
  </div>
703
811
  </div>
704
812
  <div class="tags">
705
813
 
814
+ <div class="examples">
815
+ <p class="tag_title">Examples:</p>
816
+
817
+
818
+ <pre class="example code"><code><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span> <span class='comment'># =&gt; [#&lt;Role&lt;guest&gt;&gt;, #&lt;Role&lt;manager&gt;&gt;, #&lt;Role&lt;admin&gt;&gt;]</span></code></pre>
819
+
820
+ </div>
821
+
822
+ <p class="tag_title">Returns:</p>
823
+ <ul class="return">
824
+
825
+ <li>
826
+
827
+
828
+ <span class='type'>(<tt>Array&lt;<span class='object_link'><a href="" title="Anchormodel (class)">Anchormodel</a></span>&gt;</tt>)</span>
829
+
830
+
831
+
832
+ &mdash;
833
+ <div class='inline'>
834
+ <p>All registered entries of this subclass, in declaration order.</p>
835
+ </div>
836
+
837
+ </li>
838
+
839
+ </ul>
706
840
 
707
841
  </div><table class="source_code">
708
842
  <tr>
@@ -710,12 +844,12 @@
710
844
  <pre class="lines">
711
845
 
712
846
 
713
- 24
714
- 25
715
- 26</pre>
847
+ 63
848
+ 64
849
+ 65</pre>
716
850
  </td>
717
851
  <td>
718
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 24</span>
852
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 63</span>
719
853
 
720
854
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span>
721
855
  <span class='id identifier rubyid_entries_list'>entries_list</span>
@@ -728,7 +862,7 @@
728
862
  <div class="method_details ">
729
863
  <h3 class="signature " id="find-class_method">
730
864
 
731
- .<strong>find</strong>(key) &#x21d2; <tt>Object</tt>
865
+ .<strong>find</strong>(key) &#x21d2; <tt><span class='object_link'><a href="" title="Anchormodel (class)">Anchormodel</a></span></tt><sup>?</sup>
732
866
 
733
867
 
734
868
 
@@ -737,13 +871,24 @@
737
871
  </h3><div class="docstring">
738
872
  <div class="discussion">
739
873
 
740
- <p>Retrieves a particular value given the key. Fails if not found.</p>
874
+ <p>Retrieves the entry registered under <code>key</code>.</p>
741
875
 
742
876
 
743
877
  </div>
744
878
  </div>
745
879
  <div class="tags">
746
- <p class="tag_title">Parameters:</p>
880
+
881
+ <div class="examples">
882
+ <p class="tag_title">Examples:</p>
883
+
884
+
885
+ <pre class="example code"><code><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='symbol'>:admin</span><span class='rparen'>)</span> <span class='comment'># =&gt; #&lt;Role&lt;admin&gt;&gt;
886
+ </span><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>admin</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'># =&gt; #&lt;Role&lt;admin&gt;&gt; (same singleton instance)
887
+ </span><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='kw'>nil</span><span class='rparen'>)</span> <span class='comment'># =&gt; nil
888
+ </span><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='symbol'>:nope</span><span class='rparen'>)</span> <span class='comment'># raises Anchormodel::InvalidKey</span></code></pre>
889
+
890
+ </div>
891
+ <p class="tag_title">Parameters:</p>
747
892
  <ul class="param">
748
893
 
749
894
  <li>
@@ -751,7 +896,7 @@
751
896
  <span class='name'>key</span>
752
897
 
753
898
 
754
- <span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
899
+ <span class='type'>(<tt>String</tt>, <tt>Symbol</tt>, <tt>nil</tt>)</span>
755
900
 
756
901
 
757
902
 
@@ -764,6 +909,42 @@
764
909
 
765
910
  </ul>
766
911
 
912
+ <p class="tag_title">Returns:</p>
913
+ <ul class="return">
914
+
915
+ <li>
916
+
917
+
918
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Anchormodel (class)">Anchormodel</a></span></tt>, <tt>nil</tt>)</span>
919
+
920
+
921
+
922
+ &mdash;
923
+ <div class='inline'>
924
+ <p>The matching entry, or <code>nil</code> if <code>key</code> is <code>nil</code>.</p>
925
+ </div>
926
+
927
+ </li>
928
+
929
+ </ul>
930
+ <p class="tag_title">Raises:</p>
931
+ <ul class="raise">
932
+
933
+ <li>
934
+
935
+
936
+ <span class='type'>(<tt><span class='object_link'><a href="Anchormodel/InvalidKey.html" title="Anchormodel::InvalidKey (class)">Anchormodel::InvalidKey</a></span></tt>)</span>
937
+
938
+
939
+
940
+ &mdash;
941
+ <div class='inline'>
942
+ <p>if no entry with that key exists.</p>
943
+ </div>
944
+
945
+ </li>
946
+
947
+ </ul>
767
948
 
768
949
  </div><table class="source_code">
769
950
  <tr>
@@ -771,17 +952,17 @@
771
952
  <pre class="lines">
772
953
 
773
954
 
774
- 40
775
- 41
776
- 42
777
- 43</pre>
955
+ 99
956
+ 100
957
+ 101
958
+ 102</pre>
778
959
  </td>
779
960
  <td>
780
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 40</span>
961
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 99</span>
781
962
 
782
963
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
783
964
  <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
784
- <span class='kw'>return</span> <span class='id identifier rubyid_entries_hash'>entries_hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Retreived undefined anchor model key </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'> for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
965
+ <span class='kw'>return</span> <span class='id identifier rubyid_entries_hash'>entries_hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="Anchormodel/InvalidKey.html" title="Anchormodel::InvalidKey (class)">InvalidKey</a></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Retrieved undefined anchor model key </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'> for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
785
966
  <span class='kw'>end</span></pre>
786
967
  </td>
787
968
  </tr>
@@ -791,7 +972,7 @@
791
972
  <div class="method_details ">
792
973
  <h3 class="signature " id="first-class_method">
793
974
 
794
- .<strong>first</strong> &#x21d2; <tt>Object</tt>
975
+ .<strong>first</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Anchormodel (class)">Anchormodel</a></span></tt><sup>?</sup>
795
976
 
796
977
 
797
978
 
@@ -800,13 +981,31 @@
800
981
  </h3><div class="docstring">
801
982
  <div class="discussion">
802
983
 
803
- <p>Shorthand to satisfy rubocop</p>
984
+ <p>Shorthand for <code>all.first</code>. Provided so callers can avoid Rubocop’s <code>Style/FirstElementInCollection</code>-style warnings on <code>Foo.all.first</code>.</p>
804
985
 
805
986
 
806
987
  </div>
807
988
  </div>
808
989
  <div class="tags">
809
990
 
991
+ <p class="tag_title">Returns:</p>
992
+ <ul class="return">
993
+
994
+ <li>
995
+
996
+
997
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Anchormodel (class)">Anchormodel</a></span></tt>, <tt>nil</tt>)</span>
998
+
999
+
1000
+
1001
+ &mdash;
1002
+ <div class='inline'>
1003
+ <p>The first registered entry, or <code>nil</code> if the registry is empty.</p>
1004
+ </div>
1005
+
1006
+ </li>
1007
+
1008
+ </ul>
810
1009
 
811
1010
  </div><table class="source_code">
812
1011
  <tr>
@@ -814,12 +1013,12 @@
814
1013
  <pre class="lines">
815
1014
 
816
1015
 
817
- 29
818
- 30
819
- 31</pre>
1016
+ 70
1017
+ 71
1018
+ 72</pre>
820
1019
  </td>
821
1020
  <td>
822
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 29</span>
1021
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 70</span>
823
1022
 
824
1023
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
825
1024
  <span class='id identifier rubyid_all'>all</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
@@ -832,7 +1031,7 @@
832
1031
  <div class="method_details ">
833
1032
  <h3 class="signature " id="form_collection-class_method">
834
1033
 
835
- .<strong>form_collection</strong> &#x21d2; <tt>Object</tt>
1034
+ .<strong>form_collection</strong> &#x21d2; <tt>Array&lt;Array(String,String)&gt;</tt>
836
1035
 
837
1036
 
838
1037
 
@@ -841,13 +1040,34 @@
841
1040
  </h3><div class="docstring">
842
1041
  <div class="discussion">
843
1042
 
844
- <p>Returns an array of tuples [label, key] suitable for passing as a collection to some form input helpers</p>
1043
+ <p>Builds a <code>[label, key_string]</code> tuple list suitable for Rails form select helpers.</p>
845
1044
 
846
1045
 
847
1046
  </div>
848
1047
  </div>
849
1048
  <div class="tags">
850
1049
 
1050
+ <div class="examples">
1051
+ <p class="tag_title">Examples:</p>
1052
+
1053
+
1054
+ <pre class="example code"><code>&lt;%= form.select :role, Role.form_collection %&gt;</code></pre>
1055
+
1056
+ </div>
1057
+
1058
+ <p class="tag_title">Returns:</p>
1059
+ <ul class="return">
1060
+
1061
+ <li>
1062
+
1063
+
1064
+ <span class='type'>(<tt>Array&lt;Array(String,String)&gt;</tt>)</span>
1065
+
1066
+
1067
+
1068
+ </li>
1069
+
1070
+ </ul>
851
1071
 
852
1072
  </div><table class="source_code">
853
1073
  <tr>
@@ -855,12 +1075,12 @@
855
1075
  <pre class="lines">
856
1076
 
857
1077
 
858
- 34
859
- 35
860
- 36</pre>
1078
+ 78
1079
+ 79
1080
+ 80</pre>
861
1081
  </td>
862
1082
  <td>
863
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 34</span>
1083
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 78</span>
864
1084
 
865
1085
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_form_collection'>form_collection</span>
866
1086
  <span class='id identifier rubyid_entries_list'>entries_list</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_el'>el</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_el'>el</span><span class='period'>.</span><span class='id identifier rubyid_label'>label</span><span class='comma'>,</span> <span class='id identifier rubyid_el'>el</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><span class='rbracket'>]</span> <span class='rbrace'>}</span>
@@ -873,7 +1093,7 @@
873
1093
  <div class="method_details ">
874
1094
  <h3 class="signature " id="setup!-class_method">
875
1095
 
876
- .<strong>setup!</strong> &#x21d2; <tt>Object</tt>
1096
+ .<strong>setup!</strong> &#x21d2; <tt>void</tt>
877
1097
 
878
1098
 
879
1099
 
@@ -881,14 +1101,34 @@
881
1101
 
882
1102
  </h3><div class="docstring">
883
1103
  <div class="discussion">
884
-
885
- <p>When a descendant of Anchormodel is first used, it must overwrite the class_attributes to prevent cross-class pollution.</p>
1104
+ <p class="note returns_void">This method returns an undefined value.</p>
1105
+ <p>Initializes the per-subclass registry on first use. Called automatically from the first <code>new</code> invocation. Each subclass gets its own duped copies of the registry class attributes to prevent cross-class pollution.</p>
1106
+
1107
+ <p>You normally do not need to call this directly.</p>
886
1108
 
887
1109
 
888
1110
  </div>
889
1111
  </div>
890
1112
  <div class="tags">
891
1113
 
1114
+ <p class="tag_title">Raises:</p>
1115
+ <ul class="raise">
1116
+
1117
+ <li>
1118
+
1119
+
1120
+ <span class='type'>(<tt>RuntimeError</tt>)</span>
1121
+
1122
+
1123
+
1124
+ &mdash;
1125
+ <div class='inline'>
1126
+ <p>if called twice for the same subclass.</p>
1127
+ </div>
1128
+
1129
+ </li>
1130
+
1131
+ </ul>
892
1132
 
893
1133
  </div><table class="source_code">
894
1134
  <tr>
@@ -896,16 +1136,16 @@
896
1136
  <pre class="lines">
897
1137
 
898
1138
 
899
- 15
900
- 16
901
- 17
902
- 18
903
- 19
904
- 20
905
- 21</pre>
1139
+ 52
1140
+ 53
1141
+ 54
1142
+ 55
1143
+ 56
1144
+ 57
1145
+ 58</pre>
906
1146
  </td>
907
1147
  <td>
908
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 15</span>
1148
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 52</span>
909
1149
 
910
1150
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup!'>setup!</span>
911
1151
  <span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>`setup!` was called twice for Anchormodel subclass </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_setup_completed'>setup_completed</span>
@@ -928,20 +1168,54 @@
928
1168
  <div class="method_details first">
929
1169
  <h3 class="signature first" id="==-instance_method">
930
1170
 
931
- #<strong>==</strong>(other) &#x21d2; <tt>Object</tt>
1171
+ #<strong>==</strong>(other) &#x21d2; <tt>Boolean</tt>
932
1172
 
933
1173
 
934
1174
 
1175
+ <span class="aliases">Also known as:
1176
+ <span class="names"><span id='eql?-instance_method'>eql?</span></span>
1177
+ </span>
1178
+
935
1179
 
936
1180
 
937
1181
  </h3><div class="docstring">
938
1182
  <div class="discussion">
939
1183
 
1184
+ <p>Two anchormodels are equal iff they have the same concrete class and key. Different subclasses sharing a key are not equal.</p>
1185
+
940
1186
 
941
1187
  </div>
942
1188
  </div>
943
1189
  <div class="tags">
1190
+ <p class="tag_title">Parameters:</p>
1191
+ <ul class="param">
1192
+
1193
+ <li>
1194
+
1195
+ <span class='name'>other</span>
1196
+
1197
+
1198
+ <span class='type'>(<tt>Object</tt>)</span>
1199
+
1200
+
1201
+
1202
+ </li>
1203
+
1204
+ </ul>
1205
+
1206
+ <p class="tag_title">Returns:</p>
1207
+ <ul class="return">
1208
+
1209
+ <li>
1210
+
1211
+
1212
+ <span class='type'>(<tt>Boolean</tt>)</span>
1213
+
1214
+
1215
+
1216
+ </li>
944
1217
 
1218
+ </ul>
945
1219
 
946
1220
  </div><table class="source_code">
947
1221
  <tr>
@@ -949,12 +1223,12 @@
949
1223
  <pre class="lines">
950
1224
 
951
1225
 
952
- 73
953
- 74
954
- 75</pre>
1226
+ 144
1227
+ 145
1228
+ 146</pre>
955
1229
  </td>
956
1230
  <td>
957
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 73</span>
1231
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 144</span>
958
1232
 
959
1233
  <span class='kw'>def</span> <span class='op'>==</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
960
1234
  <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>==</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_key'>key</span> <span class='op'>==</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span>
@@ -967,7 +1241,7 @@
967
1241
  <div class="method_details ">
968
1242
  <h3 class="signature " id="as_json-instance_method">
969
1243
 
970
- #<strong>as_json</strong> &#x21d2; <tt>Object</tt>
1244
+ #<strong>as_json</strong> &#x21d2; <tt>String</tt>
971
1245
 
972
1246
 
973
1247
 
@@ -976,11 +1250,34 @@
976
1250
  </h3><div class="docstring">
977
1251
  <div class="discussion">
978
1252
 
1253
+ <p>JSON serialization returns the key as a String so anchormodels round-trip cleanly through JSON (e.g. for API payloads).</p>
1254
+
979
1255
 
980
1256
  </div>
981
1257
  </div>
982
1258
  <div class="tags">
983
1259
 
1260
+ <div class="examples">
1261
+ <p class="tag_title">Examples:</p>
1262
+
1263
+
1264
+ <pre class="example code"><code><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='symbol'>:admin</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_as_json'>as_json</span> <span class='comment'># =&gt; &quot;admin&quot;</span></code></pre>
1265
+
1266
+ </div>
1267
+
1268
+ <p class="tag_title">Returns:</p>
1269
+ <ul class="return">
1270
+
1271
+ <li>
1272
+
1273
+
1274
+ <span class='type'>(<tt>String</tt>)</span>
1275
+
1276
+
1277
+
1278
+ </li>
1279
+
1280
+ </ul>
984
1281
 
985
1282
  </div><table class="source_code">
986
1283
  <tr>
@@ -988,12 +1285,12 @@
988
1285
  <pre class="lines">
989
1286
 
990
1287
 
991
- 90
992
- 91
993
- 92</pre>
1288
+ 184
1289
+ 185
1290
+ 186</pre>
994
1291
  </td>
995
1292
  <td>
996
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 90</span>
1293
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 184</span>
997
1294
 
998
1295
  <span class='kw'>def</span> <span class='id identifier rubyid_as_json'>as_json</span>
999
1296
  <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
@@ -1001,12 +1298,66 @@
1001
1298
  </td>
1002
1299
  </tr>
1003
1300
  </table>
1301
+ </div>
1302
+
1303
+ <div class="method_details ">
1304
+ <h3 class="signature " id="hash-instance_method">
1305
+
1306
+ #<strong>hash</strong> &#x21d2; <tt>Integer</tt>
1307
+
1308
+
1309
+
1310
+
1311
+
1312
+ </h3><div class="docstring">
1313
+ <div class="discussion">
1314
+
1315
+ <p>Hash matches <code>==</code> (class + key) so <code>Set</code> and <code>Hash</code> membership work correctly even for copies (<code>dup</code>, Marshal round-trip) of the singleton entries.</p>
1316
+
1317
+
1318
+ </div>
1319
+ </div>
1320
+ <div class="tags">
1321
+
1322
+ <p class="tag_title">Returns:</p>
1323
+ <ul class="return">
1324
+
1325
+ <li>
1326
+
1327
+
1328
+ <span class='type'>(<tt>Integer</tt>)</span>
1329
+
1330
+
1331
+
1332
+ </li>
1333
+
1334
+ </ul>
1335
+
1336
+ </div><table class="source_code">
1337
+ <tr>
1338
+ <td>
1339
+ <pre class="lines">
1340
+
1341
+
1342
+ 152
1343
+ 153
1344
+ 154</pre>
1345
+ </td>
1346
+ <td>
1347
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 152</span>
1348
+
1349
+ <span class='kw'>def</span> <span class='id identifier rubyid_hash'>hash</span>
1350
+ <span class='lbracket'>[</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_hash'>hash</span>
1351
+ <span class='kw'>end</span></pre>
1352
+ </td>
1353
+ </tr>
1354
+ </table>
1004
1355
  </div>
1005
1356
 
1006
1357
  <div class="method_details ">
1007
1358
  <h3 class="signature " id="inspect-instance_method">
1008
1359
 
1009
- #<strong>inspect</strong> &#x21d2; <tt>Object</tt>
1360
+ #<strong>inspect</strong> &#x21d2; <tt>String</tt>
1010
1361
 
1011
1362
 
1012
1363
 
@@ -1015,11 +1366,31 @@
1015
1366
  </h3><div class="docstring">
1016
1367
  <div class="discussion">
1017
1368
 
1369
+ <p>Returns Debug representation like <code>&quot;#&lt;Role&lt;admin&gt;:HASH&gt;&quot;</code>.</p>
1370
+
1018
1371
 
1019
1372
  </div>
1020
1373
  </div>
1021
1374
  <div class="tags">
1022
1375
 
1376
+ <p class="tag_title">Returns:</p>
1377
+ <ul class="return">
1378
+
1379
+ <li>
1380
+
1381
+
1382
+ <span class='type'>(<tt>String</tt>)</span>
1383
+
1384
+
1385
+
1386
+ &mdash;
1387
+ <div class='inline'>
1388
+ <p>Debug representation like <code>&quot;#&lt;Role&lt;admin&gt;:HASH&gt;&quot;</code>.</p>
1389
+ </div>
1390
+
1391
+ </li>
1392
+
1393
+ </ul>
1023
1394
 
1024
1395
  </div><table class="source_code">
1025
1396
  <tr>
@@ -1027,12 +1398,12 @@
1027
1398
  <pre class="lines">
1028
1399
 
1029
1400
 
1030
- 82
1031
- 83
1032
- 84</pre>
1401
+ 167
1402
+ 168
1403
+ 169</pre>
1033
1404
  </td>
1034
1405
  <td>
1035
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 82</span>
1406
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 167</span>
1036
1407
 
1037
1408
  <span class='kw'>def</span> <span class='id identifier rubyid_inspect'>inspect</span>
1038
1409
  <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>#&lt;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>&lt;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>&gt;:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_hash'>hash</span><span class='embexpr_end'>}</span><span class='tstring_content'>&gt;</span><span class='tstring_end'>&quot;</span></span>
@@ -1045,7 +1416,7 @@
1045
1416
  <div class="method_details ">
1046
1417
  <h3 class="signature " id="label-instance_method">
1047
1418
 
1048
- #<strong>label</strong> &#x21d2; <tt>Object</tt>
1419
+ #<strong>label</strong> &#x21d2; <tt>String</tt>
1049
1420
 
1050
1421
 
1051
1422
 
@@ -1054,13 +1425,34 @@
1054
1425
  </h3><div class="docstring">
1055
1426
  <div class="discussion">
1056
1427
 
1057
- <p>Returns a Rails label that is compatible with the <a href="https://github.com/grosser/gettext_i18n_rails/">Rails FastGettext</a> gem.</p>
1428
+ <p>Returns a translatable label for this entry, compatible with the <a href="https://github.com/grosser/gettext_i18n_rails/">Rails FastGettext</a> gem. The translation key is <code>&quot;&lt;SubclassName&gt;|&lt;Humanized key&gt;&quot;</code>.</p>
1058
1429
 
1059
1430
 
1060
1431
  </div>
1061
1432
  </div>
1062
1433
  <div class="tags">
1063
1434
 
1435
+ <div class="examples">
1436
+ <p class="tag_title">Examples:</p>
1437
+
1438
+
1439
+ <pre class="example code"><code><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='symbol'>:admin</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_label'>label</span> <span class='comment'># =&gt; &quot;Role|Admin&quot; (or its I18n translation)</span></code></pre>
1440
+
1441
+ </div>
1442
+
1443
+ <p class="tag_title">Returns:</p>
1444
+ <ul class="return">
1445
+
1446
+ <li>
1447
+
1448
+
1449
+ <span class='type'>(<tt>String</tt>)</span>
1450
+
1451
+
1452
+
1453
+ </li>
1454
+
1455
+ </ul>
1064
1456
 
1065
1457
  </div><table class="source_code">
1066
1458
  <tr>
@@ -1068,12 +1460,12 @@
1068
1460
  <pre class="lines">
1069
1461
 
1070
1462
 
1071
- 78
1072
- 79
1073
- 80</pre>
1463
+ 162
1464
+ 163
1465
+ 164</pre>
1074
1466
  </td>
1075
1467
  <td>
1076
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 78</span>
1468
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 162</span>
1077
1469
 
1078
1470
  <span class='kw'>def</span> <span class='id identifier rubyid_label'>label</span>
1079
1471
  <span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_t'>t</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_demodulize'>demodulize</span><span class='embexpr_end'>}</span><span class='tstring_content'>|</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_humanize'>humanize</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
@@ -1086,7 +1478,7 @@
1086
1478
  <div class="method_details ">
1087
1479
  <h3 class="signature " id="to_s-instance_method">
1088
1480
 
1089
- #<strong>to_s</strong> &#x21d2; <tt>Object</tt>
1481
+ #<strong>to_s</strong> &#x21d2; <tt>String</tt>
1090
1482
 
1091
1483
 
1092
1484
 
@@ -1095,11 +1487,26 @@
1095
1487
  </h3><div class="docstring">
1096
1488
  <div class="discussion">
1097
1489
 
1490
+ <p>Same as <span class='object_link'><a href="#inspect-instance_method" title="Anchormodel#inspect (method)">#inspect</a></span>. Anchormodel intentionally overrides <code>to_s</code> so string interpolation in templates is unambiguous; render <code>#label</code> or <code>#key</code> directly if you want a user-facing form.</p>
1491
+
1098
1492
 
1099
1493
  </div>
1100
1494
  </div>
1101
1495
  <div class="tags">
1102
1496
 
1497
+ <p class="tag_title">Returns:</p>
1498
+ <ul class="return">
1499
+
1500
+ <li>
1501
+
1502
+
1503
+ <span class='type'>(<tt>String</tt>)</span>
1504
+
1505
+
1506
+
1507
+ </li>
1508
+
1509
+ </ul>
1103
1510
 
1104
1511
  </div><table class="source_code">
1105
1512
  <tr>
@@ -1107,12 +1514,12 @@
1107
1514
  <pre class="lines">
1108
1515
 
1109
1516
 
1110
- 86
1111
- 87
1112
- 88</pre>
1517
+ 175
1518
+ 176
1519
+ 177</pre>
1113
1520
  </td>
1114
1521
  <td>
1115
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 86</span>
1522
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 175</span>
1116
1523
 
1117
1524
  <span class='kw'>def</span> <span class='id identifier rubyid_to_s'>to_s</span>
1118
1525
  <span class='id identifier rubyid_inspect'>inspect</span>
@@ -1127,7 +1534,7 @@
1127
1534
  </div>
1128
1535
 
1129
1536
  <div id="footer">
1130
- Generated on Wed May 13 11:46:10 2026 by
1537
+ Generated on Wed May 13 15:48:24 2026 by
1131
1538
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1132
1539
  0.9.28 (ruby-3.3.5).
1133
1540
  </div>