db-struct 0.1.0
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.
- checksums.yaml +7 -0
- data/README.md +125 -0
- data/Rakefile +35 -0
- data/db-struct.gemspec +37 -0
- data/doc/DBStruct/BogoHash.html +1384 -0
- data/doc/DBStruct/ErrorHelpers.html +288 -0
- data/doc/DBStruct/Failure.html +139 -0
- data/doc/DBStruct/FieldError.html +143 -0
- data/doc/DBStruct/MissingRowError.html +143 -0
- data/doc/DBStruct/TypeError.html +143 -0
- data/doc/DBStruct.html +1652 -0
- data/doc/_index.html +189 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +503 -0
- data/doc/file.README.html +187 -0
- data/doc/file_list.html +59 -0
- data/doc/frames.html +22 -0
- data/doc/index.html +187 -0
- data/doc/js/app.js +344 -0
- data/doc/js/full_list.js +242 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +342 -0
- data/doc/top-level-namespace.html +110 -0
- data/gem.deps.rb +7 -0
- data/lib/dbstruct.rb +29 -0
- data/lib/internal/bogohash.rb +226 -0
- data/lib/internal/dbstruct_base.rb +144 -0
- data/lib/internal/dbstruct_class.rb +301 -0
- data/lib/internal/error.rb +44 -0
- data/lib/internal/util.rb +11 -0
- data/spec/dbstruct_spec.rb +452 -0
- data/spec/spec_helper.rb +48 -0
- metadata +138 -0
data/doc/DBStruct.html
ADDED
@@ -0,0 +1,1652 @@
|
|
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: DBStruct
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.37
|
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 = "DBStruct";
|
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 (D)</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">DBStruct</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: DBStruct
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
<dl>
|
70
|
+
<dt>Inherits:</dt>
|
71
|
+
<dd>
|
72
|
+
<span class="inheritName">Object</span>
|
73
|
+
|
74
|
+
<ul class="fullTree">
|
75
|
+
<li>Object</li>
|
76
|
+
|
77
|
+
<li class="next">DBStruct</li>
|
78
|
+
|
79
|
+
</ul>
|
80
|
+
<a href="#" class="inheritanceTree">show all</a>
|
81
|
+
|
82
|
+
</dd>
|
83
|
+
</dl>
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
<dl>
|
89
|
+
<dt>Extended by:</dt>
|
90
|
+
<dd><span class='object_link'><a href="DBStruct/ErrorHelpers.html" title="DBStruct::ErrorHelpers (module)">ErrorHelpers</a></span></dd>
|
91
|
+
</dl>
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
<dl>
|
96
|
+
<dt>Includes:</dt>
|
97
|
+
<dd><span class='object_link'><a href="DBStruct/ErrorHelpers.html" title="DBStruct::ErrorHelpers (module)">ErrorHelpers</a></span></dd>
|
98
|
+
</dl>
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
<dl>
|
106
|
+
<dt>Defined in:</dt>
|
107
|
+
<dd>lib/dbstruct.rb<span class="defines">,<br />
|
108
|
+
lib/internal/util.rb,<br /> lib/internal/error.rb,<br /> lib/internal/dbstruct_base.rb</span>
|
109
|
+
</dd>
|
110
|
+
</dl>
|
111
|
+
|
112
|
+
</div>
|
113
|
+
|
114
|
+
<h2>Overview</h2><div class="docstring">
|
115
|
+
<div class="discussion">
|
116
|
+
|
117
|
+
<p>‘DBStruct` presents a (SQLite3) database table in a way that closely mimics a Ruby `Hash` of `Struct` objects.</p>
|
118
|
+
|
119
|
+
<p>This is an abstract base class. To use it, you create a subclass using the ‘with` method and define the fields to be used. This also associates the new class with a `Sequel` dataset.</p>
|
120
|
+
|
121
|
+
<p>Subinstances behave similarly to Ruby’s ‘Struct` class. However, setting or reading a value accesses the corresponding database row.</p>
|
122
|
+
|
123
|
+
<p>Each object also knows its database row ID, an integer that can be used to look up this object. If a subinstance outlives its database row, attempting to access the fields will raise a <span class='object_link'><a href="DBStruct/MissingRowError.html" title="DBStruct::MissingRowError (class)">MissingRowError</a></span>. You can use methods <span class='object_link'><a href="#present%3F-instance_method" title="DBStruct#present? (method)">#present?</a></span> or <span class='object_link'><a href="#deleted%3F-instance_method" title="DBStruct#deleted? (method)">#deleted?</a></span> to test if this has happened.</p>
|
124
|
+
|
125
|
+
|
126
|
+
</div>
|
127
|
+
</div>
|
128
|
+
<div class="tags">
|
129
|
+
|
130
|
+
|
131
|
+
</div><h2>Defined Under Namespace</h2>
|
132
|
+
<p class="children">
|
133
|
+
|
134
|
+
|
135
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="DBStruct/ErrorHelpers.html" title="DBStruct::ErrorHelpers (module)">ErrorHelpers</a></span>
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="DBStruct/BogoHash.html" title="DBStruct::BogoHash (class)">BogoHash</a></span>, <span class='object_link'><a href="DBStruct/Failure.html" title="DBStruct::Failure (class)">Failure</a></span>, <span class='object_link'><a href="DBStruct/FieldError.html" title="DBStruct::FieldError (class)">FieldError</a></span>, <span class='object_link'><a href="DBStruct/MissingRowError.html" title="DBStruct::MissingRowError (class)">MissingRowError</a></span>, <span class='object_link'><a href="DBStruct/TypeError.html" title="DBStruct::TypeError (class)">TypeError</a></span>
|
140
|
+
|
141
|
+
|
142
|
+
</p>
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
<h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
|
148
|
+
<ul class="summary">
|
149
|
+
|
150
|
+
<li class="public ">
|
151
|
+
<span class="summary_signature">
|
152
|
+
|
153
|
+
<a href="#rowid-instance_method" title="#rowid (instance method)">#<strong>rowid</strong> ⇒ Object </a>
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
</span>
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
<span class="note title readonly">readonly</span>
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
<span class="summary_desc"><div class='inline'>
|
173
|
+
<p>Returns the numeric Row ID that is used as the primary key for this row in both the database and any <span class='object_link'><a href="DBStruct/BogoHash.html" title="DBStruct::BogoHash (class)">BogoHash</a></span> instances that may contain it.</p>
|
174
|
+
</div></span>
|
175
|
+
|
176
|
+
</li>
|
177
|
+
|
178
|
+
|
179
|
+
</ul>
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
<h2>
|
186
|
+
Class Method Summary
|
187
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
188
|
+
</h2>
|
189
|
+
|
190
|
+
<ul class="summary">
|
191
|
+
|
192
|
+
<li class="public ">
|
193
|
+
<span class="summary_signature">
|
194
|
+
|
195
|
+
<a href="#items-class_method" title="items (class method)">.<strong>items</strong>(*selectors) ⇒ Object </a>
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
</span>
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
<span class="summary_desc"><div class='inline'>
|
210
|
+
<p>Return a ‘DBStruct::BogoHash` containing some or all of the items in this table.</p>
|
211
|
+
</div></span>
|
212
|
+
|
213
|
+
</li>
|
214
|
+
|
215
|
+
|
216
|
+
<li class="public ">
|
217
|
+
<span class="summary_signature">
|
218
|
+
|
219
|
+
<a href="#transaction-class_method" title="transaction (class method)">.<strong>transaction</strong>(*args, **kwargs, &block) ⇒ Object </a>
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
</span>
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
<span class="summary_desc"><div class='inline'>
|
234
|
+
<p>Evaluates ‘block` within a transaction.</p>
|
235
|
+
</div></span>
|
236
|
+
|
237
|
+
</li>
|
238
|
+
|
239
|
+
|
240
|
+
<li class="public ">
|
241
|
+
<span class="summary_signature">
|
242
|
+
|
243
|
+
<a href="#where-class_method" title="where (class method)">.<strong>where</strong>(*cond, **kwcond, &block) ⇒ Object </a>
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
</span>
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
<span class="summary_desc"><div class='inline'>
|
258
|
+
<p>Convenience method; equivalent to self.items.where(…).</p>
|
259
|
+
</div></span>
|
260
|
+
|
261
|
+
</li>
|
262
|
+
|
263
|
+
|
264
|
+
<li class="public ">
|
265
|
+
<span class="summary_signature">
|
266
|
+
|
267
|
+
<a href="#with-class_method" title="with (class method)">.<strong>with</strong>(db, name, &body) ⇒ Class </a>
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
</span>
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
<span class="summary_desc"><div class='inline'>
|
282
|
+
<p>Define a concrete DBStruct subclass and create the corresponding table if needed.</p>
|
283
|
+
</div></span>
|
284
|
+
|
285
|
+
</li>
|
286
|
+
|
287
|
+
|
288
|
+
</ul>
|
289
|
+
|
290
|
+
<h2>
|
291
|
+
Instance Method Summary
|
292
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
293
|
+
</h2>
|
294
|
+
|
295
|
+
<ul class="summary">
|
296
|
+
|
297
|
+
<li class="public ">
|
298
|
+
<span class="summary_signature">
|
299
|
+
|
300
|
+
<a href="#[]-instance_method" title="#[] (instance method)">#<strong>[]</strong>(field) ⇒ Object </a>
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
</span>
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
<span class="summary_desc"><div class='inline'>
|
315
|
+
<p>Equivalent to ‘get_field`.</p>
|
316
|
+
</div></span>
|
317
|
+
|
318
|
+
</li>
|
319
|
+
|
320
|
+
|
321
|
+
<li class="public ">
|
322
|
+
<span class="summary_signature">
|
323
|
+
|
324
|
+
<a href="#[]=-instance_method" title="#[]= (instance method)">#<strong>[]=</strong>(field, value) ⇒ Object </a>
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
</span>
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
<span class="summary_desc"><div class='inline'>
|
339
|
+
<p>Equivalent to ‘set_field`.</p>
|
340
|
+
</div></span>
|
341
|
+
|
342
|
+
</li>
|
343
|
+
|
344
|
+
|
345
|
+
<li class="public ">
|
346
|
+
<span class="summary_signature">
|
347
|
+
|
348
|
+
<a href="#deleted%3F-instance_method" title="#deleted? (instance method)">#<strong>deleted?</strong> ⇒ Boolean </a>
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
</span>
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
<span class="summary_desc"><div class='inline'>
|
363
|
+
<p>Test if the database row associated with ‘self` no longer exists.</p>
|
364
|
+
</div></span>
|
365
|
+
|
366
|
+
</li>
|
367
|
+
|
368
|
+
|
369
|
+
<li class="public ">
|
370
|
+
<span class="summary_signature">
|
371
|
+
|
372
|
+
<a href="#eql%3F-instance_method" title="#eql? (instance method)">#<strong>eql?</strong>(other) ⇒ Boolean </a>
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
(also: #==)
|
377
|
+
|
378
|
+
</span>
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
<span class="summary_desc"><div class='inline'>
|
389
|
+
<p>Test for equality.</p>
|
390
|
+
</div></span>
|
391
|
+
|
392
|
+
</li>
|
393
|
+
|
394
|
+
|
395
|
+
<li class="public ">
|
396
|
+
<span class="summary_signature">
|
397
|
+
|
398
|
+
<a href="#get_field-instance_method" title="#get_field (instance method)">#<strong>get_field</strong>(name) ⇒ Object </a>
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
</span>
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
<span class="summary_desc"><div class='inline'>
|
413
|
+
<p>Sets the value of the field named by ‘field` to the given value.</p>
|
414
|
+
</div></span>
|
415
|
+
|
416
|
+
</li>
|
417
|
+
|
418
|
+
|
419
|
+
<li class="public ">
|
420
|
+
<span class="summary_signature">
|
421
|
+
|
422
|
+
<a href="#hash-instance_method" title="#hash (instance method)">#<strong>hash</strong> ⇒ Object </a>
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
</span>
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
<span class="summary_desc"><div class='inline'>
|
437
|
+
<p>Return a hash; here because we’ve also overridden <span class='object_link'><a href="#eql%3F-instance_method" title="DBStruct#eql? (method)">#eql?</a></span>.</p>
|
438
|
+
</div></span>
|
439
|
+
|
440
|
+
</li>
|
441
|
+
|
442
|
+
|
443
|
+
<li class="public ">
|
444
|
+
<span class="summary_signature">
|
445
|
+
|
446
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(_id: nil, **kwargs) ⇒ DBStruct </a>
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
</span>
|
451
|
+
|
452
|
+
|
453
|
+
<span class="note title constructor">constructor</span>
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
<span class="summary_desc"><div class='inline'>
|
463
|
+
<p>Creates a new instance of class, creates the corresponding database row and initializes the fields.</p>
|
464
|
+
</div></span>
|
465
|
+
|
466
|
+
</li>
|
467
|
+
|
468
|
+
|
469
|
+
<li class="public ">
|
470
|
+
<span class="summary_signature">
|
471
|
+
|
472
|
+
<a href="#inspect-instance_method" title="#inspect (instance method)">#<strong>inspect</strong> ⇒ Object </a>
|
473
|
+
|
474
|
+
|
475
|
+
|
476
|
+
(also: #to_s)
|
477
|
+
|
478
|
+
</span>
|
479
|
+
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
|
488
|
+
<span class="summary_desc"><div class='inline'>
|
489
|
+
<p>Return a human-friendly description.</p>
|
490
|
+
</div></span>
|
491
|
+
|
492
|
+
</li>
|
493
|
+
|
494
|
+
|
495
|
+
<li class="public ">
|
496
|
+
<span class="summary_signature">
|
497
|
+
|
498
|
+
<a href="#present%3F-instance_method" title="#present? (instance method)">#<strong>present?</strong> ⇒ Boolean </a>
|
499
|
+
|
500
|
+
|
501
|
+
|
502
|
+
</span>
|
503
|
+
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
|
512
|
+
<span class="summary_desc"><div class='inline'>
|
513
|
+
<p>Test if the database row associated with ‘self` still exists.</p>
|
514
|
+
</div></span>
|
515
|
+
|
516
|
+
</li>
|
517
|
+
|
518
|
+
|
519
|
+
<li class="public ">
|
520
|
+
<span class="summary_signature">
|
521
|
+
|
522
|
+
<a href="#set_field-instance_method" title="#set_field (instance method)">#<strong>set_field</strong>(name, value) ⇒ Object </a>
|
523
|
+
|
524
|
+
|
525
|
+
|
526
|
+
</span>
|
527
|
+
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
|
536
|
+
<span class="summary_desc"><div class='inline'>
|
537
|
+
<p>Retrieve the value of the field named by symbol ‘field`.</p>
|
538
|
+
</div></span>
|
539
|
+
|
540
|
+
</li>
|
541
|
+
|
542
|
+
|
543
|
+
<li class="public ">
|
544
|
+
<span class="summary_signature">
|
545
|
+
|
546
|
+
<a href="#set_fields-instance_method" title="#set_fields (instance method)">#<strong>set_fields</strong>(**kwargs) ⇒ Object </a>
|
547
|
+
|
548
|
+
|
549
|
+
|
550
|
+
</span>
|
551
|
+
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
|
560
|
+
<span class="summary_desc"><div class='inline'>
|
561
|
+
<p>Set zero or more fields at once.</p>
|
562
|
+
</div></span>
|
563
|
+
|
564
|
+
</li>
|
565
|
+
|
566
|
+
|
567
|
+
<li class="public ">
|
568
|
+
<span class="summary_signature">
|
569
|
+
|
570
|
+
<a href="#to_a-instance_method" title="#to_a (instance method)">#<strong>to_a</strong> ⇒ Object </a>
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
</span>
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
|
584
|
+
<span class="summary_desc"><div class='inline'>
|
585
|
+
<p>Return the contents as an array of pairs of key and value.</p>
|
586
|
+
</div></span>
|
587
|
+
|
588
|
+
</li>
|
589
|
+
|
590
|
+
|
591
|
+
<li class="public ">
|
592
|
+
<span class="summary_signature">
|
593
|
+
|
594
|
+
<a href="#to_h-instance_method" title="#to_h (instance method)">#<strong>to_h</strong> ⇒ Object </a>
|
595
|
+
|
596
|
+
|
597
|
+
|
598
|
+
</span>
|
599
|
+
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
|
606
|
+
|
607
|
+
|
608
|
+
<span class="summary_desc"><div class='inline'>
|
609
|
+
<p>Return the contents as a hash.</p>
|
610
|
+
</div></span>
|
611
|
+
|
612
|
+
</li>
|
613
|
+
|
614
|
+
|
615
|
+
</ul>
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
<h3 class="inherited">Methods included from <span class='object_link'><a href="DBStruct/ErrorHelpers.html" title="DBStruct::ErrorHelpers (module)">ErrorHelpers</a></span></h3>
|
628
|
+
<p class="inherited"><span class='object_link'><a href="DBStruct/ErrorHelpers.html#check-instance_method" title="DBStruct::ErrorHelpers#check (method)">check</a></span>, <span class='object_link'><a href="DBStruct/ErrorHelpers.html#oops-instance_method" title="DBStruct::ErrorHelpers#oops (method)">oops</a></span></p>
|
629
|
+
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
|
634
|
+
|
635
|
+
<div id="constructor_details" class="method_details_list">
|
636
|
+
<h2>Constructor Details</h2>
|
637
|
+
|
638
|
+
<div class="method_details first">
|
639
|
+
<h3 class="signature first" id="initialize-instance_method">
|
640
|
+
|
641
|
+
#<strong>initialize</strong>(_id: nil, **kwargs) ⇒ <tt><span class='object_link'><a href="" title="DBStruct (class)">DBStruct</a></span></tt>
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
</h3><div class="docstring">
|
648
|
+
<div class="discussion">
|
649
|
+
|
650
|
+
<p>Creates a new instance of class, creates the corresponding database row and initializes the fields. This only works if the class is a subclass of ‘DBStruct`; `DBStruct` itself cannot be instantiated.</p>
|
651
|
+
|
652
|
+
<p>If keyword arguments are given, they must correspond to the names of the fields and have values of the correct type or nil. Omitted arguments are equivalent to nil.</p>
|
653
|
+
|
654
|
+
<p>The keyword argument ‘_id:` is intended for internal use only and should not be used.</p>
|
655
|
+
|
656
|
+
|
657
|
+
</div>
|
658
|
+
</div>
|
659
|
+
<div class="tags">
|
660
|
+
|
661
|
+
|
662
|
+
</div><table class="source_code">
|
663
|
+
<tr>
|
664
|
+
<td>
|
665
|
+
<pre class="lines">
|
666
|
+
|
667
|
+
|
668
|
+
20
|
669
|
+
21
|
670
|
+
22
|
671
|
+
23
|
672
|
+
24
|
673
|
+
25
|
674
|
+
26
|
675
|
+
27
|
676
|
+
28
|
677
|
+
29
|
678
|
+
30
|
679
|
+
31
|
680
|
+
32
|
681
|
+
33
|
682
|
+
34
|
683
|
+
35
|
684
|
+
36
|
685
|
+
37
|
686
|
+
38
|
687
|
+
39
|
688
|
+
40
|
689
|
+
41</pre>
|
690
|
+
</td>
|
691
|
+
<td>
|
692
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 20</span>
|
693
|
+
|
694
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>_id:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='comment'># Internal use only!
|
695
|
+
</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
|
696
|
+
|
697
|
+
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Attempted to instantiate abstract class DBStruct.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
|
698
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="" title="DBStruct (class)">DBStruct</a></span></span>
|
699
|
+
<span class='rbrace'>}</span>
|
700
|
+
|
701
|
+
<span class='ivar'>@rowid</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
702
|
+
|
703
|
+
<span class='comment'># Case 1: existing row
|
704
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid__id'>_id</span>
|
705
|
+
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Using '_id' with other arguments!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_kwargs'>kwargs</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span> <span class='rbrace'>}</span>
|
706
|
+
|
707
|
+
<span class='ivar'>@rowid</span> <span class='op'>=</span> <span class='id identifier rubyid__id'>_id</span>
|
708
|
+
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Row '</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid__id'>_id</span><span class='embexpr_end'>}</span><span class='tstring_content'>' does not exist!</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="DBStruct/MissingRowError.html" title="DBStruct::MissingRowError (class)">MissingRowError</a></span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_present?'>present?</span> <span class='rbrace'>}</span>
|
709
|
+
|
710
|
+
<span class='kw'>return</span>
|
711
|
+
<span class='kw'>end</span>
|
712
|
+
|
713
|
+
<span class='ivar'>@rowid</span> <span class='op'>=</span> <span class='id identifier rubyid_dataset'>dataset</span><span class='lparen'>(</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_insert'>insert</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
714
|
+
<span class='id identifier rubyid_set_fields'>set_fields</span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
|
715
|
+
<span class='kw'>end</span></pre>
|
716
|
+
</td>
|
717
|
+
</tr>
|
718
|
+
</table>
|
719
|
+
</div>
|
720
|
+
|
721
|
+
</div>
|
722
|
+
|
723
|
+
<div id="instance_attr_details" class="attr_details">
|
724
|
+
<h2>Instance Attribute Details</h2>
|
725
|
+
|
726
|
+
|
727
|
+
<span id=""></span>
|
728
|
+
<div class="method_details first">
|
729
|
+
<h3 class="signature first" id="rowid-instance_method">
|
730
|
+
|
731
|
+
#<strong>rowid</strong> ⇒ <tt>Object</tt> <span class="extras">(readonly)</span>
|
732
|
+
|
733
|
+
|
734
|
+
|
735
|
+
|
736
|
+
|
737
|
+
</h3><div class="docstring">
|
738
|
+
<div class="discussion">
|
739
|
+
|
740
|
+
<p>Returns the numeric Row ID that is used as the primary key for this row in both the database and any <span class='object_link'><a href="DBStruct/BogoHash.html" title="DBStruct::BogoHash (class)">BogoHash</a></span> instances that may contain it.</p>
|
741
|
+
|
742
|
+
|
743
|
+
</div>
|
744
|
+
</div>
|
745
|
+
<div class="tags">
|
746
|
+
|
747
|
+
|
748
|
+
</div><table class="source_code">
|
749
|
+
<tr>
|
750
|
+
<td>
|
751
|
+
<pre class="lines">
|
752
|
+
|
753
|
+
|
754
|
+
7
|
755
|
+
8
|
756
|
+
9</pre>
|
757
|
+
</td>
|
758
|
+
<td>
|
759
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 7</span>
|
760
|
+
|
761
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_rowid'>rowid</span>
|
762
|
+
<span class='ivar'>@rowid</span>
|
763
|
+
<span class='kw'>end</span></pre>
|
764
|
+
</td>
|
765
|
+
</tr>
|
766
|
+
</table>
|
767
|
+
</div>
|
768
|
+
|
769
|
+
</div>
|
770
|
+
|
771
|
+
|
772
|
+
<div id="class_method_details" class="method_details_list">
|
773
|
+
<h2>Class Method Details</h2>
|
774
|
+
|
775
|
+
|
776
|
+
<div class="method_details first">
|
777
|
+
<h3 class="signature first" id="items-class_method">
|
778
|
+
|
779
|
+
.<strong>items</strong>(*selectors) ⇒ <tt>Object</tt>
|
780
|
+
|
781
|
+
|
782
|
+
|
783
|
+
|
784
|
+
|
785
|
+
</h3><div class="docstring">
|
786
|
+
<div class="discussion">
|
787
|
+
|
788
|
+
<p>Return a ‘DBStruct::BogoHash` containing some or all of the items in this table. If arguments are given, they must correspond to `group` fields. In that case, the returned `BogoHash` contains only those items whose values in those field match the argument.</p>
|
789
|
+
|
790
|
+
<p>(This is roughly equivalent to using the Sequel ‘where` method to narrow a Dataset.)</p>
|
791
|
+
|
792
|
+
<p>So</p>
|
793
|
+
|
794
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Books</span><span class='period'>.</span><span class='id identifier rubyid_items'>items</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>non-fiction</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>dragons</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
795
|
+
</code></pre>
|
796
|
+
|
797
|
+
<p>will return a ‘BogoHash` that contains only entries whose first group field has the value “non-fiction” and whose second group field has the value 42. </p>
|
798
|
+
|
799
|
+
<p>‘nil` arguments are treated as wildcards and will match everything. Thus,</p>
|
800
|
+
|
801
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Books</span><span class='period'>.</span><span class='id identifier rubyid_items'>items</span><span class='lparen'>(</span><span class='kw'>nil</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>dragons</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
802
|
+
</code></pre>
|
803
|
+
|
804
|
+
<p>will return all items whose second group matches “dragons”.</p>
|
805
|
+
|
806
|
+
|
807
|
+
</div>
|
808
|
+
</div>
|
809
|
+
<div class="tags">
|
810
|
+
|
811
|
+
|
812
|
+
</div><table class="source_code">
|
813
|
+
<tr>
|
814
|
+
<td>
|
815
|
+
<pre class="lines">
|
816
|
+
|
817
|
+
|
818
|
+
249
|
819
|
+
250
|
820
|
+
251
|
821
|
+
252
|
822
|
+
253
|
823
|
+
254
|
824
|
+
255
|
825
|
+
256
|
826
|
+
257
|
827
|
+
258
|
828
|
+
259
|
829
|
+
260</pre>
|
830
|
+
</td>
|
831
|
+
<td>
|
832
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_class.rb', line 249</span>
|
833
|
+
|
834
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_items'>items</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_selectors'>selectors</span><span class='rparen'>)</span>
|
835
|
+
<span class='id identifier rubyid_check_not_base_class'>check_not_base_class</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
836
|
+
|
837
|
+
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Too many group specifiers!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
|
838
|
+
<span class='id identifier rubyid_selectors'>selectors</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'><=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_groups'>groups</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span>
|
839
|
+
<span class='rbrace'>}</span>
|
840
|
+
|
841
|
+
<span class='id identifier rubyid_ds'>ds</span> <span class='op'>=</span> <span class='id identifier rubyid_get_group_selection_dataset'>get_group_selection_dataset</span><span class='lparen'>(</span><span class='id identifier rubyid_selectors'>selectors</span><span class='rparen'>)</span> <span class='kw'>or</span>
|
842
|
+
<span class='kw'>return</span> <span class='kw'>nil</span>
|
843
|
+
|
844
|
+
<span class='kw'>return</span> <span class='const'><span class='object_link'><a href="" title="DBStruct (class)">DBStruct</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBStruct/BogoHash.html" title="DBStruct::BogoHash (class)">BogoHash</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_ds'>ds</span><span class='comma'>,</span> <span class='id identifier rubyid_selectors'>selectors</span><span class='rparen'>)</span>
|
845
|
+
<span class='kw'>end</span></pre>
|
846
|
+
</td>
|
847
|
+
</tr>
|
848
|
+
</table>
|
849
|
+
</div>
|
850
|
+
|
851
|
+
<div class="method_details ">
|
852
|
+
<h3 class="signature " id="transaction-class_method">
|
853
|
+
|
854
|
+
.<strong>transaction</strong>(*args, **kwargs, &block) ⇒ <tt>Object</tt>
|
855
|
+
|
856
|
+
|
857
|
+
|
858
|
+
|
859
|
+
|
860
|
+
</h3><div class="docstring">
|
861
|
+
<div class="discussion">
|
862
|
+
|
863
|
+
<p>Evaluates ‘block` within a transaction. These can be safely nested and will (usually) roll back if an exception occurs in the block.</p>
|
864
|
+
|
865
|
+
<p>This is trivial convenience wrapper around ‘Sequel::Database#transaction`; see its documentation for details.</p>
|
866
|
+
|
867
|
+
|
868
|
+
</div>
|
869
|
+
</div>
|
870
|
+
<div class="tags">
|
871
|
+
|
872
|
+
|
873
|
+
</div><table class="source_code">
|
874
|
+
<tr>
|
875
|
+
<td>
|
876
|
+
<pre class="lines">
|
877
|
+
|
878
|
+
|
879
|
+
289
|
880
|
+
290</pre>
|
881
|
+
</td>
|
882
|
+
<td>
|
883
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_class.rb', line 289</span>
|
884
|
+
|
885
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_transaction'>transaction</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='op'>=</span>
|
886
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_db'>db</span><span class='period'>.</span><span class='id identifier rubyid_transaction'>transaction</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span></pre>
|
887
|
+
</td>
|
888
|
+
</tr>
|
889
|
+
</table>
|
890
|
+
</div>
|
891
|
+
|
892
|
+
<div class="method_details ">
|
893
|
+
<h3 class="signature " id="where-class_method">
|
894
|
+
|
895
|
+
.<strong>where</strong>(*cond, **kwcond, &block) ⇒ <tt>Object</tt>
|
896
|
+
|
897
|
+
|
898
|
+
|
899
|
+
|
900
|
+
|
901
|
+
</h3><div class="docstring">
|
902
|
+
<div class="discussion">
|
903
|
+
|
904
|
+
<p>Convenience method; equivalent to self.items.where(…).</p>
|
905
|
+
|
906
|
+
<p>See <span class='object_link'><a href="DBStruct/BogoHash.html#where-instance_method" title="DBStruct::BogoHash#where (method)">DBStruct::BogoHash#where</a></span> for details.</p>
|
907
|
+
|
908
|
+
|
909
|
+
</div>
|
910
|
+
</div>
|
911
|
+
<div class="tags">
|
912
|
+
|
913
|
+
|
914
|
+
</div><table class="source_code">
|
915
|
+
<tr>
|
916
|
+
<td>
|
917
|
+
<pre class="lines">
|
918
|
+
|
919
|
+
|
920
|
+
278
|
921
|
+
279</pre>
|
922
|
+
</td>
|
923
|
+
<td>
|
924
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_class.rb', line 278</span>
|
925
|
+
|
926
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_cond'>cond</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwcond'>kwcond</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='op'>=</span>
|
927
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_items'>items</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_cond'>cond</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwcond'>kwcond</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span></pre>
|
928
|
+
</td>
|
929
|
+
</tr>
|
930
|
+
</table>
|
931
|
+
</div>
|
932
|
+
|
933
|
+
<div class="method_details ">
|
934
|
+
<h3 class="signature " id="with-class_method">
|
935
|
+
|
936
|
+
.<strong>with</strong>(db, name, &body) ⇒ <tt>Class</tt>
|
937
|
+
|
938
|
+
|
939
|
+
|
940
|
+
|
941
|
+
|
942
|
+
</h3><div class="docstring">
|
943
|
+
<div class="discussion">
|
944
|
+
|
945
|
+
<p>Define a concrete DBStruct subclass and create the corresponding table if needed.</p>
|
946
|
+
|
947
|
+
<p>The database and table are both accessed via Sequel classes (‘Sequel::Database` and `Sequel::Dataset` respectively) and so are subject to their constraints and abilities. In addition, the underlying database <strong>must</strong> be SQLite.</p>
|
948
|
+
|
949
|
+
<p>The new class is unnamed unless assigned to a global constant.</p>
|
950
|
+
|
951
|
+
<p>If the corresponding table does not exist, it is created from the class’s layout.</p>
|
952
|
+
|
953
|
+
<p>If a table with a matching name already exists, it is assumed to have previously been created by this method with this layout. While there is some rudimentary consistency checking done to ensure that the expected columns are there, it is not exhaustive. If it is possible for an incompatible table with the same name to appear (e.g. due to version upgrades), you will need to use other mechanisms to detect this.</p>
|
954
|
+
|
955
|
+
<p>The new class’s layout (and corresponding table) is defined via the attached block. It is evaluated via ‘class_eval` and so may be used to define methods for the new subclass. In addition, it provides a minimal DSL for defining fields (i.e. database columns).</p>
|
956
|
+
|
957
|
+
<p>The DSL adds two methods, ‘field` and `group`:</p>
|
958
|
+
|
959
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_field'>field</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span>
|
960
|
+
<span class='id identifier rubyid_group'>group</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span>
|
961
|
+
</code></pre>
|
962
|
+
|
963
|
+
<p>‘field` declares a new field and matching database column. It will create a database column named `name` with matching getter and setter methods that will access it. `name` must be a `Symbol`.</p>
|
964
|
+
|
965
|
+
<p>Note that ‘name` <strong>must</strong> begin with a lower-case letter. This is a limitation imposed by `DBStruct` itself so that can add extra internal fields. (Currently, the only one used is called `_id`; this is the numeric primary key used as a unique row ID.)</p>
|
966
|
+
|
967
|
+
<p>‘type` may be any Ruby type that Sequel knows how to convert to a database column (see the link below). Unlike Sequel, DBStruct requires actual Ruby classes and will ensure that only objects of that specific type (or `nil`) may be stored in that field. This is enforced by the setter methods. (Exception: `TrueClass` and `FalseClass` are interchangeable.)</p>
|
968
|
+
|
969
|
+
<p>‘group` is like `field` except that the field is also treated as a category when used to select subsets with arguments to <span class='object_link'><a href="#items-class_method" title="DBStruct.items (method)">items</a></span>. `group` calls may be freely intermixed with `field` calls; however, their order is significant. Positional argumetns to `items` must match the order of `group` declarations.</p>
|
970
|
+
|
971
|
+
<p>The new class is unnamed unless assigned to a global constant.</p>
|
972
|
+
|
973
|
+
|
974
|
+
</div>
|
975
|
+
</div>
|
976
|
+
<div class="tags">
|
977
|
+
<p class="tag_title">Parameters:</p>
|
978
|
+
<ul class="param">
|
979
|
+
|
980
|
+
<li>
|
981
|
+
|
982
|
+
<span class='name'>db</span>
|
983
|
+
|
984
|
+
|
985
|
+
<span class='type'>(<tt>Sequel::Database</tt>)</span>
|
986
|
+
|
987
|
+
|
988
|
+
|
989
|
+
—
|
990
|
+
<div class='inline'>
|
991
|
+
<p>the database.</p>
|
992
|
+
</div>
|
993
|
+
|
994
|
+
</li>
|
995
|
+
|
996
|
+
<li>
|
997
|
+
|
998
|
+
<span class='name'>name</span>
|
999
|
+
|
1000
|
+
|
1001
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
1002
|
+
|
1003
|
+
|
1004
|
+
|
1005
|
+
—
|
1006
|
+
<div class='inline'>
|
1007
|
+
<p>the name of the dataset (i.e. underlying table)</p>
|
1008
|
+
</div>
|
1009
|
+
|
1010
|
+
</li>
|
1011
|
+
|
1012
|
+
</ul>
|
1013
|
+
|
1014
|
+
<p class="tag_title">Returns:</p>
|
1015
|
+
<ul class="return">
|
1016
|
+
|
1017
|
+
<li>
|
1018
|
+
|
1019
|
+
|
1020
|
+
<span class='type'>(<tt>Class</tt>)</span>
|
1021
|
+
|
1022
|
+
|
1023
|
+
|
1024
|
+
—
|
1025
|
+
<div class='inline'>
|
1026
|
+
<p>the new class.</p>
|
1027
|
+
</div>
|
1028
|
+
|
1029
|
+
</li>
|
1030
|
+
|
1031
|
+
</ul>
|
1032
|
+
|
1033
|
+
<p class="tag_title">See Also:</p>
|
1034
|
+
<ul class="see">
|
1035
|
+
|
1036
|
+
<li><a href="https://sequel.jeremyevans.net/rdoc/files/doc/schema_modification_rdoc.html" target="_parent" title="https://sequel.jeremyevans.net/rdoc/files/doc/schema_modification_rdoc.html">https://sequel.jeremyevans.net/rdoc/files/doc/schema_modification_rdoc.html</a></li>
|
1037
|
+
|
1038
|
+
</ul>
|
1039
|
+
|
1040
|
+
</div><table class="source_code">
|
1041
|
+
<tr>
|
1042
|
+
<td>
|
1043
|
+
<pre class="lines">
|
1044
|
+
|
1045
|
+
|
1046
|
+
71
|
1047
|
+
72
|
1048
|
+
73
|
1049
|
+
74
|
1050
|
+
75
|
1051
|
+
76
|
1052
|
+
77
|
1053
|
+
78
|
1054
|
+
79
|
1055
|
+
80
|
1056
|
+
81
|
1057
|
+
82
|
1058
|
+
83
|
1059
|
+
84
|
1060
|
+
85
|
1061
|
+
86
|
1062
|
+
87
|
1063
|
+
88
|
1064
|
+
89</pre>
|
1065
|
+
</td>
|
1066
|
+
<td>
|
1067
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_class.rb', line 71</span>
|
1068
|
+
|
1069
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='id identifier rubyid_db'>db</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_body'>body</span><span class='rparen'>)</span>
|
1070
|
+
|
1071
|
+
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Argument 'db' is not a valid Sequel::Database</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
|
1072
|
+
<span class='id identifier rubyid_db'>db</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Sequel</span><span class='op'>::</span><span class='const'>Database</span><span class='rparen'>)</span>
|
1073
|
+
<span class='rbrace'>}</span>
|
1074
|
+
|
1075
|
+
<span class='comment'># It should be pretty straightfoward to support other databases,
|
1076
|
+
</span> <span class='comment'># but I have neither the time nor resources to do so right now.
|
1077
|
+
</span> <span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>DBStruct currently only supports SQLite; </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_db'>db</span><span class='period'>.</span><span class='id identifier rubyid_database_type'>database_type</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span> <span class='op'>+</span>
|
1078
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>is unsupported.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
|
1079
|
+
<span class='id identifier rubyid_db'>db</span><span class='period'>.</span><span class='id identifier rubyid_database_type'>database_type</span> <span class='op'>==</span> <span class='symbol'>:sqlite</span>
|
1080
|
+
<span class='rbrace'>}</span>
|
1081
|
+
|
1082
|
+
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Must provide a block argument</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_body'>body</span> <span class='rbrace'>}</span>
|
1083
|
+
|
1084
|
+
<span class='id identifier rubyid_sc'>sc</span> <span class='op'>=</span> <span class='id identifier rubyid_create_the_subclass'>create_the_subclass</span><span class='lparen'>(</span><span class='id identifier rubyid_db'>db</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_body'>body</span><span class='rparen'>)</span>
|
1085
|
+
<span class='id identifier rubyid_create_table_if_needed'>create_table_if_needed</span><span class='lparen'>(</span><span class='id identifier rubyid_sc'>sc</span><span class='rparen'>)</span>
|
1086
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_sc'>sc</span>
|
1087
|
+
<span class='kw'>end</span></pre>
|
1088
|
+
</td>
|
1089
|
+
</tr>
|
1090
|
+
</table>
|
1091
|
+
</div>
|
1092
|
+
|
1093
|
+
</div>
|
1094
|
+
|
1095
|
+
<div id="instance_method_details" class="method_details_list">
|
1096
|
+
<h2>Instance Method Details</h2>
|
1097
|
+
|
1098
|
+
|
1099
|
+
<div class="method_details first">
|
1100
|
+
<h3 class="signature first" id="[]-instance_method">
|
1101
|
+
|
1102
|
+
#<strong>[]</strong>(field) ⇒ <tt>Object</tt>
|
1103
|
+
|
1104
|
+
|
1105
|
+
|
1106
|
+
|
1107
|
+
|
1108
|
+
</h3><div class="docstring">
|
1109
|
+
<div class="discussion">
|
1110
|
+
|
1111
|
+
<p>Equivalent to ‘get_field`</p>
|
1112
|
+
|
1113
|
+
|
1114
|
+
</div>
|
1115
|
+
</div>
|
1116
|
+
<div class="tags">
|
1117
|
+
|
1118
|
+
|
1119
|
+
</div><table class="source_code">
|
1120
|
+
<tr>
|
1121
|
+
<td>
|
1122
|
+
<pre class="lines">
|
1123
|
+
|
1124
|
+
|
1125
|
+
115</pre>
|
1126
|
+
</td>
|
1127
|
+
<td>
|
1128
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 115</span>
|
1129
|
+
|
1130
|
+
<span class='kw'>def</span> <span class='op'>[]</span><span class='lparen'>(</span><span class='id identifier rubyid_field'>field</span><span class='rparen'>)</span> <span class='op'>=</span> <span class='id identifier rubyid_get_field'>get_field</span><span class='lparen'>(</span><span class='id identifier rubyid_field'>field</span><span class='rparen'>)</span></pre>
|
1131
|
+
</td>
|
1132
|
+
</tr>
|
1133
|
+
</table>
|
1134
|
+
</div>
|
1135
|
+
|
1136
|
+
<div class="method_details ">
|
1137
|
+
<h3 class="signature " id="[]=-instance_method">
|
1138
|
+
|
1139
|
+
#<strong>[]=</strong>(field, value) ⇒ <tt>Object</tt>
|
1140
|
+
|
1141
|
+
|
1142
|
+
|
1143
|
+
|
1144
|
+
|
1145
|
+
</h3><div class="docstring">
|
1146
|
+
<div class="discussion">
|
1147
|
+
|
1148
|
+
<p>Equivalent to ‘set_field`</p>
|
1149
|
+
|
1150
|
+
|
1151
|
+
</div>
|
1152
|
+
</div>
|
1153
|
+
<div class="tags">
|
1154
|
+
|
1155
|
+
|
1156
|
+
</div><table class="source_code">
|
1157
|
+
<tr>
|
1158
|
+
<td>
|
1159
|
+
<pre class="lines">
|
1160
|
+
|
1161
|
+
|
1162
|
+
118
|
1163
|
+
119
|
1164
|
+
120</pre>
|
1165
|
+
</td>
|
1166
|
+
<td>
|
1167
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 118</span>
|
1168
|
+
|
1169
|
+
<span class='kw'>def</span> <span class='op'>[]=</span><span class='lparen'>(</span><span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
1170
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_set_field'>set_field</span><span class='lparen'>(</span><span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
1171
|
+
<span class='kw'>end</span></pre>
|
1172
|
+
</td>
|
1173
|
+
</tr>
|
1174
|
+
</table>
|
1175
|
+
</div>
|
1176
|
+
|
1177
|
+
<div class="method_details ">
|
1178
|
+
<h3 class="signature " id="deleted?-instance_method">
|
1179
|
+
|
1180
|
+
#<strong>deleted?</strong> ⇒ <tt>Boolean</tt>
|
1181
|
+
|
1182
|
+
|
1183
|
+
|
1184
|
+
|
1185
|
+
|
1186
|
+
</h3><div class="docstring">
|
1187
|
+
<div class="discussion">
|
1188
|
+
|
1189
|
+
<p>Test if the database row associated with ‘self` no longer exists. Inverse of `present?`</p>
|
1190
|
+
|
1191
|
+
|
1192
|
+
</div>
|
1193
|
+
</div>
|
1194
|
+
<div class="tags">
|
1195
|
+
|
1196
|
+
<p class="tag_title">Returns:</p>
|
1197
|
+
<ul class="return">
|
1198
|
+
|
1199
|
+
<li>
|
1200
|
+
|
1201
|
+
|
1202
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
1203
|
+
|
1204
|
+
|
1205
|
+
|
1206
|
+
</li>
|
1207
|
+
|
1208
|
+
</ul>
|
1209
|
+
|
1210
|
+
</div><table class="source_code">
|
1211
|
+
<tr>
|
1212
|
+
<td>
|
1213
|
+
<pre class="lines">
|
1214
|
+
|
1215
|
+
|
1216
|
+
73</pre>
|
1217
|
+
</td>
|
1218
|
+
<td>
|
1219
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 73</span>
|
1220
|
+
|
1221
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_deleted?'>deleted?</span> <span class='op'>=</span> <span class='id identifier rubyid_dataset'>dataset</span><span class='lparen'>(</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='label'>_id:</span><span class='ivar'>@rowid</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span></pre>
|
1222
|
+
</td>
|
1223
|
+
</tr>
|
1224
|
+
</table>
|
1225
|
+
</div>
|
1226
|
+
|
1227
|
+
<div class="method_details ">
|
1228
|
+
<h3 class="signature " id="eql?-instance_method">
|
1229
|
+
|
1230
|
+
#<strong>eql?</strong>(other) ⇒ <tt>Boolean</tt>
|
1231
|
+
|
1232
|
+
|
1233
|
+
|
1234
|
+
<span class="aliases">Also known as:
|
1235
|
+
<span class="names"><span id='==-instance_method'>==</span></span>
|
1236
|
+
</span>
|
1237
|
+
|
1238
|
+
|
1239
|
+
|
1240
|
+
</h3><div class="docstring">
|
1241
|
+
<div class="discussion">
|
1242
|
+
|
1243
|
+
<p>Test for equality. Instances are equal if and only if they refer to the same database row and (as implied) are of the same class.</p>
|
1244
|
+
|
1245
|
+
|
1246
|
+
</div>
|
1247
|
+
</div>
|
1248
|
+
<div class="tags">
|
1249
|
+
|
1250
|
+
<p class="tag_title">Returns:</p>
|
1251
|
+
<ul class="return">
|
1252
|
+
|
1253
|
+
<li>
|
1254
|
+
|
1255
|
+
|
1256
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
1257
|
+
|
1258
|
+
|
1259
|
+
|
1260
|
+
</li>
|
1261
|
+
|
1262
|
+
</ul>
|
1263
|
+
|
1264
|
+
</div><table class="source_code">
|
1265
|
+
<tr>
|
1266
|
+
<td>
|
1267
|
+
<pre class="lines">
|
1268
|
+
|
1269
|
+
|
1270
|
+
126</pre>
|
1271
|
+
</td>
|
1272
|
+
<td>
|
1273
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 126</span>
|
1274
|
+
|
1275
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_eql?'>eql?</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>==</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>&&</span> <span class='ivar'>@rowid</span> <span class='op'>==</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_rowid'>rowid</span></pre>
|
1276
|
+
</td>
|
1277
|
+
</tr>
|
1278
|
+
</table>
|
1279
|
+
</div>
|
1280
|
+
|
1281
|
+
<div class="method_details ">
|
1282
|
+
<h3 class="signature " id="get_field-instance_method">
|
1283
|
+
|
1284
|
+
#<strong>get_field</strong>(name) ⇒ <tt>Object</tt>
|
1285
|
+
|
1286
|
+
|
1287
|
+
|
1288
|
+
|
1289
|
+
|
1290
|
+
</h3><div class="docstring">
|
1291
|
+
<div class="discussion">
|
1292
|
+
|
1293
|
+
<p>Sets the value of the field named by ‘field` to the given value. `field` must be one of the declared fields and value must have the declared class.</p>
|
1294
|
+
|
1295
|
+
|
1296
|
+
</div>
|
1297
|
+
</div>
|
1298
|
+
<div class="tags">
|
1299
|
+
|
1300
|
+
|
1301
|
+
</div><table class="source_code">
|
1302
|
+
<tr>
|
1303
|
+
<td>
|
1304
|
+
<pre class="lines">
|
1305
|
+
|
1306
|
+
|
1307
|
+
78
|
1308
|
+
79
|
1309
|
+
80
|
1310
|
+
81</pre>
|
1311
|
+
</td>
|
1312
|
+
<td>
|
1313
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 78</span>
|
1314
|
+
|
1315
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_get_field'>get_field</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
1316
|
+
<span class='id identifier rubyid_check_field'>check_field</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1317
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_dataset'>dataset</span><span class='lbracket'>[</span><span class='label'>_id:</span> <span class='ivar'>@rowid</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span>
|
1318
|
+
<span class='kw'>end</span></pre>
|
1319
|
+
</td>
|
1320
|
+
</tr>
|
1321
|
+
</table>
|
1322
|
+
</div>
|
1323
|
+
|
1324
|
+
<div class="method_details ">
|
1325
|
+
<h3 class="signature " id="hash-instance_method">
|
1326
|
+
|
1327
|
+
#<strong>hash</strong> ⇒ <tt>Object</tt>
|
1328
|
+
|
1329
|
+
|
1330
|
+
|
1331
|
+
|
1332
|
+
|
1333
|
+
</h3><div class="docstring">
|
1334
|
+
<div class="discussion">
|
1335
|
+
|
1336
|
+
<p>Return a hash; here because we’ve also overridden <span class='object_link'><a href="#eql%3F-instance_method" title="DBStruct#eql? (method)">#eql?</a></span></p>
|
1337
|
+
|
1338
|
+
|
1339
|
+
</div>
|
1340
|
+
</div>
|
1341
|
+
<div class="tags">
|
1342
|
+
|
1343
|
+
|
1344
|
+
</div><table class="source_code">
|
1345
|
+
<tr>
|
1346
|
+
<td>
|
1347
|
+
<pre class="lines">
|
1348
|
+
|
1349
|
+
|
1350
|
+
130</pre>
|
1351
|
+
</td>
|
1352
|
+
<td>
|
1353
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 130</span>
|
1354
|
+
|
1355
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_hash'>hash</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='comma'>,</span> <span class='ivar'>@rowid</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_hash'>hash</span></pre>
|
1356
|
+
</td>
|
1357
|
+
</tr>
|
1358
|
+
</table>
|
1359
|
+
</div>
|
1360
|
+
|
1361
|
+
<div class="method_details ">
|
1362
|
+
<h3 class="signature " id="inspect-instance_method">
|
1363
|
+
|
1364
|
+
#<strong>inspect</strong> ⇒ <tt>Object</tt>
|
1365
|
+
|
1366
|
+
|
1367
|
+
|
1368
|
+
<span class="aliases">Also known as:
|
1369
|
+
<span class="names"><span id='to_s-instance_method'>to_s</span></span>
|
1370
|
+
</span>
|
1371
|
+
|
1372
|
+
|
1373
|
+
|
1374
|
+
</h3><div class="docstring">
|
1375
|
+
<div class="discussion">
|
1376
|
+
|
1377
|
+
<p>Return a human-friendly description.</p>
|
1378
|
+
|
1379
|
+
|
1380
|
+
</div>
|
1381
|
+
</div>
|
1382
|
+
<div class="tags">
|
1383
|
+
|
1384
|
+
|
1385
|
+
</div><table class="source_code">
|
1386
|
+
<tr>
|
1387
|
+
<td>
|
1388
|
+
<pre class="lines">
|
1389
|
+
|
1390
|
+
|
1391
|
+
135
|
1392
|
+
136
|
1393
|
+
137
|
1394
|
+
138
|
1395
|
+
139
|
1396
|
+
140
|
1397
|
+
141</pre>
|
1398
|
+
</td>
|
1399
|
+
<td>
|
1400
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 135</span>
|
1401
|
+
|
1402
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_inspect'>inspect</span>
|
1403
|
+
<span class='id identifier rubyid_max_line'>max_line</span> <span class='op'>=</span> <span class='int'>60</span>
|
1404
|
+
|
1405
|
+
<span class='id identifier rubyid_values'>values</span> <span class='op'>=</span> <span class='id identifier rubyid_to_h'>to_h</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_k'>k</span><span class='embexpr_end'>}</span><span class='tstring_content'>: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>, </span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1406
|
+
<span class='id identifier rubyid_values'>values</span> <span class='op'>=</span> <span class='id identifier rubyid_values'>values</span><span class='lbracket'>[</span><span class='int'>0</span><span class='op'>..</span><span class='id identifier rubyid_max_line'>max_line</span><span class='rbracket'>]</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>...</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>></span> <span class='id identifier rubyid_max_line'>max_line</span>
|
1407
|
+
<span class='kw'>return</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'>.new(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_values'>values</span><span class='embexpr_end'>}</span><span class='tstring_content'>)</span><span class='tstring_end'>"</span></span>
|
1408
|
+
<span class='kw'>end</span></pre>
|
1409
|
+
</td>
|
1410
|
+
</tr>
|
1411
|
+
</table>
|
1412
|
+
</div>
|
1413
|
+
|
1414
|
+
<div class="method_details ">
|
1415
|
+
<h3 class="signature " id="present?-instance_method">
|
1416
|
+
|
1417
|
+
#<strong>present?</strong> ⇒ <tt>Boolean</tt>
|
1418
|
+
|
1419
|
+
|
1420
|
+
|
1421
|
+
|
1422
|
+
|
1423
|
+
</h3><div class="docstring">
|
1424
|
+
<div class="discussion">
|
1425
|
+
|
1426
|
+
<p>Test if the database row associated with ‘self` still exists. Inverse of `deleted?`.</p>
|
1427
|
+
|
1428
|
+
|
1429
|
+
</div>
|
1430
|
+
</div>
|
1431
|
+
<div class="tags">
|
1432
|
+
|
1433
|
+
<p class="tag_title">Returns:</p>
|
1434
|
+
<ul class="return">
|
1435
|
+
|
1436
|
+
<li>
|
1437
|
+
|
1438
|
+
|
1439
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
1440
|
+
|
1441
|
+
|
1442
|
+
|
1443
|
+
</li>
|
1444
|
+
|
1445
|
+
</ul>
|
1446
|
+
|
1447
|
+
</div><table class="source_code">
|
1448
|
+
<tr>
|
1449
|
+
<td>
|
1450
|
+
<pre class="lines">
|
1451
|
+
|
1452
|
+
|
1453
|
+
69</pre>
|
1454
|
+
</td>
|
1455
|
+
<td>
|
1456
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 69</span>
|
1457
|
+
|
1458
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_present?'>present?</span> <span class='op'>=</span> <span class='op'>!</span><span class='id identifier rubyid_deleted?'>deleted?</span></pre>
|
1459
|
+
</td>
|
1460
|
+
</tr>
|
1461
|
+
</table>
|
1462
|
+
</div>
|
1463
|
+
|
1464
|
+
<div class="method_details ">
|
1465
|
+
<h3 class="signature " id="set_field-instance_method">
|
1466
|
+
|
1467
|
+
#<strong>set_field</strong>(name, value) ⇒ <tt>Object</tt>
|
1468
|
+
|
1469
|
+
|
1470
|
+
|
1471
|
+
|
1472
|
+
|
1473
|
+
</h3><div class="docstring">
|
1474
|
+
<div class="discussion">
|
1475
|
+
|
1476
|
+
<p>Retrieve the value of the field named by symbol ‘field`. Raises an exception if `field` is not one of the declared fields.</p>
|
1477
|
+
|
1478
|
+
|
1479
|
+
</div>
|
1480
|
+
</div>
|
1481
|
+
<div class="tags">
|
1482
|
+
|
1483
|
+
|
1484
|
+
</div><table class="source_code">
|
1485
|
+
<tr>
|
1486
|
+
<td>
|
1487
|
+
<pre class="lines">
|
1488
|
+
|
1489
|
+
|
1490
|
+
85
|
1491
|
+
86
|
1492
|
+
87
|
1493
|
+
88
|
1494
|
+
89
|
1495
|
+
90
|
1496
|
+
91
|
1497
|
+
92
|
1498
|
+
93</pre>
|
1499
|
+
</td>
|
1500
|
+
<td>
|
1501
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 85</span>
|
1502
|
+
|
1503
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_set_field'>set_field</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
1504
|
+
<span class='id identifier rubyid_check_field'>check_field</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
1505
|
+
|
1506
|
+
<span class='id identifier rubyid_dataset'>dataset</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
1507
|
+
<span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='label'>_id:</span> <span class='ivar'>@rowid</span><span class='rparen'>)</span>
|
1508
|
+
<span class='period'>.</span><span class='id identifier rubyid_update'>update</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='id identifier rubyid_name'>name</span> <span class='op'>=></span> <span class='id identifier rubyid_value'>value</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
1509
|
+
|
1510
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span>
|
1511
|
+
<span class='kw'>end</span></pre>
|
1512
|
+
</td>
|
1513
|
+
</tr>
|
1514
|
+
</table>
|
1515
|
+
</div>
|
1516
|
+
|
1517
|
+
<div class="method_details ">
|
1518
|
+
<h3 class="signature " id="set_fields-instance_method">
|
1519
|
+
|
1520
|
+
#<strong>set_fields</strong>(**kwargs) ⇒ <tt>Object</tt>
|
1521
|
+
|
1522
|
+
|
1523
|
+
|
1524
|
+
|
1525
|
+
|
1526
|
+
</h3><div class="docstring">
|
1527
|
+
<div class="discussion">
|
1528
|
+
|
1529
|
+
<p>Set zero or more fields at once. Keywords must be the names of defined fields.</p>
|
1530
|
+
|
1531
|
+
<p>The update is enclosed in an transaction.</p>
|
1532
|
+
|
1533
|
+
|
1534
|
+
</div>
|
1535
|
+
</div>
|
1536
|
+
<div class="tags">
|
1537
|
+
|
1538
|
+
|
1539
|
+
</div><table class="source_code">
|
1540
|
+
<tr>
|
1541
|
+
<td>
|
1542
|
+
<pre class="lines">
|
1543
|
+
|
1544
|
+
|
1545
|
+
99
|
1546
|
+
100
|
1547
|
+
101
|
1548
|
+
102
|
1549
|
+
103
|
1550
|
+
104</pre>
|
1551
|
+
</td>
|
1552
|
+
<td>
|
1553
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 99</span>
|
1554
|
+
|
1555
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_set_fields'>set_fields</span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
|
1556
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
1557
|
+
<span class='id identifier rubyid_kwargs'>kwargs</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_set_field'>set_field</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span><span class='rbrace'>}</span>
|
1558
|
+
<span class='rbrace'>}</span>
|
1559
|
+
<span class='kw'>return</span> <span class='kw'>self</span>
|
1560
|
+
<span class='kw'>end</span></pre>
|
1561
|
+
</td>
|
1562
|
+
</tr>
|
1563
|
+
</table>
|
1564
|
+
</div>
|
1565
|
+
|
1566
|
+
<div class="method_details ">
|
1567
|
+
<h3 class="signature " id="to_a-instance_method">
|
1568
|
+
|
1569
|
+
#<strong>to_a</strong> ⇒ <tt>Object</tt>
|
1570
|
+
|
1571
|
+
|
1572
|
+
|
1573
|
+
|
1574
|
+
|
1575
|
+
</h3><div class="docstring">
|
1576
|
+
<div class="discussion">
|
1577
|
+
|
1578
|
+
<p>Return the contents as an array of pairs of key and value</p>
|
1579
|
+
|
1580
|
+
|
1581
|
+
</div>
|
1582
|
+
</div>
|
1583
|
+
<div class="tags">
|
1584
|
+
|
1585
|
+
|
1586
|
+
</div><table class="source_code">
|
1587
|
+
<tr>
|
1588
|
+
<td>
|
1589
|
+
<pre class="lines">
|
1590
|
+
|
1591
|
+
|
1592
|
+
109</pre>
|
1593
|
+
</td>
|
1594
|
+
<td>
|
1595
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 109</span>
|
1596
|
+
|
1597
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_to_a'>to_a</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_columns'>columns</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_get_field'>get_field</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span><span class='rbracket'>]</span> <span class='rbrace'>}</span></pre>
|
1598
|
+
</td>
|
1599
|
+
</tr>
|
1600
|
+
</table>
|
1601
|
+
</div>
|
1602
|
+
|
1603
|
+
<div class="method_details ">
|
1604
|
+
<h3 class="signature " id="to_h-instance_method">
|
1605
|
+
|
1606
|
+
#<strong>to_h</strong> ⇒ <tt>Object</tt>
|
1607
|
+
|
1608
|
+
|
1609
|
+
|
1610
|
+
|
1611
|
+
|
1612
|
+
</h3><div class="docstring">
|
1613
|
+
<div class="discussion">
|
1614
|
+
|
1615
|
+
<p>Return the contents as a hash</p>
|
1616
|
+
|
1617
|
+
|
1618
|
+
</div>
|
1619
|
+
</div>
|
1620
|
+
<div class="tags">
|
1621
|
+
|
1622
|
+
|
1623
|
+
</div><table class="source_code">
|
1624
|
+
<tr>
|
1625
|
+
<td>
|
1626
|
+
<pre class="lines">
|
1627
|
+
|
1628
|
+
|
1629
|
+
112</pre>
|
1630
|
+
</td>
|
1631
|
+
<td>
|
1632
|
+
<pre class="code"><span class="info file"># File 'lib/internal/dbstruct_base.rb', line 112</span>
|
1633
|
+
|
1634
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_to_h'>to_h</span> <span class='op'>=</span> <span class='id identifier rubyid_to_a'>to_a</span><span class='period'>.</span><span class='id identifier rubyid_to_h'>to_h</span></pre>
|
1635
|
+
</td>
|
1636
|
+
</tr>
|
1637
|
+
</table>
|
1638
|
+
</div>
|
1639
|
+
|
1640
|
+
</div>
|
1641
|
+
|
1642
|
+
</div>
|
1643
|
+
|
1644
|
+
<div id="footer">
|
1645
|
+
Generated on Wed Sep 11 13:00:27 2024 by
|
1646
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1647
|
+
0.9.37 (ruby-3.1.4).
|
1648
|
+
</div>
|
1649
|
+
|
1650
|
+
</div>
|
1651
|
+
</body>
|
1652
|
+
</html>
|