anchormodel 0.0.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +206 -0
  6. data/README.md +98 -9
  7. data/Rakefile +23 -3
  8. data/anchormodel.gemspec +26 -10
  9. data/bin/rails +7 -0
  10. data/doc/Anchormodel/ActiveModelTypeValue.html +14 -10
  11. data/doc/Anchormodel/Attribute.html +75 -71
  12. data/doc/Anchormodel/ModelMixin.html +190 -21
  13. data/doc/Anchormodel/Version.html +4 -4
  14. data/doc/Anchormodel.html +151 -53
  15. data/doc/_index.html +2 -2
  16. data/doc/file.README.html +118 -47
  17. data/doc/index.html +118 -47
  18. data/doc/method_list.html +9 -1
  19. data/doc/top-level-namespace.html +2 -2
  20. data/lib/anchormodel/active_model_type_value.rb +4 -4
  21. data/lib/anchormodel/attribute.rb +4 -9
  22. data/lib/anchormodel/model_mixin.rb +53 -3
  23. data/lib/anchormodel/version.rb +2 -2
  24. data/lib/anchormodel.rb +7 -2
  25. data/logo.svg +98 -0
  26. data/test/active_record_model/user_test.rb +115 -0
  27. data/test/dummy/.gitignore +29 -0
  28. data/test/dummy/Rakefile +6 -0
  29. data/test/dummy/app/anchormodels/locale.rb +6 -0
  30. data/test/dummy/app/anchormodels/role.rb +14 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/models/application_record.rb +5 -0
  33. data/test/dummy/app/models/concerns/.keep +0 -0
  34. data/test/dummy/app/models/user.rb +6 -0
  35. data/test/dummy/bin/rails +4 -0
  36. data/test/dummy/bin/rake +4 -0
  37. data/test/dummy/bin/setup +33 -0
  38. data/test/dummy/config/application.rb +37 -0
  39. data/test/dummy/config/boot.rb +3 -0
  40. data/test/dummy/config/credentials.yml.enc +1 -0
  41. data/test/dummy/config/database.yml +8 -0
  42. data/test/dummy/config/environment.rb +5 -0
  43. data/test/dummy/config/environments/test.rb +50 -0
  44. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  45. data/test/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  46. data/test/dummy/config/initializers/inflections.rb +16 -0
  47. data/test/dummy/config/initializers/permissions_policy.rb +11 -0
  48. data/test/dummy/config/locales/en.yml +33 -0
  49. data/test/dummy/config/puma.rb +43 -0
  50. data/test/dummy/config/routes.rb +6 -0
  51. data/test/dummy/config.ru +6 -0
  52. data/test/dummy/db/migrate/20230107173151_create_users.rb +12 -0
  53. data/test/dummy/db/schema.rb +23 -0
  54. data/test/dummy/db/seeds.rb +7 -0
  55. data/test/dummy/lib/tasks/.keep +0 -0
  56. data/test/dummy/log/.keep +0 -0
  57. data/test/dummy/tmp/.keep +0 -0
  58. data/test/dummy/tmp/pids/.keep +0 -0
  59. data/test/test_helper.rb +21 -0
  60. metadata +149 -13
  61. data/anchormodel-0.0.1.gem +0 -0
@@ -101,8 +101,8 @@
101
101
 
102
102
  <h2>Overview</h2><div class="docstring">
103
103
  <div class="discussion">
104
- <p>This class holds all information related to a Rails model pointing to an Anchormodel.
105
- It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
104
+
105
+ <p>This class holds all information related to a Rails model pointing to an Anchormodel. It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
106
106
 
107
107
 
108
108
  </div>
@@ -120,7 +120,7 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
120
120
  <li class="public ">
121
121
  <span class="summary_signature">
122
122
 
123
- <a href="#attribute_name-instance_method" title="#attribute_name (instance method)">#<strong>attribute_name</strong> &#x21d2; Object </a>
123
+ <a href="#anchormodel_class-instance_method" title="#anchormodel_class (instance method)">#<strong>anchormodel_class</strong> &#x21d2; Object </a>
124
124
 
125
125
 
126
126
 
@@ -147,7 +147,7 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
147
147
  <li class="public ">
148
148
  <span class="summary_signature">
149
149
 
150
- <a href="#optional-instance_method" title="#optional (instance method)">#<strong>optional</strong> &#x21d2; Object </a>
150
+ <a href="#attribute_name-instance_method" title="#attribute_name (instance method)">#<strong>attribute_name</strong> &#x21d2; Object </a>
151
151
 
152
152
 
153
153
 
@@ -171,23 +171,10 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
171
171
  </li>
172
172
 
173
173
 
174
- </ul>
175
-
176
-
177
-
178
-
179
-
180
- <h2>
181
- Instance Method Summary
182
- <small><a href="#" class="summary_toggle">collapse</a></small>
183
- </h2>
184
-
185
- <ul class="summary">
186
-
187
- <li class="public ">
174
+ <li class="public ">
188
175
  <span class="summary_signature">
189
176
 
190
- <a href="#anchor_class-instance_method" title="#anchor_class (instance method)">#<strong>anchor_class</strong> &#x21d2; Object </a>
177
+ <a href="#optional-instance_method" title="#optional (instance method)">#<strong>optional</strong> &#x21d2; Object </a>
191
178
 
192
179
 
193
180
 
@@ -195,22 +182,39 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
195
182
 
196
183
 
197
184
 
185
+
186
+ <span class="note title readonly">readonly</span>
187
+
188
+
189
+
198
190
 
199
191
 
200
192
 
201
193
 
202
194
 
203
195
 
204
- <span class="summary_desc"><div class='inline'><p>Getter for the Anchormodel class based on the name passed to the initializer.</p>
205
- </div></span>
196
+ <span class="summary_desc"><div class='inline'></div></span>
206
197
 
207
198
  </li>
208
199
 
200
+
201
+ </ul>
202
+
203
+
204
+
205
+
206
+
207
+ <h2>
208
+ Instance Method Summary
209
+ <small><a href="#" class="summary_toggle">collapse</a></small>
210
+ </h2>
211
+
212
+ <ul class="summary">
209
213
 
210
214
  <li class="public ">
211
215
  <span class="summary_signature">
212
216
 
213
- <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(model_class, attribute_name, anchor_class_name = nil, optional = false) &#x21d2; Attribute </a>
217
+ <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(model_class, attribute_name, anchormodel_class = nil, optional = false) &#x21d2; Attribute </a>
214
218
 
215
219
 
216
220
 
@@ -226,7 +230,8 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
226
230
 
227
231
 
228
232
 
229
- <span class="summary_desc"><div class='inline'><p>A new instance of Attribute.</p>
233
+ <span class="summary_desc"><div class='inline'>
234
+ <p>A new instance of Attribute.</p>
230
235
  </div></span>
231
236
 
232
237
  </li>
@@ -241,7 +246,7 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
241
246
  <div class="method_details first">
242
247
  <h3 class="signature first" id="initialize-instance_method">
243
248
 
244
- #<strong>initialize</strong>(model_class, attribute_name, anchor_class_name = nil, optional = false) &#x21d2; <tt><span class='object_link'><a href="" title="Anchormodel::Attribute (class)">Attribute</a></span></tt>
249
+ #<strong>initialize</strong>(model_class, attribute_name, anchormodel_class = nil, optional = false) &#x21d2; <tt><span class='object_link'><a href="" title="Anchormodel::Attribute (class)">Attribute</a></span></tt>
245
250
 
246
251
 
247
252
 
@@ -249,7 +254,8 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
249
254
 
250
255
  </h3><div class="docstring">
251
256
  <div class="discussion">
252
- <p>Returns a new instance of Attribute.</p>
257
+
258
+ <p>Returns a new instance of Attribute.</p>
253
259
 
254
260
 
255
261
  </div>
@@ -268,7 +274,8 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
268
274
 
269
275
 
270
276
  &mdash;
271
- <div class='inline'><p>The Rails model where ModelMixin#belongs_to_anchormodel is used</p>
277
+ <div class='inline'>
278
+ <p>The Rails model where ModelMixin#belongs_to_anchormodel is used</p>
272
279
  </div>
273
280
 
274
281
  </li>
@@ -283,24 +290,26 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
283
290
 
284
291
 
285
292
  &mdash;
286
- <div class='inline'><p>The name and database column of the attribute</p>
293
+ <div class='inline'>
294
+ <p>The name and database column of the attribute</p>
287
295
  </div>
288
296
 
289
297
  </li>
290
298
 
291
299
  <li>
292
300
 
293
- <span class='name'>anchor_class_name</span>
301
+ <span class='name'>anchormodel_class</span>
294
302
 
295
303
 
296
- <span class='type'>(<tt>String</tt>)</span>
304
+ <span class='type'>(<tt>Class</tt>)</span>
297
305
 
298
306
 
299
307
  <em class="default">(defaults to: <tt>nil</tt>)</em>
300
308
 
301
309
 
302
310
  &mdash;
303
- <div class='inline'><p>Name of the Anchormodel class (omit if attribute <code>:foo_bar</code> holds an <code>Anchormodels::FooBar</code>)</p>
311
+ <div class='inline'>
312
+ <p>Class of the Anchormodel (omit if attribute <code>:foo_bar</code> holds an <code>FooBar</code>)</p>
304
313
  </div>
305
314
 
306
315
  </li>
@@ -317,7 +326,8 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
317
326
 
318
327
 
319
328
  &mdash;
320
- <div class='inline'><p>If true, a presence validation is added to the model.</p>
329
+ <div class='inline'>
330
+ <p>If true, a presence validation is added to the model.</p>
321
331
  </div>
322
332
 
323
333
  </li>
@@ -331,20 +341,20 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
331
341
  <pre class="lines">
332
342
 
333
343
 
334
- 12
335
344
  13
336
345
  14
337
346
  15
338
347
  16
339
- 17</pre>
348
+ 17
349
+ 18</pre>
340
350
  </td>
341
351
  <td>
342
- <pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 12</span>
352
+ <pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 13</span>
343
353
 
344
- <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</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_anchor_class_name'>anchor_class_name</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_optional'>optional</span> <span class='op'>=</span> <span class='kw'>false</span><span class='rparen'>)</span>
354
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</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> <span class='id identifier rubyid_optional'>optional</span> <span class='op'>=</span> <span class='kw'>false</span><span class='rparen'>)</span>
345
355
  <span class='ivar'>@model_class</span> <span class='op'>=</span> <span class='id identifier rubyid_model_class'>model_class</span>
346
356
  <span class='ivar'>@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>
347
- <span class='ivar'>@anchor_class_name</span> <span class='op'>=</span> <span class='id identifier rubyid_anchor_class_name'>anchor_class_name</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Anchormodels::</span><span class='embexpr_beg'>#{</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='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
357
+ <span class='ivar'>@anchormodel_class</span> <span class='op'>=</span> <span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span>
348
358
  <span class='ivar'>@optional</span> <span class='op'>=</span> <span class='id identifier rubyid_optional'>optional</span>
349
359
  <span class='kw'>end</span></pre>
350
360
  </td>
@@ -360,9 +370,9 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
360
370
 
361
371
  <span id=""></span>
362
372
  <div class="method_details first">
363
- <h3 class="signature first" id="attribute_name-instance_method">
373
+ <h3 class="signature first" id="anchormodel_class-instance_method">
364
374
 
365
- #<strong>attribute_name</strong> &#x21d2; <tt>Object</tt> <span class="extras">(readonly)</span>
375
+ #<strong>anchormodel_class</strong> &#x21d2; <tt>Object</tt> <span class="extras">(readonly)</span>
366
376
 
367
377
 
368
378
 
@@ -383,15 +393,15 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
383
393
  <pre class="lines">
384
394
 
385
395
 
386
- 5
387
396
  6
388
- 7</pre>
397
+ 7
398
+ 8</pre>
389
399
  </td>
390
400
  <td>
391
- <pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 5</span>
401
+ <pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 6</span>
392
402
 
393
- <span class='kw'>def</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span>
394
- <span class='ivar'>@attribute_name</span>
403
+ <span class='kw'>def</span> <span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span>
404
+ <span class='ivar'>@anchormodel_class</span>
395
405
  <span class='kw'>end</span></pre>
396
406
  </td>
397
407
  </tr>
@@ -401,9 +411,9 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
401
411
 
402
412
  <span id=""></span>
403
413
  <div class="method_details ">
404
- <h3 class="signature " id="optional-instance_method">
414
+ <h3 class="signature " id="attribute_name-instance_method">
405
415
 
406
- #<strong>optional</strong> &#x21d2; <tt>Object</tt> <span class="extras">(readonly)</span>
416
+ #<strong>attribute_name</strong> &#x21d2; <tt>Object</tt> <span class="extras">(readonly)</span>
407
417
 
408
418
 
409
419
 
@@ -424,32 +434,27 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
424
434
  <pre class="lines">
425
435
 
426
436
 
437
+ 5
427
438
  6
428
- 7
429
- 8</pre>
439
+ 7</pre>
430
440
  </td>
431
441
  <td>
432
- <pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 6</span>
442
+ <pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 5</span>
433
443
 
434
- <span class='kw'>def</span> <span class='id identifier rubyid_optional'>optional</span>
435
- <span class='ivar'>@optional</span>
444
+ <span class='kw'>def</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span>
445
+ <span class='ivar'>@attribute_name</span>
436
446
  <span class='kw'>end</span></pre>
437
447
  </td>
438
448
  </tr>
439
449
  </table>
440
450
  </div>
441
451
 
442
- </div>
443
-
444
-
445
- <div id="instance_method_details" class="method_details_list">
446
- <h2>Instance Method Details</h2>
447
-
448
-
449
- <div class="method_details first">
450
- <h3 class="signature first" id="anchor_class-instance_method">
452
+
453
+ <span id=""></span>
454
+ <div class="method_details ">
455
+ <h3 class="signature " id="optional-instance_method">
451
456
 
452
- #<strong>anchor_class</strong> &#x21d2; <tt>Object</tt>
457
+ #<strong>optional</strong> &#x21d2; <tt>Object</tt> <span class="extras">(readonly)</span>
453
458
 
454
459
 
455
460
 
@@ -457,9 +462,7 @@ It is instanciated when ModelMixin#belongs_to_anchormodel is used.</p>
457
462
 
458
463
  </h3><div class="docstring">
459
464
  <div class="discussion">
460
- <p>Getter for the Anchormodel class based on the name passed to the initializer.
461
- We are loading the anchor class lazily, because the model mixin instanciates this statically -&gt; avoid premature anchor class loading</p>
462
-
465
+
463
466
 
464
467
  </div>
465
468
  </div>
@@ -472,15 +475,15 @@ We are loading the anchor class lazily, because the model mixin instanciates thi
472
475
  <pre class="lines">
473
476
 
474
477
 
475
- 21
476
- 22
477
- 23</pre>
478
+ 7
479
+ 8
480
+ 9</pre>
478
481
  </td>
479
482
  <td>
480
- <pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 21</span>
483
+ <pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 7</span>
481
484
 
482
- <span class='kw'>def</span> <span class='id identifier rubyid_anchor_class'>anchor_class</span>
483
- <span class='ivar'>@anchor_class</span> <span class='op'>||=</span> <span class='ivar'>@anchor_class_name</span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
485
+ <span class='kw'>def</span> <span class='id identifier rubyid_optional'>optional</span>
486
+ <span class='ivar'>@optional</span>
484
487
  <span class='kw'>end</span></pre>
485
488
  </td>
486
489
  </tr>
@@ -489,12 +492,13 @@ We are loading the anchor class lazily, because the model mixin instanciates thi
489
492
 
490
493
  </div>
491
494
 
495
+
492
496
  </div>
493
497
 
494
498
  <div id="footer">
495
- Generated on Sat Dec 17 12:56:00 2022 by
499
+ Generated on Tue Jan 24 20:27:59 2023 by
496
500
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
497
- 0.9.28 (ruby-3.0.4).
501
+ 0.9.28 (ruby-3.1.3).
498
502
  </div>
499
503
 
500
504
  </div>