anchormodel 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +36 -1
- data/VERSION +1 -1
- data/anchormodel.gemspec +5 -5
- data/doc/Anchormodel/ActiveModelTypeValueSingle.html +615 -0
- data/doc/Anchormodel/Attribute.html +3 -3
- data/doc/Anchormodel/ModelMixin.html +3 -3
- data/doc/Anchormodel/Util.html +496 -0
- data/doc/Anchormodel/Version.html +3 -3
- data/doc/Anchormodel.html +5 -5
- data/doc/AnchormodelGenerator.html +201 -0
- data/doc/_index.html +51 -4
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +35 -4
- data/doc/frames.html +5 -10
- data/doc/index.html +35 -4
- data/doc/method_list.html +17 -9
- data/doc/top-level-namespace.html +4 -4
- data/lib/anchormodel/simple_form_inputs/anchormodel_input.rb +21 -0
- data/lib/anchormodel/simple_form_inputs/anchormodel_radio_buttons_input.rb +23 -0
- data/lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.rb +49 -0
- data/lib/anchormodel.rb +3 -0
- metadata +9 -4
- data/pkg/anchormodel-0.1.3.gem +0 -0
@@ -0,0 +1,201 @@
|
|
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: AnchormodelGenerator
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.28
|
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 = "AnchormodelGenerator";
|
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> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">AnchormodelGenerator</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: AnchormodelGenerator
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
<dl>
|
70
|
+
<dt>Inherits:</dt>
|
71
|
+
<dd>
|
72
|
+
<span class="inheritName">Rails::Generators::NamedBase</span>
|
73
|
+
|
74
|
+
<ul class="fullTree">
|
75
|
+
<li>Object</li>
|
76
|
+
|
77
|
+
<li class="next">Rails::Generators::NamedBase</li>
|
78
|
+
|
79
|
+
<li class="next">AnchormodelGenerator</li>
|
80
|
+
|
81
|
+
</ul>
|
82
|
+
<a href="#" class="inheritanceTree">show all</a>
|
83
|
+
|
84
|
+
</dd>
|
85
|
+
</dl>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
<dl>
|
98
|
+
<dt>Defined in:</dt>
|
99
|
+
<dd>lib/generators/anchormodel/anchormodel_generator.rb</dd>
|
100
|
+
</dl>
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
<h2>
|
113
|
+
Instance Method Summary
|
114
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
115
|
+
</h2>
|
116
|
+
|
117
|
+
<ul class="summary">
|
118
|
+
|
119
|
+
<li class="public ">
|
120
|
+
<span class="summary_signature">
|
121
|
+
|
122
|
+
<a href="#add_anchormodel-instance_method" title="#add_anchormodel (instance method)">#<strong>add_anchormodel</strong> ⇒ Object </a>
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
</span>
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
137
|
+
|
138
|
+
</li>
|
139
|
+
|
140
|
+
|
141
|
+
</ul>
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
<div id="instance_method_details" class="method_details_list">
|
148
|
+
<h2>Instance Method Details</h2>
|
149
|
+
|
150
|
+
|
151
|
+
<div class="method_details first">
|
152
|
+
<h3 class="signature first" id="add_anchormodel-instance_method">
|
153
|
+
|
154
|
+
#<strong>add_anchormodel</strong> ⇒ <tt>Object</tt>
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
</h3><table class="source_code">
|
161
|
+
<tr>
|
162
|
+
<td>
|
163
|
+
<pre class="lines">
|
164
|
+
|
165
|
+
|
166
|
+
4
|
167
|
+
5
|
168
|
+
6
|
169
|
+
7
|
170
|
+
8
|
171
|
+
9
|
172
|
+
10</pre>
|
173
|
+
</td>
|
174
|
+
<td>
|
175
|
+
<pre class="code"><span class="info file"># File 'lib/generators/anchormodel/anchormodel_generator.rb', line 4</span>
|
176
|
+
|
177
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_add_anchormodel'>add_anchormodel</span>
|
178
|
+
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>NAME must be present.</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
|
179
|
+
<span class='ivar'>@klass</span> <span class='op'>=</span> <span class='ivar'>@name</span><span class='period'>.</span><span class='id identifier rubyid_camelize'>camelize</span>
|
180
|
+
<span class='ivar'>@filename</span> <span class='op'>=</span> <span class='ivar'>@name</span><span class='period'>.</span><span class='id identifier rubyid_underscore'>underscore</span>
|
181
|
+
|
182
|
+
<span class='id identifier rubyid_template'>template</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>anchormodel.rb.erb</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>app/anchormodels/</span><span class='embexpr_beg'>#{</span><span class='ivar'>@filename</span><span class='embexpr_end'>}</span><span class='tstring_content'>.rb</span><span class='tstring_end'>"</span></span>
|
183
|
+
<span class='kw'>end</span></pre>
|
184
|
+
</td>
|
185
|
+
</tr>
|
186
|
+
</table>
|
187
|
+
</div>
|
188
|
+
|
189
|
+
</div>
|
190
|
+
|
191
|
+
</div>
|
192
|
+
|
193
|
+
<div id="footer">
|
194
|
+
Generated on Wed Apr 24 17:01:46 2024 by
|
195
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
196
|
+
0.9.28 (ruby-3.2.2).
|
197
|
+
</div>
|
198
|
+
|
199
|
+
</div>
|
200
|
+
</body>
|
201
|
+
</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.
|
7
|
+
Documentation by YARD 0.9.28
|
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.
|
55
|
+
<div id="content"><h1 class="noborder title">Documentation by YARD 0.9.28</h1>
|
56
56
|
<div id="listing">
|
57
57
|
<h1 class="alphaindex">Alphabetic Index</h1>
|
58
58
|
|
@@ -97,6 +97,23 @@
|
|
97
97
|
|
98
98
|
</li>
|
99
99
|
|
100
|
+
<li>
|
101
|
+
<span class='object_link'><a href="AnchormodelInput.html" title="AnchormodelInput (class)">AnchormodelInput</a></span>
|
102
|
+
|
103
|
+
</li>
|
104
|
+
|
105
|
+
<li>
|
106
|
+
<span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon (module)">AnchormodelInputsCommon</a></span>
|
107
|
+
|
108
|
+
<small>(Anchormodel::SimpleFormInputs::Helpers)</small>
|
109
|
+
|
110
|
+
</li>
|
111
|
+
|
112
|
+
<li>
|
113
|
+
<span class='object_link'><a href="AnchormodelRadioButtonsInput.html" title="AnchormodelRadioButtonsInput (class)">AnchormodelRadioButtonsInput</a></span>
|
114
|
+
|
115
|
+
</li>
|
116
|
+
|
100
117
|
<li>
|
101
118
|
<span class='object_link'><a href="Anchormodel/Attribute.html" title="Anchormodel::Attribute (class)">Attribute</a></span>
|
102
119
|
|
@@ -108,6 +125,21 @@
|
|
108
125
|
</ul>
|
109
126
|
|
110
127
|
|
128
|
+
<ul id="alpha_H" class="alpha">
|
129
|
+
<li class="letter">H</li>
|
130
|
+
<ul>
|
131
|
+
|
132
|
+
<li>
|
133
|
+
<span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers.html" title="Anchormodel::SimpleFormInputs::Helpers (module)">Helpers</a></span>
|
134
|
+
|
135
|
+
<small>(Anchormodel::SimpleFormInputs)</small>
|
136
|
+
|
137
|
+
</li>
|
138
|
+
|
139
|
+
</ul>
|
140
|
+
</ul>
|
141
|
+
|
142
|
+
|
111
143
|
<ul id="alpha_M" class="alpha">
|
112
144
|
<li class="letter">M</li>
|
113
145
|
<ul>
|
@@ -123,6 +155,21 @@
|
|
123
155
|
</ul>
|
124
156
|
|
125
157
|
|
158
|
+
<ul id="alpha_S" class="alpha">
|
159
|
+
<li class="letter">S</li>
|
160
|
+
<ul>
|
161
|
+
|
162
|
+
<li>
|
163
|
+
<span class='object_link'><a href="Anchormodel/SimpleFormInputs.html" title="Anchormodel::SimpleFormInputs (module)">SimpleFormInputs</a></span>
|
164
|
+
|
165
|
+
<small>(Anchormodel)</small>
|
166
|
+
|
167
|
+
</li>
|
168
|
+
|
169
|
+
</ul>
|
170
|
+
</ul>
|
171
|
+
|
172
|
+
|
126
173
|
<ul id="alpha_U" class="alpha">
|
127
174
|
<li class="letter">U</li>
|
128
175
|
<ul>
|
@@ -161,9 +208,9 @@
|
|
161
208
|
</div>
|
162
209
|
|
163
210
|
<div id="footer">
|
164
|
-
Generated on
|
211
|
+
Generated on Wed Apr 24 17:01:45 2024 by
|
165
212
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
166
|
-
0.9.
|
213
|
+
0.9.28 (ruby-3.2.2).
|
167
214
|
</div>
|
168
215
|
|
169
216
|
</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> < 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> < 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> < 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::
|
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> < 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> < 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> < 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> < 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> < 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> < 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
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.28
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -85,7 +85,7 @@
|
|
85
85
|
|
86
86
|
<h3 id="label-ActiveEnum">ActiveEnum</h3>
|
87
87
|
|
88
|
-
<p>The gem
|
88
|
+
<p>The gem <a href="https://github.com/adzap/active_enum">ActiveEnum</a> allows to create Enum-like classes that can be extended. However it only supports Integer keys. I find this unsatisfactory, as debugging with tools like <code>psql</code> or <code>mysql</code> is made unnecessarily hard when you only see numbers. Keys for enums should be meaningful, making you immediately understand what they stand for.</p>
|
89
89
|
|
90
90
|
<p>This is why Anchormodel is strictly relying on String keys corresponding to the entries of an Anchormodel.</p>
|
91
91
|
|
@@ -159,6 +159,37 @@
|
|
159
159
|
</span><span class='ivar'>@user</span><span class='period'>.</span><span class='id identifier rubyid_role'>role</span><span class='period'>.</span><span class='id identifier rubyid_admin?'>admin?</span> <span class='comment'># true if and only if the role is admin (false otherwise)
|
160
160
|
</span></code></pre>
|
161
161
|
|
162
|
+
<p>Your form could look something like this:</p>
|
163
|
+
|
164
|
+
<pre class="code ruby"><code class="ruby"><%= form_with(model: user) do |form| %>
|
165
|
+
<%# ... %>
|
166
|
+
<%= form.collection_select :role, Role.all, :key, :label %>
|
167
|
+
<%# ... %>
|
168
|
+
<% end %>
|
169
|
+
</code></pre>
|
170
|
+
|
171
|
+
<h2 id="label-Using+Anchormodel+with+Simpleform">Using Anchormodel with Simpleform</h2>
|
172
|
+
|
173
|
+
<p>Anchormodel has built-in support for the <a href="https://github.com/heartcombo/simple_form">simple_form</a> gem by providing an input for the type <code>:anchormodel</code> which displays anchormodel attributes as a collection select.</p>
|
174
|
+
|
175
|
+
<p>After SimpleForm is installed, you can write your form as:</p>
|
176
|
+
|
177
|
+
<pre class="code ruby"><code class="ruby"><%= simple_form_for user do |f| %>
|
178
|
+
<%# ... %>
|
179
|
+
<%= f.input :role %>
|
180
|
+
<%# ... %>
|
181
|
+
<% end %>
|
182
|
+
</code></pre>
|
183
|
+
|
184
|
+
<p>Or, if you prefer radio buttons instead:</p>
|
185
|
+
|
186
|
+
<pre class="code ruby"><code class="ruby"><%= simple_form_for user do |f| %>
|
187
|
+
<%# ... %>
|
188
|
+
<%= f.input :role, as: :anchormodel_radio_buttons %>
|
189
|
+
<%# ... %>
|
190
|
+
<% end %>
|
191
|
+
</code></pre>
|
192
|
+
|
162
193
|
<h1 id="label-Rails+Enum+style+model+methods">Rails Enum style model methods</h1>
|
163
194
|
|
164
195
|
<p>By default, Anchormodel adds three kinds of methods for each key to the model:</p>
|
@@ -236,9 +267,9 @@
|
|
236
267
|
</div></div>
|
237
268
|
|
238
269
|
<div id="footer">
|
239
|
-
Generated on
|
270
|
+
Generated on Wed Apr 24 17:01:46 2024 by
|
240
271
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
241
|
-
0.9.
|
272
|
+
0.9.28 (ruby-3.2.2).
|
242
273
|
</div>
|
243
274
|
|
244
275
|
</div>
|
data/doc/frames.html
CHANGED
@@ -2,18 +2,13 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8">
|
5
|
-
<title>Documentation by YARD 0.9.
|
5
|
+
<title>Documentation by YARD 0.9.28</title>
|
6
6
|
</head>
|
7
7
|
<script type="text/javascript">
|
8
|
-
var
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
var url = new URL(name, location.href);
|
13
|
-
window.top.location.replace(url.origin === location.origin ? name : mainUrl);
|
14
|
-
} catch (e) {
|
15
|
-
window.top.location.replace(mainUrl);
|
16
|
-
}
|
8
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
9
|
+
var name = match ? match[1] : 'index.html';
|
10
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
11
|
+
window.top.location = name;
|
17
12
|
</script>
|
18
13
|
<noscript>
|
19
14
|
<h1>Oops!</h1>
|
data/doc/index.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
File: README
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.28
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -85,7 +85,7 @@
|
|
85
85
|
|
86
86
|
<h3 id="label-ActiveEnum">ActiveEnum</h3>
|
87
87
|
|
88
|
-
<p>The gem
|
88
|
+
<p>The gem <a href="https://github.com/adzap/active_enum">ActiveEnum</a> allows to create Enum-like classes that can be extended. However it only supports Integer keys. I find this unsatisfactory, as debugging with tools like <code>psql</code> or <code>mysql</code> is made unnecessarily hard when you only see numbers. Keys for enums should be meaningful, making you immediately understand what they stand for.</p>
|
89
89
|
|
90
90
|
<p>This is why Anchormodel is strictly relying on String keys corresponding to the entries of an Anchormodel.</p>
|
91
91
|
|
@@ -159,6 +159,37 @@
|
|
159
159
|
</span><span class='ivar'>@user</span><span class='period'>.</span><span class='id identifier rubyid_role'>role</span><span class='period'>.</span><span class='id identifier rubyid_admin?'>admin?</span> <span class='comment'># true if and only if the role is admin (false otherwise)
|
160
160
|
</span></code></pre>
|
161
161
|
|
162
|
+
<p>Your form could look something like this:</p>
|
163
|
+
|
164
|
+
<pre class="code ruby"><code class="ruby"><%= form_with(model: user) do |form| %>
|
165
|
+
<%# ... %>
|
166
|
+
<%= form.collection_select :role, Role.all, :key, :label %>
|
167
|
+
<%# ... %>
|
168
|
+
<% end %>
|
169
|
+
</code></pre>
|
170
|
+
|
171
|
+
<h2 id="label-Using+Anchormodel+with+Simpleform">Using Anchormodel with Simpleform</h2>
|
172
|
+
|
173
|
+
<p>Anchormodel has built-in support for the <a href="https://github.com/heartcombo/simple_form">simple_form</a> gem by providing an input for the type <code>:anchormodel</code> which displays anchormodel attributes as a collection select.</p>
|
174
|
+
|
175
|
+
<p>After SimpleForm is installed, you can write your form as:</p>
|
176
|
+
|
177
|
+
<pre class="code ruby"><code class="ruby"><%= simple_form_for user do |f| %>
|
178
|
+
<%# ... %>
|
179
|
+
<%= f.input :role %>
|
180
|
+
<%# ... %>
|
181
|
+
<% end %>
|
182
|
+
</code></pre>
|
183
|
+
|
184
|
+
<p>Or, if you prefer radio buttons instead:</p>
|
185
|
+
|
186
|
+
<pre class="code ruby"><code class="ruby"><%= simple_form_for user do |f| %>
|
187
|
+
<%# ... %>
|
188
|
+
<%= f.input :role, as: :anchormodel_radio_buttons %>
|
189
|
+
<%# ... %>
|
190
|
+
<% end %>
|
191
|
+
</code></pre>
|
192
|
+
|
162
193
|
<h1 id="label-Rails+Enum+style+model+methods">Rails Enum style model methods</h1>
|
163
194
|
|
164
195
|
<p>By default, Anchormodel adds three kinds of methods for each key to the model:</p>
|
@@ -236,9 +267,9 @@
|
|
236
267
|
</div></div>
|
237
268
|
|
238
269
|
<div id="footer">
|
239
|
-
Generated on
|
270
|
+
Generated on Wed Apr 24 17:01:46 2024 by
|
240
271
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
241
|
-
0.9.
|
272
|
+
0.9.28 (ruby-3.2.2).
|
242
273
|
</div>
|
243
274
|
|
244
275
|
</div>
|
data/doc/method_list.html
CHANGED
@@ -149,6 +149,14 @@
|
|
149
149
|
|
150
150
|
|
151
151
|
<li class="even ">
|
152
|
+
<div class="item">
|
153
|
+
<span class='object_link'><a href="Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html#input-instance_method" title="Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon#input (method)">#input</a></span>
|
154
|
+
<small>Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon</small>
|
155
|
+
</div>
|
156
|
+
</li>
|
157
|
+
|
158
|
+
|
159
|
+
<li class="odd ">
|
152
160
|
<div class="item">
|
153
161
|
<span class='object_link'><a href="Anchormodel.html#inspect-instance_method" title="Anchormodel#inspect (method)">#inspect</a></span>
|
154
162
|
<small>Anchormodel</small>
|
@@ -156,7 +164,7 @@
|
|
156
164
|
</li>
|
157
165
|
|
158
166
|
|
159
|
-
<li class="
|
167
|
+
<li class="even ">
|
160
168
|
<div class="item">
|
161
169
|
<span class='object_link'><a href="Anchormodel/Util.html#install_methods_in_model-class_method" title="Anchormodel::Util.install_methods_in_model (method)">install_methods_in_model</a></span>
|
162
170
|
<small>Anchormodel::Util</small>
|
@@ -164,7 +172,7 @@
|
|
164
172
|
</li>
|
165
173
|
|
166
174
|
|
167
|
-
<li class="
|
175
|
+
<li class="odd ">
|
168
176
|
<div class="item">
|
169
177
|
<span class='object_link'><a href="Anchormodel.html#key-instance_method" title="Anchormodel#key (method)">#key</a></span>
|
170
178
|
<small>Anchormodel</small>
|
@@ -172,7 +180,7 @@
|
|
172
180
|
</li>
|
173
181
|
|
174
182
|
|
175
|
-
<li class="
|
183
|
+
<li class="even ">
|
176
184
|
<div class="item">
|
177
185
|
<span class='object_link'><a href="Anchormodel.html#label-instance_method" title="Anchormodel#label (method)">#label</a></span>
|
178
186
|
<small>Anchormodel</small>
|
@@ -180,7 +188,7 @@
|
|
180
188
|
</li>
|
181
189
|
|
182
190
|
|
183
|
-
<li class="
|
191
|
+
<li class="odd ">
|
184
192
|
<div class="item">
|
185
193
|
<span class='object_link'><a href="Anchormodel/Attribute.html#optional-instance_method" title="Anchormodel::Attribute#optional (method)">#optional</a></span>
|
186
194
|
<small>Anchormodel::Attribute</small>
|
@@ -188,7 +196,7 @@
|
|
188
196
|
</li>
|
189
197
|
|
190
198
|
|
191
|
-
<li class="
|
199
|
+
<li class="even ">
|
192
200
|
<div class="item">
|
193
201
|
<span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html#serializable%3F-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#serializable? (method)">#serializable?</a></span>
|
194
202
|
<small>Anchormodel::ActiveModelTypeValueSingle</small>
|
@@ -196,7 +204,7 @@
|
|
196
204
|
</li>
|
197
205
|
|
198
206
|
|
199
|
-
<li class="
|
207
|
+
<li class="odd ">
|
200
208
|
<div class="item">
|
201
209
|
<span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html#serialize-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#serialize (method)">#serialize</a></span>
|
202
210
|
<small>Anchormodel::ActiveModelTypeValueSingle</small>
|
@@ -204,7 +212,7 @@
|
|
204
212
|
</li>
|
205
213
|
|
206
214
|
|
207
|
-
<li class="
|
215
|
+
<li class="even ">
|
208
216
|
<div class="item">
|
209
217
|
<span class='object_link'><a href="Anchormodel.html#setup!-class_method" title="Anchormodel.setup! (method)">setup!</a></span>
|
210
218
|
<small>Anchormodel</small>
|
@@ -212,7 +220,7 @@
|
|
212
220
|
</li>
|
213
221
|
|
214
222
|
|
215
|
-
<li class="
|
223
|
+
<li class="odd ">
|
216
224
|
<div class="item">
|
217
225
|
<span class='object_link'><a href="Anchormodel.html#to_s-instance_method" title="Anchormodel#to_s (method)">#to_s</a></span>
|
218
226
|
<small>Anchormodel</small>
|
@@ -220,7 +228,7 @@
|
|
220
228
|
</li>
|
221
229
|
|
222
230
|
|
223
|
-
<li class="
|
231
|
+
<li class="even ">
|
224
232
|
<div class="item">
|
225
233
|
<span class='object_link'><a href="Anchormodel/ActiveModelTypeValueSingle.html#type-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#type (method)">#type</a></span>
|
226
234
|
<small>Anchormodel::ActiveModelTypeValueSingle</small>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.28
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -84,7 +84,7 @@
|
|
84
84
|
|
85
85
|
|
86
86
|
|
87
|
-
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span>, <span class='object_link'><a href="AnchormodelGenerator.html" title="AnchormodelGenerator (class)">AnchormodelGenerator</a></span>
|
87
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span>, <span class='object_link'><a href="AnchormodelGenerator.html" title="AnchormodelGenerator (class)">AnchormodelGenerator</a></span>, <span class='object_link'><a href="AnchormodelInput.html" title="AnchormodelInput (class)">AnchormodelInput</a></span>, <span class='object_link'><a href="AnchormodelRadioButtonsInput.html" title="AnchormodelRadioButtonsInput (class)">AnchormodelRadioButtonsInput</a></span>
|
88
88
|
|
89
89
|
|
90
90
|
</p>
|
@@ -100,9 +100,9 @@
|
|
100
100
|
</div>
|
101
101
|
|
102
102
|
<div id="footer">
|
103
|
-
Generated on
|
103
|
+
Generated on Wed Apr 24 17:01:46 2024 by
|
104
104
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
|
-
0.9.
|
105
|
+
0.9.28 (ruby-3.2.2).
|
106
106
|
</div>
|
107
107
|
|
108
108
|
</div>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
unless defined? SimpleForm
|
2
|
+
begin
|
3
|
+
require 'simple_form'
|
4
|
+
rescue LoadError
|
5
|
+
nil
|
6
|
+
end
|
7
|
+
|
8
|
+
end
|
9
|
+
if defined? SimpleForm
|
10
|
+
class AnchormodelInput < SimpleForm::Inputs::CollectionSelectInput
|
11
|
+
include Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def sf_selection_key
|
16
|
+
:selected
|
17
|
+
end
|
18
|
+
|
19
|
+
def before_render_input; end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
unless defined? SimpleForm
|
2
|
+
begin
|
3
|
+
require 'simple_form'
|
4
|
+
rescue LoadError
|
5
|
+
nil
|
6
|
+
end
|
7
|
+
|
8
|
+
end
|
9
|
+
if defined? SimpleForm
|
10
|
+
class AnchormodelRadioButtonsInput < SimpleForm::Inputs::CollectionRadioButtonsInput
|
11
|
+
include Anchormodel::SimpleFormInputs::Helpers::AnchormodelInputsCommon
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def sf_selection_key
|
16
|
+
:checked
|
17
|
+
end
|
18
|
+
|
19
|
+
def before_render_input
|
20
|
+
@input_type = :radio_buttons
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|