anchormodel 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0879b0ba5bb815a7ac9c2f8f79767fe5fa4e8e16451398e721f90ad76f74c722'
4
- data.tar.gz: b8291cd902aec98f1e8e66960d3f5bb8b7087dcaedcd37e2779ec5bbf1168466
3
+ metadata.gz: 8dc8f056d1710a491d181aef71c5b576302d21baaf2f0075557f71e467e5f63a
4
+ data.tar.gz: 7b9d36723f5485c18de24450021e7a0822c9a479af99a556b58643fcd4375316
5
5
  SHA512:
6
- metadata.gz: ab29238cbfc8eb19660cd264882bbb8d2dd8a2990e8269bca937488319e893e8d7e0be602b15082acb3d87a4bd85e208831c1ef3a3761791e0c2f0cda782abe7
7
- data.tar.gz: e3c2dcd50fabbc3227c6dd6e35e98e26d8165815fd329b4b460641d825ad98b774f9392949ca8ed5654aeeebc6fea1103810eceb7172bd6839489de70e8adbc0
6
+ metadata.gz: 0d7f310e1e5ff0a4d310408a792c5794d8f6068a8a8b01f2a650270a3e46a1a3ff7c31a4ed403eb3588f4d378b959906a881f6c03105d5a1165059bfed3a0530
7
+ data.tar.gz: 60f5405f9b8f24e3477e4a37396c45409321da47826f252185f9c255bbbaa18e462243dbfc650ac113a61994a683d701689f9fb81d2bed2912d88242ab6d3136
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.2.5
2
+
3
+ - Fix an issue in combination with the active_type gem, causing virtual models to always read nil on anchormodel attributes
4
+ - When serializing an Anchormodel to json, return the key
5
+
6
+ # 0.2.4 (06.11.2024)
7
+
8
+ - Implement `YourConstant.first` as a shorthand for `YourConstant.all.first` to avoid Rubocop problems
9
+
1
10
  # 0.2.3 (01.11.2024)
2
11
 
3
12
  - Relax Rails dependency
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.5
data/anchormodel.gemspec CHANGED
@@ -2,21 +2,21 @@
2
2
  # This file is auto-generated via: 'rake gemspec'.
3
3
 
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: anchormodel 0.2.3 ruby lib
5
+ # stub: anchormodel 0.2.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "anchormodel".freeze
9
- s.version = "0.2.3".freeze
9
+ s.version = "0.2.5".freeze
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Sandro Kalbermatter".freeze]
14
- s.date = "2024-11-01"
14
+ s.date = "2025-02-14"
15
15
  s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "Gemfile.lock".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "anchormodel.gemspec".freeze, "bin/rails".freeze, "doc/Anchormodel.html".freeze, "doc/Anchormodel/ActiveModelTypeValue.html".freeze, "doc/Anchormodel/ActiveModelTypeValueMulti.html".freeze, "doc/Anchormodel/ActiveModelTypeValueSingle.html".freeze, "doc/Anchormodel/Attribute.html".freeze, "doc/Anchormodel/ModelMixin.html".freeze, "doc/Anchormodel/SimpleFormInputs.html".freeze, "doc/Anchormodel/SimpleFormInputs/Helpers.html".freeze, "doc/Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html".freeze, "doc/Anchormodel/Util.html".freeze, "doc/Anchormodel/Version.html".freeze, "doc/AnchormodelCheckBoxesInput.html".freeze, "doc/AnchormodelGenerator.html".freeze, "doc/AnchormodelInput.html".freeze, "doc/AnchormodelRadioButtonsInput.html".freeze, "doc/_index.html".freeze, "doc/class_list.html".freeze, "doc/css/common.css".freeze, "doc/css/full_list.css".freeze, "doc/css/style.css".freeze, "doc/file.README.html".freeze, "doc/file_list.html".freeze, "doc/frames.html".freeze, "doc/index.html".freeze, "doc/js/app.js".freeze, "doc/js/full_list.js".freeze, "doc/js/jquery.js".freeze, "doc/method_list.html".freeze, "doc/top-level-namespace.html".freeze, "lib/anchormodel.rb".freeze, "lib/anchormodel/active_model_type_value_multi.rb".freeze, "lib/anchormodel/active_model_type_value_single.rb".freeze, "lib/anchormodel/attribute.rb".freeze, "lib/anchormodel/model_mixin.rb".freeze, "lib/anchormodel/simple_form_inputs/anchormodel_check_boxes_input.rb".freeze, "lib/anchormodel/simple_form_inputs/anchormodel_input.rb".freeze, "lib/anchormodel/simple_form_inputs/anchormodel_radio_buttons_input.rb".freeze, "lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.rb".freeze, "lib/anchormodel/util.rb".freeze, "lib/anchormodel/version.rb".freeze, "lib/generators/anchormodel/USAGE".freeze, "lib/generators/anchormodel/anchormodel_generator.rb".freeze, "lib/generators/anchormodel/templates/anchormodel.rb.erb".freeze, "logo.svg".freeze, "test/active_record_model/user_test.rb".freeze, "test/dummy/.gitignore".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/anchormodels/animal.rb".freeze, "test/dummy/app/anchormodels/locale.rb".freeze, "test/dummy/app/anchormodels/role.rb".freeze, "test/dummy/app/helpers/application_helper.rb".freeze, "test/dummy/app/models/application_record.rb".freeze, "test/dummy/app/models/concerns/.keep".freeze, "test/dummy/app/models/user.rb".freeze, "test/dummy/bin/rails".freeze, "test/dummy/bin/rake".freeze, "test/dummy/bin/setup".freeze, "test/dummy/config.ru".freeze, "test/dummy/config/application.rb".freeze, "test/dummy/config/boot.rb".freeze, "test/dummy/config/credentials.yml.enc".freeze, "test/dummy/config/database.yml".freeze, "test/dummy/config/environment.rb".freeze, "test/dummy/config/environments/test.rb".freeze, "test/dummy/config/initializers/content_security_policy.rb".freeze, "test/dummy/config/initializers/filter_parameter_logging.rb".freeze, "test/dummy/config/initializers/inflections.rb".freeze, "test/dummy/config/initializers/permissions_policy.rb".freeze, "test/dummy/config/locales/en.yml".freeze, "test/dummy/config/puma.rb".freeze, "test/dummy/config/routes.rb".freeze, "test/dummy/db/migrate/20230107173151_create_users.rb".freeze, "test/dummy/db/migrate/20240425182000_add_animals_to_users.rb".freeze, "test/dummy/db/schema.rb".freeze, "test/dummy/db/seeds.rb".freeze, "test/dummy/lib/tasks/.keep".freeze, "test/dummy/log/.keep".freeze, "test/dummy/tmp/.keep".freeze, "test/dummy/tmp/pids/.keep".freeze, "test/test_helper.rb".freeze]
16
16
  s.homepage = "https://github.com/kalsan/anchormodel".freeze
17
17
  s.licenses = ["LGPL-3.0-or-later".freeze]
18
18
  s.required_ruby_version = Gem::Requirement.new(">= 3.0.0".freeze)
19
- s.rubygems_version = "3.5.22".freeze
19
+ s.rubygems_version = "3.6.3".freeze
20
20
  s.summary = "Bringing object-oriented programming to Rails enums".freeze
21
21
 
22
22
  s.specification_version = 4
@@ -400,7 +400,7 @@
400
400
  </div>
401
401
 
402
402
  <div id="footer">
403
- Generated on Fri Nov 1 12:02:06 2024 by
403
+ Generated on Fri Feb 14 13:25:30 2025 by
404
404
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
405
405
  0.9.37 (ruby-3.3.5).
406
406
  </div>
@@ -687,7 +687,7 @@
687
687
  </div>
688
688
 
689
689
  <div id="footer">
690
- Generated on Fri Nov 1 12:02:06 2024 by
690
+ Generated on Fri Feb 14 13:25:30 2025 by
691
691
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
692
692
  0.9.37 (ruby-3.3.5).
693
693
  </div>
@@ -596,7 +596,7 @@
596
596
  </div>
597
597
 
598
598
  <div id="footer">
599
- Generated on Fri Nov 1 12:02:06 2024 by
599
+ Generated on Fri Feb 14 13:25:30 2025 by
600
600
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
601
601
  0.9.37 (ruby-3.3.5).
602
602
  </div>
@@ -273,7 +273,7 @@
273
273
  </div>
274
274
 
275
275
  <div id="footer">
276
- Generated on Fri Nov 1 12:02:06 2024 by
276
+ Generated on Fri Feb 14 13:25:30 2025 by
277
277
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
278
278
  0.9.37 (ruby-3.3.5).
279
279
  </div>
@@ -269,7 +269,7 @@ Affected object: </span><span class='embexpr_beg'>#{</span><span class='id ident
269
269
  </div>
270
270
 
271
271
  <div id="footer">
272
- Generated on Fri Nov 1 12:02:06 2024 by
272
+ Generated on Fri Feb 14 13:25:30 2025 by
273
273
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
274
274
  0.9.37 (ruby-3.3.5).
275
275
  </div>
@@ -114,7 +114,7 @@
114
114
  </div>
115
115
 
116
116
  <div id="footer">
117
- Generated on Fri Nov 1 12:02:06 2024 by
117
+ Generated on Fri Feb 14 13:25:30 2025 by
118
118
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
119
119
  0.9.37 (ruby-3.3.5).
120
120
  </div>
@@ -114,7 +114,7 @@
114
114
  </div>
115
115
 
116
116
  <div id="footer">
117
- Generated on Fri Nov 1 12:02:06 2024 by
117
+ Generated on Fri Feb 14 13:25:30 2025 by
118
118
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
119
119
  0.9.37 (ruby-3.3.5).
120
120
  </div>
@@ -458,7 +458,13 @@
458
458
  139
459
459
  140
460
460
  141
461
- 142</pre>
461
+ 142
462
+ 143
463
+ 144
464
+ 145
465
+ 146
466
+ 147
467
+ 148</pre>
462
468
  </td>
463
469
  <td>
464
470
  <pre class="code"><span class="info file"># File 'lib/anchormodel/util.rb', line 14</span>
@@ -497,7 +503,13 @@
497
503
 
498
504
  <span class='comment'># Overwrite reader to force building anchors at every retrieval
499
505
  </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>
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>
506
+ <span class='comment'># This patch fixes an issue in combination with the active_type gem, causing virtual models to always read nil on anchormodel attributes.
507
+ </span> <span class='id identifier rubyid_raw_data'>raw_data</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='kw'>defined?</span><span class='lparen'>(</span><span class='const'>ActiveType</span><span class='op'>::</span><span class='const'>Object</span><span class='rparen'>)</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>ActiveType</span><span class='op'>::</span><span class='const'>Object</span><span class='rparen'>)</span>
508
+ <span class='id identifier rubyid_virtual_attributes'>virtual_attributes</span><span class='lbracket'>[</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='rbracket'>]</span>
509
+ <span class='kw'>else</span>
510
+ <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>
511
+ <span class='kw'>end</span>
512
+ <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_raw_data'>raw_data</span><span class='rparen'>)</span>
501
513
 
502
514
  <span class='comment'># If this attribute holds multiple anchormodels (`belongs_to_anchormodels`), patch the Array before returning in order to implement collection modifiers:
503
515
  </span> <span class='kw'>if</span> <span class='id identifier rubyid_multiple'>multiple</span>
@@ -602,7 +614,7 @@
602
614
  </div>
603
615
 
604
616
  <div id="footer">
605
- Generated on Fri Nov 1 12:02:06 2024 by
617
+ Generated on Fri Feb 14 13:25:30 2025 by
606
618
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
607
619
  0.9.37 (ruby-3.3.5).
608
620
  </div>
@@ -129,7 +129,7 @@
129
129
  </div>
130
130
 
131
131
  <div id="footer">
132
- Generated on Fri Nov 1 12:02:06 2024 by
132
+ Generated on Fri Feb 14 13:25:30 2025 by
133
133
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
134
134
  0.9.37 (ruby-3.3.5).
135
135
  </div>
data/doc/Anchormodel.html CHANGED
@@ -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="#first-class_method" title="first (class method)">.<strong>first</strong> &#x21d2; 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>Shorthand to satisfy rubocop.</p>
268
+ </div></span>
269
+
246
270
  </li>
247
271
 
248
272
 
@@ -320,6 +344,28 @@
320
344
 
321
345
 
322
346
 
347
+ <span class="summary_desc"><div class='inline'></div></span>
348
+
349
+ </li>
350
+
351
+
352
+ <li class="public ">
353
+ <span class="summary_signature">
354
+
355
+ <a href="#as_json-instance_method" title="#as_json (instance method)">#<strong>as_json</strong> &#x21d2; Object </a>
356
+
357
+
358
+
359
+ </span>
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
323
369
  <span class="summary_desc"><div class='inline'></div></span>
324
370
 
325
371
  </li>
@@ -487,11 +533,6 @@
487
533
  <pre class="lines">
488
534
 
489
535
 
490
- 43
491
- 44
492
- 45
493
- 46
494
- 47
495
536
  48
496
537
  49
497
538
  50
@@ -509,10 +550,15 @@
509
550
  62
510
551
  63
511
552
  64
512
- 65</pre>
553
+ 65
554
+ 66
555
+ 67
556
+ 68
557
+ 69
558
+ 70</pre>
513
559
  </td>
514
560
  <td>
515
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 43</span>
561
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 48</span>
516
562
 
517
563
  <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>
518
564
  <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>
@@ -723,13 +769,13 @@
723
769
  <pre class="lines">
724
770
 
725
771
 
726
- 35
727
- 36
728
- 37
729
- 38</pre>
772
+ 40
773
+ 41
774
+ 42
775
+ 43</pre>
730
776
  </td>
731
777
  <td>
732
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 35</span>
778
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 40</span>
733
779
 
734
780
  <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>
735
781
  <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>
@@ -741,9 +787,9 @@
741
787
  </div>
742
788
 
743
789
  <div class="method_details ">
744
- <h3 class="signature " id="form_collection-class_method">
790
+ <h3 class="signature " id="first-class_method">
745
791
 
746
- .<strong>form_collection</strong> &#x21d2; <tt>Object</tt>
792
+ .<strong>first</strong> &#x21d2; <tt>Object</tt>
747
793
 
748
794
 
749
795
 
@@ -752,7 +798,7 @@
752
798
  </h3><div class="docstring">
753
799
  <div class="discussion">
754
800
 
755
- <p>Returns an array of tuples [label, key] suitable for passing as a collection to some form input helpers</p>
801
+ <p>Shorthand to satisfy rubocop</p>
756
802
 
757
803
 
758
804
  </div>
@@ -773,6 +819,47 @@
773
819
  <td>
774
820
  <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 29</span>
775
821
 
822
+ <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
823
+ <span class='id identifier rubyid_all'>all</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
824
+ <span class='kw'>end</span></pre>
825
+ </td>
826
+ </tr>
827
+ </table>
828
+ </div>
829
+
830
+ <div class="method_details ">
831
+ <h3 class="signature " id="form_collection-class_method">
832
+
833
+ .<strong>form_collection</strong> &#x21d2; <tt>Object</tt>
834
+
835
+
836
+
837
+
838
+
839
+ </h3><div class="docstring">
840
+ <div class="discussion">
841
+
842
+ <p>Returns an array of tuples [label, key] suitable for passing as a collection to some form input helpers</p>
843
+
844
+
845
+ </div>
846
+ </div>
847
+ <div class="tags">
848
+
849
+
850
+ </div><table class="source_code">
851
+ <tr>
852
+ <td>
853
+ <pre class="lines">
854
+
855
+
856
+ 34
857
+ 35
858
+ 36</pre>
859
+ </td>
860
+ <td>
861
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 34</span>
862
+
776
863
  <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
864
  <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
865
  <span class='kw'>end</span></pre>
@@ -860,12 +947,12 @@
860
947
  <pre class="lines">
861
948
 
862
949
 
863
- 67
864
- 68
865
- 69</pre>
950
+ 72
951
+ 73
952
+ 74</pre>
866
953
  </td>
867
954
  <td>
868
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 67</span>
955
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 72</span>
869
956
 
870
957
  <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>
871
958
  <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>
@@ -873,6 +960,45 @@
873
960
  </td>
874
961
  </tr>
875
962
  </table>
963
+ </div>
964
+
965
+ <div class="method_details ">
966
+ <h3 class="signature " id="as_json-instance_method">
967
+
968
+ #<strong>as_json</strong> &#x21d2; <tt>Object</tt>
969
+
970
+
971
+
972
+
973
+
974
+ </h3><div class="docstring">
975
+ <div class="discussion">
976
+
977
+
978
+ </div>
979
+ </div>
980
+ <div class="tags">
981
+
982
+
983
+ </div><table class="source_code">
984
+ <tr>
985
+ <td>
986
+ <pre class="lines">
987
+
988
+
989
+ 89
990
+ 90
991
+ 91</pre>
992
+ </td>
993
+ <td>
994
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 89</span>
995
+
996
+ <span class='kw'>def</span> <span class='id identifier rubyid_as_json'>as_json</span>
997
+ <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
998
+ <span class='kw'>end</span></pre>
999
+ </td>
1000
+ </tr>
1001
+ </table>
876
1002
  </div>
877
1003
 
878
1004
  <div class="method_details ">
@@ -899,12 +1025,12 @@
899
1025
  <pre class="lines">
900
1026
 
901
1027
 
902
- 76
903
- 77
904
- 78</pre>
1028
+ 81
1029
+ 82
1030
+ 83</pre>
905
1031
  </td>
906
1032
  <td>
907
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 76</span>
1033
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 81</span>
908
1034
 
909
1035
  <span class='kw'>def</span> <span class='id identifier rubyid_inspect'>inspect</span>
910
1036
  <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>
@@ -940,12 +1066,12 @@
940
1066
  <pre class="lines">
941
1067
 
942
1068
 
943
- 72
944
- 73
945
- 74</pre>
1069
+ 77
1070
+ 78
1071
+ 79</pre>
946
1072
  </td>
947
1073
  <td>
948
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 72</span>
1074
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 77</span>
949
1075
 
950
1076
  <span class='kw'>def</span> <span class='id identifier rubyid_label'>label</span>
951
1077
  <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>
@@ -979,12 +1105,12 @@
979
1105
  <pre class="lines">
980
1106
 
981
1107
 
982
- 80
983
- 81
984
- 82</pre>
1108
+ 85
1109
+ 86
1110
+ 87</pre>
985
1111
  </td>
986
1112
  <td>
987
- <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 80</span>
1113
+ <pre class="code"><span class="info file"># File 'lib/anchormodel.rb', line 85</span>
988
1114
 
989
1115
  <span class='kw'>def</span> <span class='id identifier rubyid_to_s'>to_s</span>
990
1116
  <span class='id identifier rubyid_inspect'>inspect</span>
@@ -999,7 +1125,7 @@
999
1125
  </div>
1000
1126
 
1001
1127
  <div id="footer">
1002
- Generated on Fri Nov 1 12:02:06 2024 by
1128
+ Generated on Fri Feb 14 13:25:30 2025 by
1003
1129
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1004
1130
  0.9.37 (ruby-3.3.5).
1005
1131
  </div>
@@ -130,7 +130,7 @@
130
130
  </div>
131
131
 
132
132
  <div id="footer">
133
- Generated on Fri Nov 1 12:02:06 2024 by
133
+ Generated on Fri Feb 14 13:25:30 2025 by
134
134
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
135
135
  0.9.37 (ruby-3.3.5).
136
136
  </div>
@@ -191,7 +191,7 @@
191
191
  </div>
192
192
 
193
193
  <div id="footer">
194
- Generated on Fri Nov 1 12:02:06 2024 by
194
+ Generated on Fri Feb 14 13:25:30 2025 by
195
195
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
196
196
  0.9.37 (ruby-3.3.5).
197
197
  </div>
@@ -130,7 +130,7 @@
130
130
  </div>
131
131
 
132
132
  <div id="footer">
133
- Generated on Fri Nov 1 12:02:06 2024 by
133
+ Generated on Fri Feb 14 13:25:30 2025 by
134
134
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
135
135
  0.9.37 (ruby-3.3.5).
136
136
  </div>
@@ -130,7 +130,7 @@
130
130
  </div>
131
131
 
132
132
  <div id="footer">
133
- Generated on Fri Nov 1 12:02:06 2024 by
133
+ Generated on Fri Feb 14 13:25:30 2025 by
134
134
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
135
135
  0.9.37 (ruby-3.3.5).
136
136
  </div>
data/doc/_index.html CHANGED
@@ -220,7 +220,7 @@
220
220
  </div>
221
221
 
222
222
  <div id="footer">
223
- Generated on Fri Nov 1 12:02:06 2024 by
223
+ Generated on Fri Feb 14 13:25:30 2025 by
224
224
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
225
225
  0.9.37 (ruby-3.3.5).
226
226
  </div>
data/doc/file.README.html CHANGED
@@ -339,7 +339,7 @@
339
339
  </div></div>
340
340
 
341
341
  <div id="footer">
342
- Generated on Fri Nov 1 12:02:06 2024 by
342
+ Generated on Fri Feb 14 13:25:30 2025 by
343
343
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
344
344
  0.9.37 (ruby-3.3.5).
345
345
  </div>
data/doc/index.html CHANGED
@@ -339,7 +339,7 @@
339
339
  </div></div>
340
340
 
341
341
  <div id="footer">
342
- Generated on Fri Nov 1 12:02:06 2024 by
342
+ Generated on Fri Feb 14 13:25:30 2025 by
343
343
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
344
344
  0.9.37 (ruby-3.3.5).
345
345
  </div>
data/doc/method_list.html CHANGED
@@ -80,6 +80,14 @@
80
80
 
81
81
 
82
82
  <li class="odd ">
83
+ <div class="item">
84
+ <span class='object_link'><a href="Anchormodel.html#as_json-instance_method" title="Anchormodel#as_json (method)">#as_json</a></span>
85
+ <small>Anchormodel</small>
86
+ </div>
87
+ </li>
88
+
89
+
90
+ <li class="even ">
83
91
  <div class="item">
84
92
  <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html#attribute-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#attribute (method)">#attribute</a></span>
85
93
  <small>Anchormodel::ActiveModelTypeValueSingle</small>
@@ -87,7 +95,7 @@
87
95
  </li>
88
96
 
89
97
 
90
- <li class="even ">
98
+ <li class="odd ">
91
99
  <div class="item">
92
100
  <span class='object_link'><a href="Anchormodel/Attribute.html#attribute_name-instance_method" title="Anchormodel::Attribute#attribute_name (method)">#attribute_name</a></span>
93
101
  <small>Anchormodel::Attribute</small>
@@ -95,7 +103,7 @@
95
103
  </li>
96
104
 
97
105
 
98
- <li class="odd ">
106
+ <li class="even ">
99
107
  <div class="item">
100
108
  <span class='object_link'><a href="Anchormodel/ModelMixin.html#belongs_to_anchormodel-class_method" title="Anchormodel::ModelMixin.belongs_to_anchormodel (method)">belongs_to_anchormodel</a></span>
101
109
  <small>Anchormodel::ModelMixin</small>
@@ -103,7 +111,7 @@
103
111
  </li>
104
112
 
105
113
 
106
- <li class="even ">
114
+ <li class="odd ">
107
115
  <div class="item">
108
116
  <span class='object_link'><a href="Anchormodel/ModelMixin.html#belongs_to_anchormodels-class_method" title="Anchormodel::ModelMixin.belongs_to_anchormodels (method)">belongs_to_anchormodels</a></span>
109
117
  <small>Anchormodel::ModelMixin</small>
@@ -111,7 +119,7 @@
111
119
  </li>
112
120
 
113
121
 
114
- <li class="odd ">
122
+ <li class="even ">
115
123
  <div class="item">
116
124
  <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueMulti.html#cast-instance_method" title="Anchormodel::ActiveModelTypeValueMulti#cast (method)">#cast</a></span>
117
125
  <small>Anchormodel::ActiveModelTypeValueMulti</small>
@@ -119,7 +127,7 @@
119
127
  </li>
120
128
 
121
129
 
122
- <li class="even ">
130
+ <li class="odd ">
123
131
  <div class="item">
124
132
  <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html#cast-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#cast (method)">#cast</a></span>
125
133
  <small>Anchormodel::ActiveModelTypeValueSingle</small>
@@ -127,7 +135,7 @@
127
135
  </li>
128
136
 
129
137
 
130
- <li class="odd ">
138
+ <li class="even ">
131
139
  <div class="item">
132
140
  <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html#changed_in_place%3F-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#changed_in_place? (method)">#changed_in_place?</a></span>
133
141
  <small>Anchormodel::ActiveModelTypeValueSingle</small>
@@ -135,7 +143,7 @@
135
143
  </li>
136
144
 
137
145
 
138
- <li class="even ">
146
+ <li class="odd ">
139
147
  <div class="item">
140
148
  <span class='object_link'><a href="Anchormodel.html#find-class_method" title="Anchormodel.find (method)">find</a></span>
141
149
  <small>Anchormodel</small>
@@ -143,6 +151,14 @@
143
151
  </li>
144
152
 
145
153
 
154
+ <li class="even ">
155
+ <div class="item">
156
+ <span class='object_link'><a href="Anchormodel.html#first-class_method" title="Anchormodel.first (method)">first</a></span>
157
+ <small>Anchormodel</small>
158
+ </div>
159
+ </li>
160
+
161
+
146
162
  <li class="odd ">
147
163
  <div class="item">
148
164
  <span class='object_link'><a href="Anchormodel.html#form_collection-class_method" title="Anchormodel.form_collection (method)">form_collection</a></span>
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Fri Nov 1 12:02:06 2024 by
103
+ Generated on Fri Feb 14 13:25:30 2025 by
104
104
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.37 (ruby-3.3.5).
106
106
  </div>
@@ -45,7 +45,13 @@ module Anchormodel::Util
45
45
 
46
46
  # Overwrite reader to force building anchors at every retrieval
47
47
  model_class.define_method(attribute_name.to_s) do
48
- result = active_model_type_value.deserialize(read_attribute_before_type_cast(attribute_name))
48
+ # This patch fixes an issue in combination with the active_type gem, causing virtual models to always read nil on anchormodel attributes.
49
+ raw_data = if defined?(ActiveType::Object) && is_a?(ActiveType::Object)
50
+ virtual_attributes[attribute_name.to_s]
51
+ else
52
+ read_attribute_before_type_cast(attribute_name)
53
+ end
54
+ result = active_model_type_value.deserialize(raw_data)
49
55
 
50
56
  # If this attribute holds multiple anchormodels (`belongs_to_anchormodels`), patch the Array before returning in order to implement collection modifiers:
51
57
  if multiple
data/lib/anchormodel.rb CHANGED
@@ -25,6 +25,11 @@ class Anchormodel
25
25
  entries_list
26
26
  end
27
27
 
28
+ # Shorthand to satisfy rubocop
29
+ def self.first
30
+ all.first
31
+ end
32
+
28
33
  # Returns an array of tuples [label, key] suitable for passing as a collection to some form input helpers
29
34
  def self.form_collection
30
35
  entries_list.map { |el| [el.label, el.key.to_s] }
@@ -80,6 +85,10 @@ class Anchormodel
80
85
  def to_s
81
86
  inspect
82
87
  end
88
+
89
+ def as_json
90
+ key.to_s
91
+ end
83
92
  end
84
93
 
85
94
  require 'anchormodel/util'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anchormodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Kalbermatter
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-01 00:00:00.000000000 Z
10
+ date: 2025-02-14 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -150,8 +149,6 @@ dependencies:
150
149
  - - "~>"
151
150
  - !ruby/object:Gem::Version
152
151
  version: 1.6.0
153
- description:
154
- email:
155
152
  executables: []
156
153
  extensions: []
157
154
  extra_rdoc_files: []
@@ -252,7 +249,6 @@ homepage: https://github.com/kalsan/anchormodel
252
249
  licenses:
253
250
  - LGPL-3.0-or-later
254
251
  metadata: {}
255
- post_install_message:
256
252
  rdoc_options: []
257
253
  require_paths:
258
254
  - lib
@@ -267,8 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
263
  - !ruby/object:Gem::Version
268
264
  version: '0'
269
265
  requirements: []
270
- rubygems_version: 3.4.10
271
- signing_key:
266
+ rubygems_version: 3.6.3
272
267
  specification_version: 4
273
268
  summary: Bringing object-oriented programming to Rails enums
274
269
  test_files: []