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,496 @@
|
|
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
|
+
Module: Anchormodel::Util
|
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 = "Anchormodel::Util";
|
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 (U)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">Util</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>Module: Anchormodel::Util
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<dl>
|
80
|
+
<dt>Defined in:</dt>
|
81
|
+
<dd>lib/anchormodel/util.rb</dd>
|
82
|
+
</dl>
|
83
|
+
|
84
|
+
</div>
|
85
|
+
|
86
|
+
<h2>Overview</h2><div class="docstring">
|
87
|
+
<div class="discussion">
|
88
|
+
|
89
|
+
<p>A swiss army knife for common functionality</p>
|
90
|
+
|
91
|
+
|
92
|
+
</div>
|
93
|
+
</div>
|
94
|
+
<div class="tags">
|
95
|
+
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
<h2>
|
106
|
+
Class Method Summary
|
107
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
108
|
+
</h2>
|
109
|
+
|
110
|
+
<ul class="summary">
|
111
|
+
|
112
|
+
<li class="public ">
|
113
|
+
<span class="summary_signature">
|
114
|
+
|
115
|
+
<a href="#install_methods_in_model-class_method" title="install_methods_in_model (class method)">.<strong>install_methods_in_model</strong>(model_class, attribute_name, anchormodel_class = nil, optional: false, model_readers: true, model_writers: true, model_scopes: true, model_methods: nil) ⇒ Object </a>
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
</span>
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
<span class="summary_desc"><div class='inline'>
|
130
|
+
<p>Installs an anchormodel attribute in a model class.</p>
|
131
|
+
</div></span>
|
132
|
+
|
133
|
+
</li>
|
134
|
+
|
135
|
+
|
136
|
+
</ul>
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
<div id="class_method_details" class="method_details_list">
|
142
|
+
<h2>Class Method Details</h2>
|
143
|
+
|
144
|
+
|
145
|
+
<div class="method_details first">
|
146
|
+
<h3 class="signature first" id="install_methods_in_model-class_method">
|
147
|
+
|
148
|
+
.<strong>install_methods_in_model</strong>(model_class, attribute_name, anchormodel_class = nil, optional: false, model_readers: true, model_writers: true, model_scopes: true, model_methods: nil) ⇒ <tt>Object</tt>
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
</h3><div class="docstring">
|
155
|
+
<div class="discussion">
|
156
|
+
|
157
|
+
<p>Installs an anchormodel attribute in a model class</p>
|
158
|
+
|
159
|
+
|
160
|
+
</div>
|
161
|
+
</div>
|
162
|
+
<div class="tags">
|
163
|
+
<p class="tag_title">Parameters:</p>
|
164
|
+
<ul class="param">
|
165
|
+
|
166
|
+
<li>
|
167
|
+
|
168
|
+
<span class='name'>model_class</span>
|
169
|
+
|
170
|
+
|
171
|
+
<span class='type'>(<tt>ActiveRecord::Base</tt>)</span>
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
—
|
176
|
+
<div class='inline'>
|
177
|
+
<p>Internal only. The model class that the attribute should be installed to.</p>
|
178
|
+
</div>
|
179
|
+
|
180
|
+
</li>
|
181
|
+
|
182
|
+
<li>
|
183
|
+
|
184
|
+
<span class='name'>attribute_name</span>
|
185
|
+
|
186
|
+
|
187
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
—
|
192
|
+
<div class='inline'>
|
193
|
+
<p>The name and database column of the attribute</p>
|
194
|
+
</div>
|
195
|
+
|
196
|
+
</li>
|
197
|
+
|
198
|
+
<li>
|
199
|
+
|
200
|
+
<span class='name'>anchormodel_class</span>
|
201
|
+
|
202
|
+
|
203
|
+
<span class='type'>(<tt>Class</tt>)</span>
|
204
|
+
|
205
|
+
|
206
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
207
|
+
|
208
|
+
|
209
|
+
—
|
210
|
+
<div class='inline'>
|
211
|
+
<p>Class of the Anchormodel (omit if attribute <code>:foo_bar</code> holds a <code>FooBar</code>)</p>
|
212
|
+
</div>
|
213
|
+
|
214
|
+
</li>
|
215
|
+
|
216
|
+
<li>
|
217
|
+
|
218
|
+
<span class='name'>optional</span>
|
219
|
+
|
220
|
+
|
221
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
222
|
+
|
223
|
+
|
224
|
+
<em class="default">(defaults to: <tt>false</tt>)</em>
|
225
|
+
|
226
|
+
|
227
|
+
—
|
228
|
+
<div class='inline'>
|
229
|
+
<p>If false, a presence validation is added to the model.</p>
|
230
|
+
</div>
|
231
|
+
|
232
|
+
</li>
|
233
|
+
|
234
|
+
<li>
|
235
|
+
|
236
|
+
<span class='name'>model_readers</span>
|
237
|
+
|
238
|
+
|
239
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
240
|
+
|
241
|
+
|
242
|
+
<em class="default">(defaults to: <tt>true</tt>)</em>
|
243
|
+
|
244
|
+
|
245
|
+
—
|
246
|
+
<div class='inline'>
|
247
|
+
<p>If true, the model is given an ActiveRecord::Enum style method <code>my_model.my_key?</code> reader for each key in the anchormodel</p>
|
248
|
+
</div>
|
249
|
+
|
250
|
+
</li>
|
251
|
+
|
252
|
+
<li>
|
253
|
+
|
254
|
+
<span class='name'>model_writers</span>
|
255
|
+
|
256
|
+
|
257
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
258
|
+
|
259
|
+
|
260
|
+
<em class="default">(defaults to: <tt>true</tt>)</em>
|
261
|
+
|
262
|
+
|
263
|
+
—
|
264
|
+
<div class='inline'>
|
265
|
+
<p>If true, the model is given an ActiveRecord::Enum style method <code>my_model.my_key!</code> writer for each key in the anchormodel</p>
|
266
|
+
</div>
|
267
|
+
|
268
|
+
</li>
|
269
|
+
|
270
|
+
<li>
|
271
|
+
|
272
|
+
<span class='name'>model_scopes</span>
|
273
|
+
|
274
|
+
|
275
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
276
|
+
|
277
|
+
|
278
|
+
<em class="default">(defaults to: <tt>true</tt>)</em>
|
279
|
+
|
280
|
+
|
281
|
+
—
|
282
|
+
<div class='inline'>
|
283
|
+
<p>If true, the model is given an ActiveRecord::Enum style scope <code>MyModel.mykey</code> for each key in the anchormodel</p>
|
284
|
+
</div>
|
285
|
+
|
286
|
+
</li>
|
287
|
+
|
288
|
+
<li>
|
289
|
+
|
290
|
+
<span class='name'>model_methods</span>
|
291
|
+
|
292
|
+
|
293
|
+
<span class='type'>(<tt>Boolean</tt>, <tt>NilClass</tt>)</span>
|
294
|
+
|
295
|
+
|
296
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
297
|
+
|
298
|
+
|
299
|
+
—
|
300
|
+
<div class='inline'>
|
301
|
+
<p>If non-nil, this mass-assigns and overrides <code>model_readers</code>, <code>model_writers</code> and <code>model_scopes</code></p>
|
302
|
+
</div>
|
303
|
+
|
304
|
+
</li>
|
305
|
+
|
306
|
+
</ul>
|
307
|
+
|
308
|
+
|
309
|
+
</div><table class="source_code">
|
310
|
+
<tr>
|
311
|
+
<td>
|
312
|
+
<pre class="lines">
|
313
|
+
|
314
|
+
|
315
|
+
13
|
316
|
+
14
|
317
|
+
15
|
318
|
+
16
|
319
|
+
17
|
320
|
+
18
|
321
|
+
19
|
322
|
+
20
|
323
|
+
21
|
324
|
+
22
|
325
|
+
23
|
326
|
+
24
|
327
|
+
25
|
328
|
+
26
|
329
|
+
27
|
330
|
+
28
|
331
|
+
29
|
332
|
+
30
|
333
|
+
31
|
334
|
+
32
|
335
|
+
33
|
336
|
+
34
|
337
|
+
35
|
338
|
+
36
|
339
|
+
37
|
340
|
+
38
|
341
|
+
39
|
342
|
+
40
|
343
|
+
41
|
344
|
+
42
|
345
|
+
43
|
346
|
+
44
|
347
|
+
45
|
348
|
+
46
|
349
|
+
47
|
350
|
+
48
|
351
|
+
49
|
352
|
+
50
|
353
|
+
51
|
354
|
+
52
|
355
|
+
53
|
356
|
+
54
|
357
|
+
55
|
358
|
+
56
|
359
|
+
57
|
360
|
+
58
|
361
|
+
59
|
362
|
+
60
|
363
|
+
61
|
364
|
+
62
|
365
|
+
63
|
366
|
+
64
|
367
|
+
65
|
368
|
+
66
|
369
|
+
67
|
370
|
+
68
|
371
|
+
69
|
372
|
+
70
|
373
|
+
71
|
374
|
+
72
|
375
|
+
73
|
376
|
+
74
|
377
|
+
75
|
378
|
+
76
|
379
|
+
77
|
380
|
+
78
|
381
|
+
79
|
382
|
+
80
|
383
|
+
81
|
384
|
+
82
|
385
|
+
83
|
386
|
+
84
|
387
|
+
85
|
388
|
+
86
|
389
|
+
87
|
390
|
+
88
|
391
|
+
89
|
392
|
+
90
|
393
|
+
91
|
394
|
+
92</pre>
|
395
|
+
</td>
|
396
|
+
<td>
|
397
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/util.rb', line 13</span>
|
398
|
+
|
399
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_install_methods_in_model'>install_methods_in_model</span><span class='lparen'>(</span><span class='id identifier rubyid_model_class'>model_class</span><span class='comma'>,</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span>
|
400
|
+
<span class='label'>optional:</span> <span class='kw'>false</span><span class='comma'>,</span>
|
401
|
+
<span class='label'>model_readers:</span> <span class='kw'>true</span><span class='comma'>,</span>
|
402
|
+
<span class='label'>model_writers:</span> <span class='kw'>true</span><span class='comma'>,</span>
|
403
|
+
<span class='label'>model_scopes:</span> <span class='kw'>true</span><span class='comma'>,</span>
|
404
|
+
<span class='label'>model_methods:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
405
|
+
|
406
|
+
<span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span> <span class='op'>||=</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_classify'>classify</span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
407
|
+
<span class='id identifier rubyid_attribute_name'>attribute_name</span> <span class='op'>=</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
408
|
+
<span class='id identifier rubyid_attribute'>attribute</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Attribute.html" title="Anchormodel::Attribute (class)">Attribute</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Attribute.html#initialize-instance_method" title="Anchormodel::Attribute#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='comma'>,</span> <span class='id identifier rubyid_optional'>optional</span><span class='rparen'>)</span>
|
409
|
+
|
410
|
+
<span class='comment'># Mass configurations if model_methods was specfied
|
411
|
+
</span> <span class='kw'>unless</span> <span class='id identifier rubyid_model_methods'>model_methods</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
412
|
+
<span class='id identifier rubyid_model_readers'>model_readers</span> <span class='op'>=</span> <span class='id identifier rubyid_model_methods'>model_methods</span>
|
413
|
+
<span class='id identifier rubyid_model_writers'>model_writers</span> <span class='op'>=</span> <span class='id identifier rubyid_model_methods'>model_methods</span>
|
414
|
+
<span class='id identifier rubyid_model_scopes'>model_scopes</span> <span class='op'>=</span> <span class='id identifier rubyid_model_methods'>model_methods</span>
|
415
|
+
<span class='kw'>end</span>
|
416
|
+
|
417
|
+
<span class='comment'># Register attribute
|
418
|
+
</span> <span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_attributes'>anchormodel_attributes</span> <span class='op'>=</span> <span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_attributes'>anchormodel_attributes</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='lbrace'>{</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span> <span class='op'>=></span> <span class='id identifier rubyid_attribute'>attribute</span> <span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>
|
419
|
+
|
420
|
+
<span class='comment'># Add presence validation if required
|
421
|
+
</span> <span class='kw'>unless</span> <span class='id identifier rubyid_optional'>optional</span>
|
422
|
+
<span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_validates'>validates</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='label'>presence:</span> <span class='kw'>true</span>
|
423
|
+
<span class='kw'>end</span>
|
424
|
+
|
425
|
+
<span class='comment'># Make casting work
|
426
|
+
</span> <span class='comment'># Define serializer/deserializer
|
427
|
+
</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="ActiveModelTypeValueSingle.html#initialize-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_attribute'>attribute</span><span class='rparen'>)</span>
|
428
|
+
|
429
|
+
<span class='comment'># Overwrite reader to force building anchors at every retrieval
|
430
|
+
</span> <span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
431
|
+
<span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span><span class='period'>.</span><span class='id identifier rubyid_deserialize'>deserialize</span><span class='lparen'>(</span><span class='id identifier rubyid_read_attribute_before_type_cast'>read_attribute_before_type_cast</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
432
|
+
<span class='kw'>end</span>
|
433
|
+
|
434
|
+
<span class='comment'># Override writer to fail early when an invalid target value is specified
|
435
|
+
</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='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>=</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_new_value'>new_value</span><span class='op'>|</span>
|
436
|
+
<span class='id identifier rubyid_write_attribute'>write_attribute</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span><span class='period'>.</span><span class='id identifier rubyid_serialize'>serialize</span><span class='lparen'>(</span><span class='id identifier rubyid_new_value'>new_value</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
437
|
+
<span class='kw'>end</span>
|
438
|
+
|
439
|
+
<span class='comment'># Supply serializer and deserializer
|
440
|
+
</span> <span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_attribute'>attribute</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span>
|
441
|
+
|
442
|
+
<span class='comment'># Create ActiveRecord::Enum style reader directly in the model if asked to do so
|
443
|
+
</span> <span class='comment'># For a model User with anchormodel Role with keys :admin and :guest, this creates user.admin? and user.guest? (returning true iff role is admin/guest)
|
444
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid_model_readers'>model_readers</span>
|
445
|
+
<span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_entry'>entry</span><span class='op'>|</span>
|
446
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>?</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
447
|
+
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Anchormodel reader </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>? already defined for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>, add `model_readers: false` to `belongs_to_anchormodel :</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>`.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
448
|
+
<span class='kw'>end</span>
|
449
|
+
<span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>?</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
450
|
+
<span class='id identifier rubyid_public_send'>public_send</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='id identifier rubyid_entry'>entry</span>
|
451
|
+
<span class='kw'>end</span>
|
452
|
+
<span class='kw'>end</span>
|
453
|
+
<span class='kw'>end</span>
|
454
|
+
|
455
|
+
<span class='comment'># Create ActiveRecord::Enum style writer directly in the model if asked to do so
|
456
|
+
</span> <span class='comment'># For a model User with anchormodel Role with keys :admin and :guest, this creates user.admin! and user.guest! (setting the role to admin/guest)
|
457
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid_model_writers'>model_writers</span>
|
458
|
+
<span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_entry'>entry</span><span class='op'>|</span>
|
459
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
460
|
+
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Anchormodel writer </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>! already defined for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>, add `model_writers: false` to `belongs_to_anchormodel :</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>`.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
461
|
+
<span class='kw'>end</span>
|
462
|
+
<span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
463
|
+
<span class='id identifier rubyid_public_send'>public_send</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>=</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_entry'>entry</span><span class='rparen'>)</span>
|
464
|
+
<span class='kw'>end</span>
|
465
|
+
<span class='kw'>end</span>
|
466
|
+
<span class='kw'>end</span>
|
467
|
+
|
468
|
+
<span class='comment'># Create ActiveRecord::Enum style scope directly in the model class if asked to do so
|
469
|
+
</span> <span class='comment'># For a model User with anchormodel Role with keys :admin and :guest, this creates user.admin! and user.guest! (setting the role to admin/guest)
|
470
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid_model_scopes'>model_scopes</span>
|
471
|
+
<span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_entry'>entry</span><span class='op'>|</span>
|
472
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
473
|
+
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Anchormodel scope </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'> already defined for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>, add `model_scopes: false` to `belongs_to_anchormodel :</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>`.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
474
|
+
<span class='kw'>end</span>
|
475
|
+
<span class='id identifier rubyid_model_class'>model_class</span><span class='period'>.</span><span class='id identifier rubyid_scope'>scope</span><span class='lparen'>(</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='tlambda'>-></span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span> <span class='op'>=></span> <span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
476
|
+
<span class='kw'>end</span>
|
477
|
+
<span class='kw'>end</span>
|
478
|
+
<span class='kw'>end</span></pre>
|
479
|
+
</td>
|
480
|
+
</tr>
|
481
|
+
</table>
|
482
|
+
</div>
|
483
|
+
|
484
|
+
</div>
|
485
|
+
|
486
|
+
</div>
|
487
|
+
|
488
|
+
<div id="footer">
|
489
|
+
Generated on Wed Apr 24 17:01:46 2024 by
|
490
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
491
|
+
0.9.28 (ruby-3.2.2).
|
492
|
+
</div>
|
493
|
+
|
494
|
+
</div>
|
495
|
+
</body>
|
496
|
+
</html>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Anchormodel::Version
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.28
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -129,9 +129,9 @@
|
|
129
129
|
</div>
|
130
130
|
|
131
131
|
<div id="footer">
|
132
|
-
Generated on
|
132
|
+
Generated on Wed Apr 24 17:01:46 2024 by
|
133
133
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
134
|
-
0.9.
|
134
|
+
0.9.28 (ruby-3.2.2).
|
135
135
|
</div>
|
136
136
|
|
137
137
|
</div>
|
data/doc/Anchormodel.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Class: Anchormodel
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.28
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -95,7 +95,7 @@
|
|
95
95
|
<dl>
|
96
96
|
<dt>Defined in:</dt>
|
97
97
|
<dd>lib/anchormodel.rb<span class="defines">,<br />
|
98
|
-
lib/anchormodel/version.rb</span>
|
98
|
+
lib/anchormodel/version.rb,<br /> lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.rb</span>
|
99
99
|
</dd>
|
100
100
|
</dl>
|
101
101
|
|
@@ -116,7 +116,7 @@
|
|
116
116
|
<p class="children">
|
117
117
|
|
118
118
|
|
119
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Anchormodel/ModelMixin.html" title="Anchormodel::ModelMixin (module)">ModelMixin</a></span>, <span class='object_link'><a href="Anchormodel/Util.html" title="Anchormodel::Util (module)">Util</a></span>, <span class='object_link'><a href="Anchormodel/Version.html" title="Anchormodel::Version (module)">Version</a></span>
|
119
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Anchormodel/ModelMixin.html" title="Anchormodel::ModelMixin (module)">ModelMixin</a></span>, <span class='object_link'><a href="Anchormodel/SimpleFormInputs.html" title="Anchormodel::SimpleFormInputs (module)">SimpleFormInputs</a></span>, <span class='object_link'><a href="Anchormodel/Util.html" title="Anchormodel::Util (module)">Util</a></span>, <span class='object_link'><a href="Anchormodel/Version.html" title="Anchormodel::Version (module)">Version</a></span>
|
120
120
|
|
121
121
|
|
122
122
|
|
@@ -934,9 +934,9 @@
|
|
934
934
|
</div>
|
935
935
|
|
936
936
|
<div id="footer">
|
937
|
-
Generated on
|
937
|
+
Generated on Wed Apr 24 17:01:46 2024 by
|
938
938
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
939
|
-
0.9.
|
939
|
+
0.9.28 (ruby-3.2.2).
|
940
940
|
</div>
|
941
941
|
|
942
942
|
</div>
|