anchormodel 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +78 -2
  5. data/VERSION +1 -1
  6. data/anchormodel.gemspec +4 -4
  7. data/doc/Anchormodel/ActiveModelTypeValueSingle.html +113 -31
  8. data/doc/Anchormodel/Attribute.html +109 -9
  9. data/doc/Anchormodel/ModelMixin.html +75 -3
  10. data/doc/Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html +269 -0
  11. data/doc/Anchormodel/SimpleFormInputs/Helpers.html +124 -0
  12. data/doc/Anchormodel/SimpleFormInputs.html +124 -0
  13. data/doc/Anchormodel/Util.html +131 -15
  14. data/doc/Anchormodel/Version.html +3 -3
  15. data/doc/Anchormodel.html +97 -32
  16. data/doc/AnchormodelGenerator.html +3 -3
  17. data/doc/AnchormodelInput.html +140 -0
  18. data/doc/AnchormodelRadioButtonsInput.html +140 -0
  19. data/doc/_index.html +16 -4
  20. data/doc/class_list.html +1 -1
  21. data/doc/file.README.html +77 -5
  22. data/doc/frames.html +1 -1
  23. data/doc/index.html +77 -5
  24. data/doc/method_list.html +62 -6
  25. data/doc/top-level-namespace.html +4 -4
  26. data/lib/anchormodel/active_model_type_value_multi.rb +31 -0
  27. data/lib/anchormodel/active_model_type_value_single.rb +4 -2
  28. data/lib/anchormodel/attribute.rb +7 -1
  29. data/lib/anchormodel/model_mixin.rb +7 -0
  30. data/lib/anchormodel/simple_form_inputs/anchormodel_check_boxes_input.rb +23 -0
  31. data/lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.rb +8 -3
  32. data/lib/anchormodel/util.rb +57 -7
  33. data/lib/anchormodel.rb +7 -0
  34. data/test/active_record_model/user_test.rb +73 -9
  35. data/test/dummy/app/anchormodels/animal.rb +6 -0
  36. data/test/dummy/app/models/user.rb +1 -0
  37. data/test/dummy/db/migrate/20240425182000_add_animals_to_users.rb +5 -0
  38. data/test/dummy/db/schema.rb +2 -1
  39. metadata +11 -2
@@ -0,0 +1,140 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Class: AnchormodelInput
8
+
9
+ &mdash; Documentation by YARD 0.9.34
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "AnchormodelInput";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index (A)</a> &raquo;
40
+
41
+
42
+ <span class="title">AnchormodelInput</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Class: AnchormodelInput
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName">SimpleForm::Inputs::CollectionSelectInput</span>
73
+
74
+ <ul class="fullTree">
75
+ <li>Object</li>
76
+
77
+ <li class="next">SimpleForm::Inputs::CollectionSelectInput</li>
78
+
79
+ <li class="next">AnchormodelInput</li>
80
+
81
+ </ul>
82
+ <a href="#" class="inheritanceTree">show all</a>
83
+
84
+ </dd>
85
+ </dl>
86
+
87
+
88
+
89
+
90
+
91
+
92
+ <dl>
93
+ <dt>Includes:</dt>
94
+ <dd><span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon (module)">Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon</a></span></dd>
95
+ </dl>
96
+
97
+
98
+
99
+
100
+
101
+
102
+ <dl>
103
+ <dt>Defined in:</dt>
104
+ <dd>lib/anchormodel/simple_form_inputs/anchormodel_input.rb</dd>
105
+ </dl>
106
+
107
+ </div>
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+ <h2>Method Summary</h2>
124
+
125
+ <h3 class="inherited">Methods included from <span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon (module)">Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon</a></span></h3>
126
+ <p class="inherited"><span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html#input-instance_method" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon#input (method)">#input</a></span></p>
127
+
128
+
129
+
130
+ </div>
131
+
132
+ <div id="footer">
133
+ Generated on Sat Apr 27 10:18:33 2024 by
134
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
135
+ 0.9.34 (ruby-3.2.2).
136
+ </div>
137
+
138
+ </div>
139
+ </body>
140
+ </html>
@@ -0,0 +1,140 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Class: AnchormodelRadioButtonsInput
8
+
9
+ &mdash; Documentation by YARD 0.9.34
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "AnchormodelRadioButtonsInput";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index (A)</a> &raquo;
40
+
41
+
42
+ <span class="title">AnchormodelRadioButtonsInput</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Class: AnchormodelRadioButtonsInput
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName">SimpleForm::Inputs::CollectionRadioButtonsInput</span>
73
+
74
+ <ul class="fullTree">
75
+ <li>Object</li>
76
+
77
+ <li class="next">SimpleForm::Inputs::CollectionRadioButtonsInput</li>
78
+
79
+ <li class="next">AnchormodelRadioButtonsInput</li>
80
+
81
+ </ul>
82
+ <a href="#" class="inheritanceTree">show all</a>
83
+
84
+ </dd>
85
+ </dl>
86
+
87
+
88
+
89
+
90
+
91
+
92
+ <dl>
93
+ <dt>Includes:</dt>
94
+ <dd><span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon (module)">Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon</a></span></dd>
95
+ </dl>
96
+
97
+
98
+
99
+
100
+
101
+
102
+ <dl>
103
+ <dt>Defined in:</dt>
104
+ <dd>lib/anchormodel/simple_form_inputs/anchormodel_radio_buttons_input.rb</dd>
105
+ </dl>
106
+
107
+ </div>
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+ <h2>Method Summary</h2>
124
+
125
+ <h3 class="inherited">Methods included from <span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon (module)">Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon</a></span></h3>
126
+ <p class="inherited"><span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html#input-instance_method" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon#input (method)">#input</a></span></p>
127
+
128
+
129
+
130
+ </div>
131
+
132
+ <div id="footer">
133
+ Generated on Sat Apr 27 10:18:33 2024 by
134
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
135
+ 0.9.34 (ruby-3.2.2).
136
+ </div>
137
+
138
+ </div>
139
+ </body>
140
+ </html>
data/doc/_index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>
7
- Documentation by YARD 0.9.28
7
+ Documentation by YARD 0.9.34
8
8
 
9
9
  </title>
10
10
 
@@ -52,7 +52,7 @@
52
52
  <div class="clear"></div>
53
53
  </div>
54
54
 
55
- <div id="content"><h1 class="noborder title">Documentation by YARD 0.9.28</h1>
55
+ <div id="content"><h1 class="noborder title">Documentation by YARD 0.9.34</h1>
56
56
  <div id="listing">
57
57
  <h1 class="alphaindex">Alphabetic Index</h1>
58
58
 
@@ -80,6 +80,13 @@
80
80
  <li class="letter">A</li>
81
81
  <ul>
82
82
 
83
+ <li>
84
+ <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueMulti.html" title="Anchormodel::ActiveModelTypeValueMulti (class)">ActiveModelTypeValueMulti</a></span>
85
+
86
+ <small>(Anchormodel)</small>
87
+
88
+ </li>
89
+
83
90
  <li>
84
91
  <span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span>
85
92
 
@@ -92,6 +99,11 @@
92
99
 
93
100
  </li>
94
101
 
102
+ <li>
103
+ <span class='object_link'><a href="AnchormodelCheckBoxesInput.html" title="AnchormodelCheckBoxesInput (class)">AnchormodelCheckBoxesInput</a></span>
104
+
105
+ </li>
106
+
95
107
  <li>
96
108
  <span class='object_link'><a href="AnchormodelGenerator.html" title="AnchormodelGenerator (class)">AnchormodelGenerator</a></span>
97
109
 
@@ -208,9 +220,9 @@
208
220
  </div>
209
221
 
210
222
  <div id="footer">
211
- Generated on Wed Apr 24 17:01:45 2024 by
223
+ Generated on Sat Apr 27 10:18:32 2024 by
212
224
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
213
- 0.9.28 (ruby-3.2.2).
225
+ 0.9.34 (ruby-3.2.2).
214
226
  </div>
215
227
 
216
228
  </div>
data/doc/class_list.html CHANGED
@@ -43,7 +43,7 @@
43
43
 
44
44
  <ul id="full_list" class="class">
45
45
  <li id="object_" class="odd"><div class="item" style="padding-left:30px"><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></div></li>
46
- <li id='object_Anchormodel' class='even'><div class='item' style='padding-left:30px'><a class='toggle'></a> <span class='object_link'><a href="Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span> &lt; Object<small class='search_info'>Top Level Namespace</small></div><ul><li id='object_Anchormodel::ActiveModelTypeValueSingle' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span> &lt; Value<small class='search_info'>Anchormodel</small></div></li><li id='object_Anchormodel::Attribute' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/Attribute.html" title="Anchormodel::Attribute (class)">Attribute</a></span> &lt; Object<small class='search_info'>Anchormodel</small></div></li><li id='object_Anchormodel::ModelMixin' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/ModelMixin.html" title="Anchormodel::ModelMixin (module)">ModelMixin</a></span><small class='search_info'>Anchormodel</small></div></li><li id='object_Anchormodel::SimpleFormInputs' class='collapsed even'><div class='item' style='padding-left:45px'><a class='toggle'></a> <span class='object_link'><a href="Anchormodel/SimpleFormInputs.html" title="Anchormodel::SimpleFormInputs (module)">SimpleFormInputs</a></span><small class='search_info'>Anchormodel</small></div><ul><li id='object_Anchormodel::SimpleFormInputs::Helpers' class='collapsed'><div class='item' style='padding-left:60px'><a class='toggle'></a> <span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers.html" title="Anchormodel::SimpleFormInputs::Helpers (module)">Helpers</a></span><small class='search_info'>Anchormodel::SimpleFormInputs</small></div><ul><li id='object_Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon' class='collapsed'><div class='item' style='padding-left:75px'><span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon (module)">AnchormodelInputsCommon</a></span><small class='search_info'>Anchormodel::SimpleFormInputs::Helpers</small></div></li></ul></li></ul></li><li id='object_Anchormodel::Util' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/Util.html" title="Anchormodel::Util (module)">Util</a></span><small class='search_info'>Anchormodel</small></div></li><li id='object_Anchormodel::Version' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/Version.html" title="Anchormodel::Version (module)">Version</a></span><small class='search_info'>Anchormodel</small></div></li></ul></li><li id='object_AnchormodelGenerator' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="AnchormodelGenerator.html" title="AnchormodelGenerator (class)">AnchormodelGenerator</a></span> &lt; NamedBase<small class='search_info'>Top Level Namespace</small></div></li><li id='object_AnchormodelInput' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="AnchormodelInput.html" title="AnchormodelInput (class)">AnchormodelInput</a></span> &lt; CollectionSelectInput<small class='search_info'>Top Level Namespace</small></div></li><li id='object_AnchormodelRadioButtonsInput' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="AnchormodelRadioButtonsInput.html" title="AnchormodelRadioButtonsInput (class)">AnchormodelRadioButtonsInput</a></span> &lt; CollectionRadioButtonsInput<small class='search_info'>Top Level Namespace</small></div></li>
46
+ <li id='object_Anchormodel' class='even'><div class='item' style='padding-left:30px'><a class='toggle'></a> <span class='object_link'><a href="Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span> &lt; Object<small class='search_info'>Top Level Namespace</small></div><ul><li id='object_Anchormodel::ActiveModelTypeValueMulti' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/ActiveModelTypeValueMulti.html" title="Anchormodel::ActiveModelTypeValueMulti (class)">ActiveModelTypeValueMulti</a></span> &lt; ActiveModelTypeValueSingle<small class='search_info'>Anchormodel</small></div></li><li id='object_Anchormodel::ActiveModelTypeValueSingle' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span> &lt; Value<small class='search_info'>Anchormodel</small></div></li><li id='object_Anchormodel::Attribute' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/Attribute.html" title="Anchormodel::Attribute (class)">Attribute</a></span> &lt; Object<small class='search_info'>Anchormodel</small></div></li><li id='object_Anchormodel::ModelMixin' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/ModelMixin.html" title="Anchormodel::ModelMixin (module)">ModelMixin</a></span><small class='search_info'>Anchormodel</small></div></li><li id='object_Anchormodel::SimpleFormInputs' class='collapsed odd'><div class='item' style='padding-left:45px'><a class='toggle'></a> <span class='object_link'><a href="Anchormodel/SimpleFormInputs.html" title="Anchormodel::SimpleFormInputs (module)">SimpleFormInputs</a></span><small class='search_info'>Anchormodel</small></div><ul><li id='object_Anchormodel::SimpleFormInputs::Helpers' class='collapsed'><div class='item' style='padding-left:60px'><a class='toggle'></a> <span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers.html" title="Anchormodel::SimpleFormInputs::Helpers (module)">Helpers</a></span><small class='search_info'>Anchormodel::SimpleFormInputs</small></div><ul><li id='object_Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon' class='collapsed'><div class='item' style='padding-left:75px'><span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon (module)">AnchormodelInputsCommon</a></span><small class='search_info'>Anchormodel::SimpleFormInputs::Helpers</small></div></li></ul></li></ul></li><li id='object_Anchormodel::Util' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/Util.html" title="Anchormodel::Util (module)">Util</a></span><small class='search_info'>Anchormodel</small></div></li><li id='object_Anchormodel::Version' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Anchormodel/Version.html" title="Anchormodel::Version (module)">Version</a></span><small class='search_info'>Anchormodel</small></div></li></ul></li><li id='object_AnchormodelCheckBoxesInput' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="AnchormodelCheckBoxesInput.html" title="AnchormodelCheckBoxesInput (class)">AnchormodelCheckBoxesInput</a></span> &lt; CollectionCheckBoxesInput<small class='search_info'>Top Level Namespace</small></div></li><li id='object_AnchormodelGenerator' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="AnchormodelGenerator.html" title="AnchormodelGenerator (class)">AnchormodelGenerator</a></span> &lt; NamedBase<small class='search_info'>Top Level Namespace</small></div></li><li id='object_AnchormodelInput' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="AnchormodelInput.html" title="AnchormodelInput (class)">AnchormodelInput</a></span> &lt; CollectionSelectInput<small class='search_info'>Top Level Namespace</small></div></li><li id='object_AnchormodelRadioButtonsInput' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="AnchormodelRadioButtonsInput.html" title="AnchormodelRadioButtonsInput (class)">AnchormodelRadioButtonsInput</a></span> &lt; CollectionRadioButtonsInput<small class='search_info'>Top Level Namespace</small></div></li>
47
47
 
48
48
  </ul>
49
49
  </div>
data/doc/file.README.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  File: README
8
8
 
9
- &mdash; Documentation by YARD 0.9.28
9
+ &mdash; Documentation by YARD 0.9.34
10
10
 
11
11
  </title>
12
12
 
@@ -261,15 +261,87 @@
261
261
  <p>If you want to have multiple attributes in the same model pointing to the same Anchormodel, you need to disable <code>model_methods</code> for at least one of them (otherwise the model methods will clash in your model class):</p>
262
262
 
263
263
  <pre class="code ruby"><code class="ruby"><span class='comment'># app/models/user.rb
264
- </span> <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span> <span class='symbol'>:role</span>
265
- <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span> <span class='symbol'>:secondary_role</span><span class='comma'>,</span> <span class='const'>Role</span><span class='comma'>,</span> <span class='label'>model_methods:</span> <span class='kw'>false</span>
264
+ </span><span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span> <span class='symbol'>:role</span>
265
+ <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span> <span class='symbol'>:secondary_role</span><span class='comma'>,</span> <span class='const'>Role</span><span class='comma'>,</span> <span class='label'>model_methods:</span> <span class='kw'>false</span>
266
+ </code></pre>
267
+
268
+ <h1 id="label-Attaching+multiple+Anchormodels+to+an+attribute+-28similar+to+a+has_many+collection-29">Attaching multiple Anchormodels to an attribute (similar to a has_many collection)</h1>
269
+
270
+ <p>Collections of Anchormodels are supported. Assuming that your <code>User</code> can have multiple <code>Role</code> anchormodels, your code can look as follows:</p>
271
+
272
+ <pre class="code ruby"><code class="ruby"><span class='comment'># app/models/user.rb
273
+ </span><span class='id identifier rubyid_belongs_to_anchormodels'>belongs_to_anchormodels</span> <span class='symbol'>:roles</span>
274
+ </code></pre>
275
+
276
+ <p>The method is deliberately called <code>belongs_to...</code> and not <code>has_many...</code> in order to indicate that the key is stored in a column of the model in which you are calling it. The rule of thumb for using a collection of Anchormodels is:</p>
277
+ <ul><li>
278
+ <p>Your column should be of type <code>string</code>, just like with the singular <code>belongs_to_anchormodel</code>.</p>
279
+ </li><li>
280
+ <p>Anchormodels will be stored in string form, separated by the <code>,</code> character</p>
281
+ </li><li>
282
+ <p>When reading the attribute, you will get a <code>Set</code>, thus duplicates are avoided.</p>
283
+ </li></ul>
284
+
285
+ <p>Example usage for a User model with multiple roles as shown above:</p>
286
+
287
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_u'>u</span> <span class='op'>=</span> <span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
288
+ <span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span> <span class='op'>=</span> <span class='qsymbols_beg'>%i[</span><span class='tstring_content'>moderator</span><span class='words_sep'> </span><span class='tstring_content'>admin</span><span class='tstring_end'>]</span></span> <span class='comment'># this will replace the user&#39;s roles by the two specified
289
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span> <span class='comment'># this will return a set of two Role Anchormodel instances, moderator and role
290
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_guest!'>guest!</span> <span class='comment'># this will add the role `guest` to the user&#39;s roles
291
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_guest?'>guest?</span> <span class='comment'># this will query whether the role `guest` is part of the user&#39;s roles
292
+ </span><span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_moderator'>moderator</span> <span class='comment'># This will return all users that have the moderator role as part of their roles
293
+ </span></code></pre>
294
+
295
+ <p>For modifying a collection of Anchormodels, the following methods are implemented, the first three accepting a String, Symbol or Anchormodel:</p>
296
+
297
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='symbol'>:moderator</span><span class='rparen'>)</span> <span class='comment'># same as u.moderator!
298
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span> <span class='op'>&lt;&lt;</span> <span class='symbol'>:moderator</span> <span class='comment'># alias of add
299
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:moderator</span><span class='rparen'>)</span>
300
+ <span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span><span class='period'>.</span><span class='id identifier rubyid_clear'>clear</span>
301
+ </code></pre>
302
+
303
+ <p>Note that no other methods of Set are overwritten at this point - if you use any other methods mutating the underlying Set, your changes will not be applied.</p>
304
+
305
+ <h2 id="label-Basic+rails+form+for+a+collection+of+Anchormodels">Basic rails form for a collection of Anchormodels</h2>
306
+
307
+ <pre class="code ruby"><code class="ruby">&lt;%= form_with(model: user) do |form| %&gt;
308
+ &lt;%# ... %&gt;
309
+ &lt;%= form.collection_select :role, Role.all, :key, :label, multiple: true %&gt;
310
+ &lt;%# ... %&gt;
311
+ &lt;% end %&gt;
312
+ </code></pre>
313
+
314
+ <p>If you get an error due to unpermitted params, make sure, you are allowing array-style parameters: <code>params.require(:user).permit(roles: [])</code></p>
315
+
316
+ <h2 id="label-SimpleForm+for+a+collection+of+Anchormodels">SimpleForm for a collection of Anchormodels</h2>
317
+
318
+ <p>Anchormodel’s <a href="https://github.com/heartcombo/simple_form">simple_form</a> support also includes collections of Anchormodels.</p>
319
+
320
+ <p>Just like in the single Anchormodel implementation, a select input can be provided with:</p>
321
+
322
+ <pre class="code ruby"><code class="ruby">&lt;%= simple_form_for user do |f| %&gt;
323
+ &lt;%# ... %&gt;
324
+ &lt;%= f.input :role %&gt;
325
+ &lt;%# ... %&gt;
326
+ &lt;% end %&gt;
327
+ </code></pre>
328
+
329
+ <p>The input figures out automatically that it is operating on a collection, so the form code is the same as for a single Anchormodel.</p>
330
+
331
+ <p>However, radio buttons are unsuitable for collections, so use check boxes instead:</p>
332
+
333
+ <pre class="code ruby"><code class="ruby">&lt;%= simple_form_for user do |f| %&gt;
334
+ &lt;%# ... %&gt;
335
+ &lt;%= f.input :role, as: :anchormodel_check_boxes %&gt;
336
+ &lt;%# ... %&gt;
337
+ &lt;% end %&gt;
266
338
  </code></pre>
267
339
  </div></div>
268
340
 
269
341
  <div id="footer">
270
- Generated on Wed Apr 24 17:01:46 2024 by
342
+ Generated on Sat Apr 27 10:18:33 2024 by
271
343
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
272
- 0.9.28 (ruby-3.2.2).
344
+ 0.9.34 (ruby-3.2.2).
273
345
  </div>
274
346
 
275
347
  </div>
data/doc/frames.html CHANGED
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8">
5
- <title>Documentation by YARD 0.9.28</title>
5
+ <title>Documentation by YARD 0.9.34</title>
6
6
  </head>
7
7
  <script type="text/javascript">
8
8
  var match = unescape(window.location.hash).match(/^#!(.+)/);
data/doc/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  File: README
8
8
 
9
- &mdash; Documentation by YARD 0.9.28
9
+ &mdash; Documentation by YARD 0.9.34
10
10
 
11
11
  </title>
12
12
 
@@ -261,15 +261,87 @@
261
261
  <p>If you want to have multiple attributes in the same model pointing to the same Anchormodel, you need to disable <code>model_methods</code> for at least one of them (otherwise the model methods will clash in your model class):</p>
262
262
 
263
263
  <pre class="code ruby"><code class="ruby"><span class='comment'># app/models/user.rb
264
- </span> <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span> <span class='symbol'>:role</span>
265
- <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span> <span class='symbol'>:secondary_role</span><span class='comma'>,</span> <span class='const'>Role</span><span class='comma'>,</span> <span class='label'>model_methods:</span> <span class='kw'>false</span>
264
+ </span><span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span> <span class='symbol'>:role</span>
265
+ <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span> <span class='symbol'>:secondary_role</span><span class='comma'>,</span> <span class='const'>Role</span><span class='comma'>,</span> <span class='label'>model_methods:</span> <span class='kw'>false</span>
266
+ </code></pre>
267
+
268
+ <h1 id="label-Attaching+multiple+Anchormodels+to+an+attribute+-28similar+to+a+has_many+collection-29">Attaching multiple Anchormodels to an attribute (similar to a has_many collection)</h1>
269
+
270
+ <p>Collections of Anchormodels are supported. Assuming that your <code>User</code> can have multiple <code>Role</code> anchormodels, your code can look as follows:</p>
271
+
272
+ <pre class="code ruby"><code class="ruby"><span class='comment'># app/models/user.rb
273
+ </span><span class='id identifier rubyid_belongs_to_anchormodels'>belongs_to_anchormodels</span> <span class='symbol'>:roles</span>
274
+ </code></pre>
275
+
276
+ <p>The method is deliberately called <code>belongs_to...</code> and not <code>has_many...</code> in order to indicate that the key is stored in a column of the model in which you are calling it. The rule of thumb for using a collection of Anchormodels is:</p>
277
+ <ul><li>
278
+ <p>Your column should be of type <code>string</code>, just like with the singular <code>belongs_to_anchormodel</code>.</p>
279
+ </li><li>
280
+ <p>Anchormodels will be stored in string form, separated by the <code>,</code> character</p>
281
+ </li><li>
282
+ <p>When reading the attribute, you will get a <code>Set</code>, thus duplicates are avoided.</p>
283
+ </li></ul>
284
+
285
+ <p>Example usage for a User model with multiple roles as shown above:</p>
286
+
287
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_u'>u</span> <span class='op'>=</span> <span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
288
+ <span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span> <span class='op'>=</span> <span class='qsymbols_beg'>%i[</span><span class='tstring_content'>moderator</span><span class='words_sep'> </span><span class='tstring_content'>admin</span><span class='tstring_end'>]</span></span> <span class='comment'># this will replace the user&#39;s roles by the two specified
289
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span> <span class='comment'># this will return a set of two Role Anchormodel instances, moderator and role
290
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_guest!'>guest!</span> <span class='comment'># this will add the role `guest` to the user&#39;s roles
291
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_guest?'>guest?</span> <span class='comment'># this will query whether the role `guest` is part of the user&#39;s roles
292
+ </span><span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_moderator'>moderator</span> <span class='comment'># This will return all users that have the moderator role as part of their roles
293
+ </span></code></pre>
294
+
295
+ <p>For modifying a collection of Anchormodels, the following methods are implemented, the first three accepting a String, Symbol or Anchormodel:</p>
296
+
297
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='symbol'>:moderator</span><span class='rparen'>)</span> <span class='comment'># same as u.moderator!
298
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span> <span class='op'>&lt;&lt;</span> <span class='symbol'>:moderator</span> <span class='comment'># alias of add
299
+ </span><span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:moderator</span><span class='rparen'>)</span>
300
+ <span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_roles'>roles</span><span class='period'>.</span><span class='id identifier rubyid_clear'>clear</span>
301
+ </code></pre>
302
+
303
+ <p>Note that no other methods of Set are overwritten at this point - if you use any other methods mutating the underlying Set, your changes will not be applied.</p>
304
+
305
+ <h2 id="label-Basic+rails+form+for+a+collection+of+Anchormodels">Basic rails form for a collection of Anchormodels</h2>
306
+
307
+ <pre class="code ruby"><code class="ruby">&lt;%= form_with(model: user) do |form| %&gt;
308
+ &lt;%# ... %&gt;
309
+ &lt;%= form.collection_select :role, Role.all, :key, :label, multiple: true %&gt;
310
+ &lt;%# ... %&gt;
311
+ &lt;% end %&gt;
312
+ </code></pre>
313
+
314
+ <p>If you get an error due to unpermitted params, make sure, you are allowing array-style parameters: <code>params.require(:user).permit(roles: [])</code></p>
315
+
316
+ <h2 id="label-SimpleForm+for+a+collection+of+Anchormodels">SimpleForm for a collection of Anchormodels</h2>
317
+
318
+ <p>Anchormodel’s <a href="https://github.com/heartcombo/simple_form">simple_form</a> support also includes collections of Anchormodels.</p>
319
+
320
+ <p>Just like in the single Anchormodel implementation, a select input can be provided with:</p>
321
+
322
+ <pre class="code ruby"><code class="ruby">&lt;%= simple_form_for user do |f| %&gt;
323
+ &lt;%# ... %&gt;
324
+ &lt;%= f.input :role %&gt;
325
+ &lt;%# ... %&gt;
326
+ &lt;% end %&gt;
327
+ </code></pre>
328
+
329
+ <p>The input figures out automatically that it is operating on a collection, so the form code is the same as for a single Anchormodel.</p>
330
+
331
+ <p>However, radio buttons are unsuitable for collections, so use check boxes instead:</p>
332
+
333
+ <pre class="code ruby"><code class="ruby">&lt;%= simple_form_for user do |f| %&gt;
334
+ &lt;%# ... %&gt;
335
+ &lt;%= f.input :role, as: :anchormodel_check_boxes %&gt;
336
+ &lt;%# ... %&gt;
337
+ &lt;% end %&gt;
266
338
  </code></pre>
267
339
  </div></div>
268
340
 
269
341
  <div id="footer">
270
- Generated on Wed Apr 24 17:01:46 2024 by
342
+ Generated on Sat Apr 27 10:18:33 2024 by
271
343
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
272
- 0.9.28 (ruby-3.2.2).
344
+ 0.9.34 (ruby-3.2.2).
273
345
  </div>
274
346
 
275
347
  </div>