anchormodel 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,307 @@
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::ModelMixin
8
+
9
+ &mdash; 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::ModelMixin";
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 (M)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span>
41
+ &raquo;
42
+ <span class="title">ModelMixin</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::ModelMixin
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+ <dl>
73
+ <dt>Extended by:</dt>
74
+ <dd>ActiveSupport::Concern</dd>
75
+ </dl>
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+ <dl>
85
+ <dt>Defined in:</dt>
86
+ <dd>lib/anchormodel/model_mixin.rb</dd>
87
+ </dl>
88
+
89
+ </div>
90
+
91
+ <h2>Overview</h2><div class="docstring">
92
+ <div class="discussion">
93
+ <p>All Rails models making use of #belongs_to_anchormodel must include this mixin. Typically, it is included in <code>application_record.rb</code>.</p>
94
+
95
+
96
+ </div>
97
+ </div>
98
+ <div class="tags">
99
+
100
+
101
+ </div>
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+ <h2>
110
+ Class Method Summary
111
+ <small><a href="#" class="summary_toggle">collapse</a></small>
112
+ </h2>
113
+
114
+ <ul class="summary">
115
+
116
+ <li class="public ">
117
+ <span class="summary_signature">
118
+
119
+ <a href="#belongs_to_anchormodel-class_method" title="belongs_to_anchormodel (class method)">.<strong>belongs_to_anchormodel</strong>(attribute_name, anchor_class_name = nil, optional: false) &#x21d2; Object </a>
120
+
121
+
122
+
123
+ </span>
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ <span class="summary_desc"><div class='inline'><p>Creates an attribute linking to an Anchormodel.</p>
134
+ </div></span>
135
+
136
+ </li>
137
+
138
+
139
+ </ul>
140
+
141
+
142
+
143
+
144
+
145
+ <div id="class_method_details" class="method_details_list">
146
+ <h2>Class Method Details</h2>
147
+
148
+
149
+ <div class="method_details first">
150
+ <h3 class="signature first" id="belongs_to_anchormodel-class_method">
151
+
152
+ .<strong>belongs_to_anchormodel</strong>(attribute_name, anchor_class_name = nil, optional: false) &#x21d2; <tt>Object</tt>
153
+
154
+
155
+
156
+
157
+
158
+ </h3><div class="docstring">
159
+ <div class="discussion">
160
+ <p>Creates an attribute linking to an Anchormodel. The attribute should be
161
+ present in the DB and the column should be named the same as <code>attribute_name.</code></p>
162
+
163
+
164
+ </div>
165
+ </div>
166
+ <div class="tags">
167
+ <p class="tag_title">Parameters:</p>
168
+ <ul class="param">
169
+
170
+ <li>
171
+
172
+ <span class='name'>attribute_name</span>
173
+
174
+
175
+ <span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
176
+
177
+
178
+
179
+ &mdash;
180
+ <div class='inline'><p>The name and database column of the attribute</p>
181
+ </div>
182
+
183
+ </li>
184
+
185
+ <li>
186
+
187
+ <span class='name'>anchor_class_name</span>
188
+
189
+
190
+ <span class='type'>(<tt>String</tt>)</span>
191
+
192
+
193
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
194
+
195
+
196
+ &mdash;
197
+ <div class='inline'><p>Name of the Anchormodel class (omit if attribute <code>:foo_bar</code> holds an <code>Anchormodels::FooBar</code>)</p>
198
+ </div>
199
+
200
+ </li>
201
+
202
+ <li>
203
+
204
+ <span class='name'>optional</span>
205
+
206
+
207
+ <span class='type'>(<tt>Boolean</tt>)</span>
208
+
209
+
210
+ <em class="default">(defaults to: <tt>false</tt>)</em>
211
+
212
+
213
+ &mdash;
214
+ <div class='inline'><p>If true, a presence validation is added to the model.</p>
215
+ </div>
216
+
217
+ </li>
218
+
219
+ </ul>
220
+
221
+
222
+ </div><table class="source_code">
223
+ <tr>
224
+ <td>
225
+ <pre class="lines">
226
+
227
+
228
+ 16
229
+ 17
230
+ 18
231
+ 19
232
+ 20
233
+ 21
234
+ 22
235
+ 23
236
+ 24
237
+ 25
238
+ 26
239
+ 27
240
+ 28
241
+ 29
242
+ 30
243
+ 31
244
+ 32
245
+ 33
246
+ 34
247
+ 35
248
+ 36
249
+ 37
250
+ 38
251
+ 39
252
+ 40
253
+ 41
254
+ 42
255
+ 43
256
+ 44</pre>
257
+ </td>
258
+ <td>
259
+ <pre class="code"><span class="info file"># File 'lib/anchormodel/model_mixin.rb', line 16</span>
260
+
261
+ <span class='kw'>def</span> <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_anchor_class_name'>anchor_class_name</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>optional:</span> <span class='kw'>false</span><span class='rparen'>)</span>
262
+ <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>
263
+ <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_anchor_class_name'>anchor_class_name</span><span class='comma'>,</span> <span class='id identifier rubyid_optional'>optional</span><span class='rparen'>)</span>
264
+
265
+ <span class='comment'># Register attribute
266
+ </span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_attributes'>anchormodel_attributes</span> <span class='op'>=</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'>=&gt;</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>
267
+
268
+ <span class='comment'># Add presence validation if required
269
+ </span> <span class='kw'>unless</span> <span class='id identifier rubyid_optional'>optional</span>
270
+ <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>
271
+ <span class='kw'>end</span>
272
+
273
+ <span class='comment'># Make casting work
274
+ </span> <span class='comment'># Define serializer/deserializer
275
+ </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="ActiveModelTypeValue.html" title="Anchormodel::ActiveModelTypeValue (class)">ActiveModelTypeValue</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="ActiveModelTypeValue.html#initialize-instance_method" title="Anchormodel::ActiveModelTypeValue#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_attribute'>attribute</span><span class='rparen'>)</span>
276
+
277
+ <span class='comment'># Overwrite reader to force building anchors at every retrieval
278
+ </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>
279
+ <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'>read_attribute</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='rparen'>)</span><span class='rparen'>)</span>
280
+ <span class='kw'>end</span>
281
+
282
+ <span class='comment'># Override writer to fail early when an invalid target value is specified
283
+ </span> <span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</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'>&quot;</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>
284
+ <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>
285
+ <span class='kw'>end</span>
286
+
287
+ <span class='comment'># Supply serializer and deserializer
288
+ </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>
289
+ <span class='kw'>end</span></pre>
290
+ </td>
291
+ </tr>
292
+ </table>
293
+ </div>
294
+
295
+ </div>
296
+
297
+ </div>
298
+
299
+ <div id="footer">
300
+ Generated on Sat Dec 17 12:56:00 2022 by
301
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
302
+ 0.9.28 (ruby-3.0.4).
303
+ </div>
304
+
305
+ </div>
306
+ </body>
307
+ </html>
@@ -0,0 +1,195 @@
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::Version
8
+
9
+ &mdash; 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::Version";
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 (V)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span>
41
+ &raquo;
42
+ <span class="title">Version</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::Version
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/version.rb</dd>
82
+ </dl>
83
+
84
+ </div>
85
+
86
+ <div class="docstring">
87
+ <div class="discussion">
88
+
89
+
90
+ </div>
91
+ </div>
92
+ <div class="tags">
93
+
94
+
95
+ </div>
96
+
97
+ <h2>
98
+ Constant Summary
99
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
100
+ </h2>
101
+
102
+ <dl class="constants">
103
+
104
+ <dt id="MAJOR-constant" class="">MAJOR =
105
+ <div class="docstring">
106
+ <div class="discussion">
107
+
108
+
109
+ </div>
110
+ </div>
111
+ <div class="tags">
112
+
113
+
114
+ </div>
115
+ </dt>
116
+ <dd><pre class="code"><span class='int'>0</span></pre></dd>
117
+
118
+ <dt id="MINOR-constant" class="">MINOR =
119
+ <div class="docstring">
120
+ <div class="discussion">
121
+
122
+
123
+ </div>
124
+ </div>
125
+ <div class="tags">
126
+
127
+
128
+ </div>
129
+ </dt>
130
+ <dd><pre class="code"><span class='int'>0</span></pre></dd>
131
+
132
+ <dt id="PATCH-constant" class="">PATCH =
133
+ <div class="docstring">
134
+ <div class="discussion">
135
+
136
+
137
+ </div>
138
+ </div>
139
+ <div class="tags">
140
+
141
+
142
+ </div>
143
+ </dt>
144
+ <dd><pre class="code"><span class='int'>1</span></pre></dd>
145
+
146
+ <dt id="EDGE-constant" class="">EDGE =
147
+ <div class="docstring">
148
+ <div class="discussion">
149
+
150
+
151
+ </div>
152
+ </div>
153
+ <div class="tags">
154
+
155
+
156
+ </div>
157
+ </dt>
158
+ <dd><pre class="code"><span class='kw'>true</span></pre></dd>
159
+
160
+ <dt id="LABEL-constant" class="">LABEL =
161
+ <div class="docstring">
162
+ <div class="discussion">
163
+
164
+
165
+ </div>
166
+ </div>
167
+ <div class="tags">
168
+
169
+
170
+ </div>
171
+ </dt>
172
+ <dd><pre class="code"><span class='lbracket'>[</span><span class='const'><span class='object_link'><a href="#MAJOR-constant" title="Anchormodel::Version::MAJOR (constant)">MAJOR</a></span></span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="#MINOR-constant" title="Anchormodel::Version::MINOR (constant)">MINOR</a></span></span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="#PATCH-constant" title="Anchormodel::Version::PATCH (constant)">PATCH</a></span></span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="#EDGE-constant" title="Anchormodel::Version::EDGE (constant)">EDGE</a></span></span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>edge</span><span class='tstring_end'>&#39;</span></span> <span class='op'>:</span> <span class='kw'>nil</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>.</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span></pre></dd>
173
+
174
+ </dl>
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+ </div>
186
+
187
+ <div id="footer">
188
+ Generated on Sat Dec 17 12:56:00 2022 by
189
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
190
+ 0.9.28 (ruby-3.0.4).
191
+ </div>
192
+
193
+ </div>
194
+ </body>
195
+ </html>