anchormodel 0.1.5 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +6 -6
- data/README.md +78 -2
- data/VERSION +1 -1
- data/anchormodel.gemspec +4 -4
- data/doc/Anchormodel/ActiveModelTypeValueMulti.html +410 -0
- data/doc/Anchormodel/ActiveModelTypeValueSingle.html +113 -31
- data/doc/Anchormodel/Attribute.html +109 -9
- data/doc/Anchormodel/ModelMixin.html +3 -92
- data/doc/Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html +267 -0
- data/doc/Anchormodel/SimpleFormInputs/Helpers.html +124 -0
- data/doc/Anchormodel/SimpleFormInputs.html +124 -0
- data/doc/Anchormodel/Util.html +131 -15
- data/doc/Anchormodel/Version.html +3 -3
- data/doc/Anchormodel.html +97 -32
- data/doc/AnchormodelCheckBoxesInput.html +140 -0
- data/doc/AnchormodelGenerator.html +3 -3
- data/doc/AnchormodelInput.html +140 -0
- data/doc/AnchormodelRadioButtonsInput.html +140 -0
- data/doc/_index.html +16 -4
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +77 -5
- data/doc/frames.html +1 -1
- data/doc/index.html +77 -5
- data/doc/method_list.html +49 -9
- data/doc/top-level-namespace.html +4 -4
- data/lib/anchormodel/active_model_type_value_multi.rb +31 -0
- data/lib/anchormodel/active_model_type_value_single.rb +4 -2
- data/lib/anchormodel/attribute.rb +7 -1
- data/lib/anchormodel/model_mixin.rb +7 -0
- data/lib/anchormodel/simple_form_inputs/anchormodel_check_boxes_input.rb +23 -0
- data/lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.rb +7 -3
- data/lib/anchormodel/util.rb +57 -7
- data/lib/anchormodel.rb +7 -0
- data/test/active_record_model/user_test.rb +73 -9
- data/test/dummy/app/anchormodels/animal.rb +6 -0
- data/test/dummy/app/models/user.rb +1 -0
- data/test/dummy/db/migrate/20240425182000_add_animals_to_users.rb +5 -0
- data/test/dummy/db/schema.rb +2 -1
- metadata +13 -2
data/doc/Anchormodel/Util.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Anchormodel::Util
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.34
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -112,7 +112,7 @@
|
|
112
112
|
<li class="public ">
|
113
113
|
<span class="summary_signature">
|
114
114
|
|
115
|
-
<a href="#install_methods_in_model-class_method" title="install_methods_in_model (class method)">.<strong>install_methods_in_model</strong>(model_class, attribute_name, anchormodel_class = nil, optional: false, model_readers: true, model_writers: true, model_scopes: true, model_methods: nil) ⇒ Object </a>
|
115
|
+
<a href="#install_methods_in_model-class_method" title="install_methods_in_model (class method)">.<strong>install_methods_in_model</strong>(model_class, attribute_name, anchormodel_class = nil, optional: false, multiple: false, model_readers: true, model_writers: true, model_scopes: true, model_methods: nil) ⇒ Object </a>
|
116
116
|
|
117
117
|
|
118
118
|
|
@@ -145,7 +145,7 @@
|
|
145
145
|
<div class="method_details first">
|
146
146
|
<h3 class="signature first" id="install_methods_in_model-class_method">
|
147
147
|
|
148
|
-
.<strong>install_methods_in_model</strong>(model_class, attribute_name, anchormodel_class = nil, optional: false, model_readers: true, model_writers: true, model_scopes: true, model_methods: nil) ⇒ <tt>Object</tt>
|
148
|
+
.<strong>install_methods_in_model</strong>(model_class, attribute_name, anchormodel_class = nil, optional: false, multiple: false, model_readers: true, model_writers: true, model_scopes: true, model_methods: nil) ⇒ <tt>Object</tt>
|
149
149
|
|
150
150
|
|
151
151
|
|
@@ -226,7 +226,25 @@
|
|
226
226
|
|
227
227
|
—
|
228
228
|
<div class='inline'>
|
229
|
-
<p>If false, a presence validation is added to the model.</p>
|
229
|
+
<p>If false, a presence validation is added to the model. Forced to true if multiple is true.</p>
|
230
|
+
</div>
|
231
|
+
|
232
|
+
</li>
|
233
|
+
|
234
|
+
<li>
|
235
|
+
|
236
|
+
<span class='name'>multiple</span>
|
237
|
+
|
238
|
+
|
239
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
240
|
+
|
241
|
+
|
242
|
+
<em class="default">(defaults to: <tt>false</tt>)</em>
|
243
|
+
|
244
|
+
|
245
|
+
—
|
246
|
+
<div class='inline'>
|
247
|
+
<p>Internal only. Distinguishes between <code>belongs_to_anchormodel</code> and <code>belongs_to_anchormodels</code>.</p>
|
230
248
|
</div>
|
231
249
|
|
232
250
|
</li>
|
@@ -312,7 +330,6 @@
|
|
312
330
|
<pre class="lines">
|
313
331
|
|
314
332
|
|
315
|
-
13
|
316
333
|
14
|
317
334
|
15
|
318
335
|
16
|
@@ -391,21 +408,73 @@
|
|
391
408
|
89
|
392
409
|
90
|
393
410
|
91
|
394
|
-
92
|
411
|
+
92
|
412
|
+
93
|
413
|
+
94
|
414
|
+
95
|
415
|
+
96
|
416
|
+
97
|
417
|
+
98
|
418
|
+
99
|
419
|
+
100
|
420
|
+
101
|
421
|
+
102
|
422
|
+
103
|
423
|
+
104
|
424
|
+
105
|
425
|
+
106
|
426
|
+
107
|
427
|
+
108
|
428
|
+
109
|
429
|
+
110
|
430
|
+
111
|
431
|
+
112
|
432
|
+
113
|
433
|
+
114
|
434
|
+
115
|
435
|
+
116
|
436
|
+
117
|
437
|
+
118
|
438
|
+
119
|
439
|
+
120
|
440
|
+
121
|
441
|
+
122
|
442
|
+
123
|
443
|
+
124
|
444
|
+
125
|
445
|
+
126
|
446
|
+
127
|
447
|
+
128
|
448
|
+
129
|
449
|
+
130
|
450
|
+
131
|
451
|
+
132
|
452
|
+
133
|
453
|
+
134
|
454
|
+
135
|
455
|
+
136
|
456
|
+
137
|
457
|
+
138
|
458
|
+
139
|
459
|
+
140
|
460
|
+
141
|
461
|
+
142</pre>
|
395
462
|
</td>
|
396
463
|
<td>
|
397
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/util.rb', line
|
464
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/util.rb', line 14</span>
|
398
465
|
|
399
466
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_install_methods_in_model'>install_methods_in_model</span><span class='lparen'>(</span><span class='id identifier rubyid_model_class'>model_class</span><span class='comma'>,</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span>
|
400
467
|
<span class='label'>optional:</span> <span class='kw'>false</span><span class='comma'>,</span>
|
468
|
+
<span class='label'>multiple:</span> <span class='kw'>false</span><span class='comma'>,</span>
|
401
469
|
<span class='label'>model_readers:</span> <span class='kw'>true</span><span class='comma'>,</span>
|
402
470
|
<span class='label'>model_writers:</span> <span class='kw'>true</span><span class='comma'>,</span>
|
403
471
|
<span class='label'>model_scopes:</span> <span class='kw'>true</span><span class='comma'>,</span>
|
404
472
|
<span class='label'>model_methods:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
405
473
|
|
474
|
+
<span class='id identifier rubyid_optional'>optional</span> <span class='op'>=</span> <span class='kw'>true</span> <span class='kw'>if</span> <span class='id identifier rubyid_multiple'>multiple</span>
|
406
475
|
<span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span> <span class='op'>||=</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_classify'>classify</span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
407
476
|
<span class='id identifier rubyid_attribute_name'>attribute_name</span> <span class='op'>=</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
408
|
-
<span class='id identifier rubyid_attribute'>attribute</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Attribute.html" title="Anchormodel::Attribute (class)">Attribute</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Attribute.html#initialize-instance_method" title="Anchormodel::Attribute#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='
|
477
|
+
<span class='id identifier rubyid_attribute'>attribute</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Attribute.html" title="Anchormodel::Attribute (class)">Attribute</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Attribute.html#initialize-instance_method" title="Anchormodel::Attribute#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_model_class'>model_class</span><span class='comma'>,</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='comma'>,</span> <span class='id identifier rubyid_optional'>optional</span><span class='comma'>,</span> <span class='id identifier rubyid_multiple'>multiple</span><span class='rparen'>)</span>
|
409
478
|
|
410
479
|
<span class='comment'># Mass configurations if model_methods was specfied
|
411
480
|
</span> <span class='kw'>unless</span> <span class='id identifier rubyid_model_methods'>model_methods</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
@@ -424,11 +493,43 @@
|
|
424
493
|
|
425
494
|
<span class='comment'># Make casting work
|
426
495
|
</span> <span class='comment'># Define serializer/deserializer
|
427
|
-
</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="
|
496
|
+
</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='id identifier rubyid_multiple'>multiple</span> <span class='op'>?</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="ActiveModelTypeValueMulti.html" title="Anchormodel::ActiveModelTypeValueMulti (class)">ActiveModelTypeValueMulti</a></span></span> <span class='op'>:</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute'>attribute</span><span class='rparen'>)</span>
|
428
497
|
|
429
498
|
<span class='comment'># Overwrite reader to force building anchors at every retrieval
|
430
499
|
</span> <span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
431
|
-
<span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span><span class='period'>.</span><span class='id identifier rubyid_deserialize'>deserialize</span><span class='lparen'>(</span><span class='id identifier rubyid_read_attribute_before_type_cast'>read_attribute_before_type_cast</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
500
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span><span class='period'>.</span><span class='id identifier rubyid_deserialize'>deserialize</span><span class='lparen'>(</span><span class='id identifier rubyid_read_attribute_before_type_cast'>read_attribute_before_type_cast</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
501
|
+
|
502
|
+
<span class='comment'># If this attribute holds multiple anchormodels (`belongs_to_anchormodels`), patch the Array before returning in order to implement collection modifiers:
|
503
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid_multiple'>multiple</span>
|
504
|
+
<span class='id identifier rubyid_model'>model</span> <span class='op'>=</span> <span class='kw'>self</span> <span class='comment'># fetching the model in order to pass it to the implementation of the following via reflection to make it available for storage
|
505
|
+
</span> <span class='id identifier rubyid_single_tv'>single_tv</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="ActiveModelTypeValueSingle.html#initialize-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_attribute'>attribute</span><span class='rparen'>)</span> <span class='comment'># Used for casting inputs to properly compare them to the set.
|
506
|
+
</span>
|
507
|
+
<span class='comment'># Adding
|
508
|
+
</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_define_singleton_method'>define_singleton_method</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>add</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_value_to_add'>value_to_add</span><span class='op'>|</span>
|
509
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_single_tv'>single_tv</span><span class='period'>.</span><span class='id identifier rubyid_cast'>cast</span><span class='lparen'>(</span><span class='id identifier rubyid_value_to_add'>value_to_add</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
510
|
+
<span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_write_attribute'>write_attribute</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span><span class='period'>.</span><span class='id identifier rubyid_serialize'>serialize</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
511
|
+
<span class='kw'>next</span> <span class='kw'>self</span>
|
512
|
+
<span class='kw'>end</span>
|
513
|
+
<span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_define_singleton_method'>define_singleton_method</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'><<</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value_to_add'>value_to_add</span><span class='op'>|</span> <span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='id identifier rubyid_single_tv'>single_tv</span><span class='period'>.</span><span class='id identifier rubyid_cast'>cast</span><span class='lparen'>(</span><span class='id identifier rubyid_value_to_add'>value_to_add</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
514
|
+
|
515
|
+
<span class='comment'># Deleting
|
516
|
+
</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_define_singleton_method'>define_singleton_method</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>delete</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_value_to_delete'>value_to_delete</span><span class='op'>|</span>
|
517
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_single_tv'>single_tv</span><span class='period'>.</span><span class='id identifier rubyid_cast'>cast</span><span class='lparen'>(</span><span class='id identifier rubyid_value_to_delete'>value_to_delete</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
518
|
+
<span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_write_attribute'>write_attribute</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span><span class='period'>.</span><span class='id identifier rubyid_serialize'>serialize</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
519
|
+
<span class='kw'>next</span> <span class='kw'>self</span>
|
520
|
+
<span class='kw'>end</span>
|
521
|
+
|
522
|
+
<span class='comment'># Clearing
|
523
|
+
</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_define_singleton_method'>define_singleton_method</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>clear</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
524
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
525
|
+
<span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_write_attribute'>write_attribute</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span><span class='period'>.</span><span class='id identifier rubyid_serialize'>serialize</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
526
|
+
<span class='kw'>next</span> <span class='kw'>self</span>
|
527
|
+
<span class='kw'>end</span>
|
528
|
+
|
529
|
+
<span class='comment'># In the future, further methods could be supported. e.g. delete_if, subtract etc.
|
530
|
+
</span> <span class='kw'>end</span>
|
531
|
+
|
532
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_result'>result</span>
|
432
533
|
<span class='kw'>end</span>
|
433
534
|
|
434
535
|
<span class='comment'># Override writer to fail early when an invalid target value is specified
|
@@ -447,7 +548,11 @@
|
|
447
548
|
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Anchormodel reader </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>? already defined for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>, add `model_readers: false` to `belongs_to_anchormodel :</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>`.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
448
549
|
<span class='kw'>end</span>
|
449
550
|
<span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>?</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
450
|
-
<span class='
|
551
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_multiple'>multiple</span>
|
552
|
+
<span class='id identifier rubyid_public_send'>public_send</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_entry'>entry</span><span class='rparen'>)</span>
|
553
|
+
<span class='kw'>else</span>
|
554
|
+
<span class='id identifier rubyid_public_send'>public_send</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='id identifier rubyid_entry'>entry</span>
|
555
|
+
<span class='kw'>end</span>
|
451
556
|
<span class='kw'>end</span>
|
452
557
|
<span class='kw'>end</span>
|
453
558
|
<span class='kw'>end</span>
|
@@ -460,7 +565,11 @@
|
|
460
565
|
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Anchormodel writer </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>! already defined for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>, add `model_writers: false` to `belongs_to_anchormodel :</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>`.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
461
566
|
<span class='kw'>end</span>
|
462
567
|
<span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
463
|
-
<span class='
|
568
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_multiple'>multiple</span>
|
569
|
+
<span class='id identifier rubyid_public_send'>public_send</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span> <span class='op'><<</span> <span class='id identifier rubyid_entry'>entry</span>
|
570
|
+
<span class='kw'>else</span>
|
571
|
+
<span class='id identifier rubyid_public_send'>public_send</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>=</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_entry'>entry</span><span class='rparen'>)</span>
|
572
|
+
<span class='kw'>end</span>
|
464
573
|
<span class='kw'>end</span>
|
465
574
|
<span class='kw'>end</span>
|
466
575
|
<span class='kw'>end</span>
|
@@ -472,7 +581,14 @@
|
|
472
581
|
<span class='kw'>if</span> <span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
473
582
|
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Anchormodel scope </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'> already defined for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>, add `model_scopes: false` to `belongs_to_anchormodel :</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>`.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
474
583
|
<span class='kw'>end</span>
|
475
|
-
<span class='
|
584
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_multiple'>multiple</span>
|
585
|
+
<span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_scope'>scope</span><span class='lparen'>(</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_lambda'>lambda</span> <span class='lbrace'>{</span>
|
586
|
+
<span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> LIKE ? OR </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> LIKE ? OR </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> LIKE ? OR </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> LIKE ?</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
587
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>%</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>,%</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>%</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>,%</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_entry'>entry</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='rparen'>)</span>
|
588
|
+
<span class='rbrace'>}</span><span class='rparen'>)</span>
|
589
|
+
<span class='kw'>else</span>
|
590
|
+
<span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_scope'>scope</span><span class='lparen'>(</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='tlambda'>-></span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span> <span class='op'>=></span> <span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
591
|
+
<span class='kw'>end</span>
|
476
592
|
<span class='kw'>end</span>
|
477
593
|
<span class='kw'>end</span>
|
478
594
|
<span class='kw'>end</span></pre>
|
@@ -486,9 +602,9 @@
|
|
486
602
|
</div>
|
487
603
|
|
488
604
|
<div id="footer">
|
489
|
-
Generated on Wed
|
605
|
+
Generated on Wed May 22 11:24:43 2024 by
|
490
606
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
491
|
-
0.9.
|
607
|
+
0.9.34 (ruby-3.2.2).
|
492
608
|
</div>
|
493
609
|
|
494
610
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Anchormodel::Version
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.34
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -129,9 +129,9 @@
|
|
129
129
|
</div>
|
130
130
|
|
131
131
|
<div id="footer">
|
132
|
-
Generated on Wed
|
132
|
+
Generated on Wed May 22 11:24:43 2024 by
|
133
133
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
134
|
-
0.9.
|
134
|
+
0.9.34 (ruby-3.2.2).
|
135
135
|
</div>
|
136
136
|
|
137
137
|
</div>
|
data/doc/Anchormodel.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Class: Anchormodel
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.34
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -120,7 +120,7 @@
|
|
120
120
|
|
121
121
|
|
122
122
|
|
123
|
-
<strong class="classes">Classes:</strong> <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>
|
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>
|
124
124
|
|
125
125
|
|
126
126
|
</p>
|
@@ -243,6 +243,30 @@
|
|
243
243
|
<p>Retrieves a particular value given the key.</p>
|
244
244
|
</div></span>
|
245
245
|
|
246
|
+
</li>
|
247
|
+
|
248
|
+
|
249
|
+
<li class="public ">
|
250
|
+
<span class="summary_signature">
|
251
|
+
|
252
|
+
<a href="#form_collection-class_method" title="form_collection (class method)">.<strong>form_collection</strong> ⇒ Object </a>
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
</span>
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
<span class="summary_desc"><div class='inline'>
|
267
|
+
<p>Returns an array of tuples [label, key] suitable for passing as a collection to some form input helpers.</p>
|
268
|
+
</div></span>
|
269
|
+
|
246
270
|
</li>
|
247
271
|
|
248
272
|
|
@@ -463,11 +487,6 @@
|
|
463
487
|
<pre class="lines">
|
464
488
|
|
465
489
|
|
466
|
-
38
|
467
|
-
39
|
468
|
-
40
|
469
|
-
41
|
470
|
-
42
|
471
490
|
43
|
472
491
|
44
|
473
492
|
45
|
@@ -485,10 +504,15 @@
|
|
485
504
|
57
|
486
505
|
58
|
487
506
|
59
|
488
|
-
60
|
507
|
+
60
|
508
|
+
61
|
509
|
+
62
|
510
|
+
63
|
511
|
+
64
|
512
|
+
65</pre>
|
489
513
|
</td>
|
490
514
|
<td>
|
491
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line
|
515
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 43</span>
|
492
516
|
|
493
517
|
<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>
|
494
518
|
<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>
|
@@ -699,13 +723,13 @@
|
|
699
723
|
<pre class="lines">
|
700
724
|
|
701
725
|
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
726
|
+
35
|
727
|
+
36
|
728
|
+
37
|
729
|
+
38</pre>
|
706
730
|
</td>
|
707
731
|
<td>
|
708
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line
|
732
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 35</span>
|
709
733
|
|
710
734
|
<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>
|
711
735
|
<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>
|
@@ -714,6 +738,47 @@
|
|
714
738
|
</td>
|
715
739
|
</tr>
|
716
740
|
</table>
|
741
|
+
</div>
|
742
|
+
|
743
|
+
<div class="method_details ">
|
744
|
+
<h3 class="signature " id="form_collection-class_method">
|
745
|
+
|
746
|
+
.<strong>form_collection</strong> ⇒ <tt>Object</tt>
|
747
|
+
|
748
|
+
|
749
|
+
|
750
|
+
|
751
|
+
|
752
|
+
</h3><div class="docstring">
|
753
|
+
<div class="discussion">
|
754
|
+
|
755
|
+
<p>Returns an array of tuples [label, key] suitable for passing as a collection to some form input helpers</p>
|
756
|
+
|
757
|
+
|
758
|
+
</div>
|
759
|
+
</div>
|
760
|
+
<div class="tags">
|
761
|
+
|
762
|
+
|
763
|
+
</div><table class="source_code">
|
764
|
+
<tr>
|
765
|
+
<td>
|
766
|
+
<pre class="lines">
|
767
|
+
|
768
|
+
|
769
|
+
29
|
770
|
+
30
|
771
|
+
31</pre>
|
772
|
+
</td>
|
773
|
+
<td>
|
774
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 29</span>
|
775
|
+
|
776
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_form_collection'>form_collection</span>
|
777
|
+
<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>
|
778
|
+
<span class='kw'>end</span></pre>
|
779
|
+
</td>
|
780
|
+
</tr>
|
781
|
+
</table>
|
717
782
|
</div>
|
718
783
|
|
719
784
|
<div class="method_details ">
|
@@ -795,12 +860,12 @@
|
|
795
860
|
<pre class="lines">
|
796
861
|
|
797
862
|
|
798
|
-
|
799
|
-
|
800
|
-
|
863
|
+
67
|
864
|
+
68
|
865
|
+
69</pre>
|
801
866
|
</td>
|
802
867
|
<td>
|
803
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line
|
868
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 67</span>
|
804
869
|
|
805
870
|
<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>
|
806
871
|
<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'>&&</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>
|
@@ -834,12 +899,12 @@
|
|
834
899
|
<pre class="lines">
|
835
900
|
|
836
901
|
|
837
|
-
|
838
|
-
|
839
|
-
|
902
|
+
76
|
903
|
+
77
|
904
|
+
78</pre>
|
840
905
|
</td>
|
841
906
|
<td>
|
842
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line
|
907
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 76</span>
|
843
908
|
|
844
909
|
<span class='kw'>def</span> <span class='id identifier rubyid_inspect'>inspect</span>
|
845
910
|
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>#<</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'><</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>>:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_hash'>hash</span><span class='embexpr_end'>}</span><span class='tstring_content'>></span><span class='tstring_end'>"</span></span>
|
@@ -875,12 +940,12 @@
|
|
875
940
|
<pre class="lines">
|
876
941
|
|
877
942
|
|
878
|
-
|
879
|
-
|
880
|
-
|
943
|
+
72
|
944
|
+
73
|
945
|
+
74</pre>
|
881
946
|
</td>
|
882
947
|
<td>
|
883
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line
|
948
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 72</span>
|
884
949
|
|
885
950
|
<span class='kw'>def</span> <span class='id identifier rubyid_label'>label</span>
|
886
951
|
<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'>"</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'>"</span></span><span class='rparen'>)</span>
|
@@ -914,12 +979,12 @@
|
|
914
979
|
<pre class="lines">
|
915
980
|
|
916
981
|
|
917
|
-
|
918
|
-
|
919
|
-
|
982
|
+
80
|
983
|
+
81
|
984
|
+
82</pre>
|
920
985
|
</td>
|
921
986
|
<td>
|
922
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line
|
987
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 80</span>
|
923
988
|
|
924
989
|
<span class='kw'>def</span> <span class='id identifier rubyid_to_s'>to_s</span>
|
925
990
|
<span class='id identifier rubyid_inspect'>inspect</span>
|
@@ -934,9 +999,9 @@
|
|
934
999
|
</div>
|
935
1000
|
|
936
1001
|
<div id="footer">
|
937
|
-
Generated on Wed
|
1002
|
+
Generated on Wed May 22 11:24:43 2024 by
|
938
1003
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
939
|
-
0.9.
|
1004
|
+
0.9.34 (ruby-3.2.2).
|
940
1005
|
</div>
|
941
1006
|
|
942
1007
|
</div>
|