shep 0.1.0.pre.alpha0
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/Copyright.txt +8 -0
- data/LICENSE.txt +697 -0
- data/README.md +101 -0
- data/Rakefile +52 -0
- data/doc/Shep/Entity/Account.html +193 -0
- data/doc/Shep/Entity/Context.html +165 -0
- data/doc/Shep/Entity/CustomEmoji.html +171 -0
- data/doc/Shep/Entity/MediaAttachment.html +175 -0
- data/doc/Shep/Entity/Notification.html +171 -0
- data/doc/Shep/Entity/Status.html +217 -0
- data/doc/Shep/Entity/StatusSource.html +167 -0
- data/doc/Shep/Entity/Status_Application.html +167 -0
- data/doc/Shep/Entity/Status_Mention.html +169 -0
- data/doc/Shep/Entity/Status_Tag.html +165 -0
- data/doc/Shep/Entity.html +1457 -0
- data/doc/Shep/Error/Caller.html +147 -0
- data/doc/Shep/Error/Http.html +329 -0
- data/doc/Shep/Error/Remote.html +143 -0
- data/doc/Shep/Error/Server.html +147 -0
- data/doc/Shep/Error/Type.html +233 -0
- data/doc/Shep/Error.html +149 -0
- data/doc/Shep/Session.html +4094 -0
- data/doc/Shep.html +128 -0
- data/doc/_index.html +300 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +497 -0
- data/doc/file.README.html +159 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +300 -0
- data/doc/js/app.js +314 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +387 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/shep/entities.rb +164 -0
- data/lib/shep/entity_base.rb +378 -0
- data/lib/shep/exceptions.rb +78 -0
- data/lib/shep/session.rb +970 -0
- data/lib/shep/typeboxes.rb +180 -0
- data/lib/shep.rb +22 -0
- data/run_rake_test.example.sh +46 -0
- data/shep.gemspec +28 -0
- data/spec/data/smallimg.jpg +0 -0
- data/spec/data/smallish.jpg +0 -0
- data/spec/entity_common.rb +120 -0
- data/spec/entity_t1_spec.rb +168 -0
- data/spec/entity_t2_spec.rb +123 -0
- data/spec/entity_t3_spec.rb +30 -0
- data/spec/json_objects/account.1.json +25 -0
- data/spec/json_objects/account.2.json +36 -0
- data/spec/json_objects/status.1.json +85 -0
- data/spec/json_objects/status.2.json +59 -0
- data/spec/json_objects/status.3.json +95 -0
- data/spec/json_objects/status.4.json +95 -0
- data/spec/json_objects/status.5.json +74 -0
- data/spec/json_objects/status.6.json +140 -0
- data/spec/json_objects/status.7.json +84 -0
- data/spec/session_reader_1_unauth_spec.rb +366 -0
- data/spec/session_reader_2_auth_spec.rb +96 -0
- data/spec/session_writer_spec.rb +183 -0
- data/spec/spec_helper.rb +73 -0
- data/yard_helper.rb +30 -0
- metadata +154 -0
@@ -0,0 +1,1457 @@
|
|
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: Shep::Entity
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.34
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "Shep::Entity";
|
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 (E)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../Shep.html" title="Shep (module)">Shep</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">Entity</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: Shep::Entity
|
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">Shep::Entity</li>
|
78
|
+
|
79
|
+
</ul>
|
80
|
+
<a href="#" class="inheritanceTree">show all</a>
|
81
|
+
|
82
|
+
</dd>
|
83
|
+
</dl>
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
<dl>
|
96
|
+
<dt>Defined in:</dt>
|
97
|
+
<dd>lib/shep/entity_base.rb</dd>
|
98
|
+
</dl>
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<h2>Overview</h2><div class="docstring">
|
103
|
+
<div class="discussion">
|
104
|
+
|
105
|
+
<p>Abstract base class for Mastodon objects.</p>
|
106
|
+
|
107
|
+
<p>Mastodon provides its content as JSON hashes with documented names and values. Shep takes this one step further and provides a class for each object type. These are similar to Ruby’s <code>Struct</code> but are also strongly typed.</p>
|
108
|
+
|
109
|
+
<p>Typing is primarily useful for converting things that don’t have explicit JSON types (e.g. Time, URI) into Ruby types. However, it will also catch the case where you’re trying to set a field to something with the wrong type.</p>
|
110
|
+
|
111
|
+
<p>Supported types are:</p>
|
112
|
+
<ul><li>
|
113
|
+
<p>Number - (Integer but also allows Float)</p>
|
114
|
+
</li><li>
|
115
|
+
<p>Boolean</p>
|
116
|
+
</li><li>
|
117
|
+
<p>String</p>
|
118
|
+
</li><li>
|
119
|
+
<p>URI - (a Ruby URI object)</p>
|
120
|
+
</li><li>
|
121
|
+
<p>Time - parsed from and converted to ISO8601-format strings</p>
|
122
|
+
</li><li>
|
123
|
+
<p>Entity - an arbitrary Entity subclass</p>
|
124
|
+
</li><li>
|
125
|
+
<p>Array - strongly typed array of any of the above types</p>
|
126
|
+
</li></ul>
|
127
|
+
|
128
|
+
<p>Fields may also be set to nil, except for <code>Array</code> which must instead be set to an ampty array.</p>
|
129
|
+
|
130
|
+
<p>Entities can be converted to and from Ruby Hashes. For this, we provide two flavours of Hash: the regular Ruby Hash where values are just the Ruby objects and the JSON hash where everything has been converted to the types expected by a Mastodon server.</p>
|
131
|
+
|
132
|
+
<p>For JSON hashes, <code>Time</code> objects become ISO8601-formatted strings, <code>URI</code> objects become strings containing the url and <code>Entity</code> subobjects become their own JSON hashes. (Note that conversion to JSON hashes isn’t really used outside of some testing and internal stuff so I don’t guarantee that a Mastodon server or client will accept them.)</p>
|
133
|
+
|
134
|
+
<p>Normally, we care about initializing Entity objects from the corresponding parsed JSON object and produce Ruby hashes when we need to use a feature <code>Hash</code> provides.</p>
|
135
|
+
|
136
|
+
<p>Subclasses are all defined inside the Entity namespace so that it groups nicely in YARD docs (and because it makes the intent obvious).</p>
|
137
|
+
|
138
|
+
|
139
|
+
</div>
|
140
|
+
</div>
|
141
|
+
<div class="tags">
|
142
|
+
|
143
|
+
|
144
|
+
</div><div id="subclasses">
|
145
|
+
<h2>Direct Known Subclasses</h2>
|
146
|
+
<p class="children"><span class='object_link'><a href="Entity/Account.html" title="Shep::Entity::Account (class)">Account</a></span>, <span class='object_link'><a href="Entity/Context.html" title="Shep::Entity::Context (class)">Context</a></span>, <span class='object_link'><a href="Entity/CustomEmoji.html" title="Shep::Entity::CustomEmoji (class)">CustomEmoji</a></span>, <span class='object_link'><a href="Entity/MediaAttachment.html" title="Shep::Entity::MediaAttachment (class)">MediaAttachment</a></span>, <span class='object_link'><a href="Entity/Notification.html" title="Shep::Entity::Notification (class)">Notification</a></span>, <span class='object_link'><a href="Entity/Status.html" title="Shep::Entity::Status (class)">Status</a></span>, <span class='object_link'><a href="Entity/StatusSource.html" title="Shep::Entity::StatusSource (class)">StatusSource</a></span>, <span class='object_link'><a href="Entity/Status_Application.html" title="Shep::Entity::Status_Application (class)">Status_Application</a></span>, <span class='object_link'><a href="Entity/Status_Mention.html" title="Shep::Entity::Status_Mention (class)">Status_Mention</a></span>, <span class='object_link'><a href="Entity/Status_Tag.html" title="Shep::Entity::Status_Tag (class)">Status_Tag</a></span></p>
|
147
|
+
</div>
|
148
|
+
<h2>Defined Under Namespace</h2>
|
149
|
+
<p class="children">
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Entity/Account.html" title="Shep::Entity::Account (class)">Account</a></span>, <span class='object_link'><a href="Entity/Context.html" title="Shep::Entity::Context (class)">Context</a></span>, <span class='object_link'><a href="Entity/CustomEmoji.html" title="Shep::Entity::CustomEmoji (class)">CustomEmoji</a></span>, <span class='object_link'><a href="Entity/MediaAttachment.html" title="Shep::Entity::MediaAttachment (class)">MediaAttachment</a></span>, <span class='object_link'><a href="Entity/Notification.html" title="Shep::Entity::Notification (class)">Notification</a></span>, <span class='object_link'><a href="Entity/Status.html" title="Shep::Entity::Status (class)">Status</a></span>, <span class='object_link'><a href="Entity/StatusSource.html" title="Shep::Entity::StatusSource (class)">StatusSource</a></span>, <span class='object_link'><a href="Entity/Status_Application.html" title="Shep::Entity::Status_Application (class)">Status_Application</a></span>, <span class='object_link'><a href="Entity/Status_Mention.html" title="Shep::Entity::Status_Mention (class)">Status_Mention</a></span>, <span class='object_link'><a href="Entity/Status_Tag.html" title="Shep::Entity::Status_Tag (class)">Status_Tag</a></span>
|
155
|
+
|
156
|
+
|
157
|
+
</p>
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
<h2>
|
167
|
+
Class Method Summary
|
168
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
169
|
+
</h2>
|
170
|
+
|
171
|
+
<ul class="summary">
|
172
|
+
|
173
|
+
<li class="public ">
|
174
|
+
<span class="summary_signature">
|
175
|
+
|
176
|
+
<a href="#fields-class_method" title="fields (class method)">.<strong>fields</strong>(*flds) ⇒ Object </a>
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
</span>
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
<span class="private note title">private</span>
|
188
|
+
|
189
|
+
|
190
|
+
<span class="summary_desc"><div class='inline'>
|
191
|
+
<p>Cool metaprogramming thing for defining <span class='object_link'><a href="" title="Shep::Entity (class)">Entity</a></span> subclasses.</p>
|
192
|
+
</div></span>
|
193
|
+
|
194
|
+
</li>
|
195
|
+
|
196
|
+
|
197
|
+
<li class="public ">
|
198
|
+
<span class="summary_signature">
|
199
|
+
|
200
|
+
<a href="#from-class_method" title="from (class method)">.<strong>from</strong>(json_hash) ⇒ Object </a>
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
</span>
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
<span class="summary_desc"><div class='inline'>
|
215
|
+
<p>Construct an instance from the (parsed) JSON object returned by Mastodon.</p>
|
216
|
+
</div></span>
|
217
|
+
|
218
|
+
</li>
|
219
|
+
|
220
|
+
|
221
|
+
<li class="public ">
|
222
|
+
<span class="summary_signature">
|
223
|
+
|
224
|
+
<a href="#with-class_method" title="with (class method)">.<strong>with</strong>(**fields) ⇒ Object </a>
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
</span>
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
<span class="summary_desc"><div class='inline'>
|
239
|
+
<p>Construct an instance initialized with Ruby objects.</p>
|
240
|
+
</div></span>
|
241
|
+
|
242
|
+
</li>
|
243
|
+
|
244
|
+
|
245
|
+
</ul>
|
246
|
+
|
247
|
+
<h2>
|
248
|
+
Instance Method Summary
|
249
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
250
|
+
</h2>
|
251
|
+
|
252
|
+
<ul class="summary">
|
253
|
+
|
254
|
+
<li class="public ">
|
255
|
+
<span class="summary_signature">
|
256
|
+
|
257
|
+
<a href="#==-instance_method" title="#== (instance method)">#<strong>==</strong>(other) ⇒ Boolean </a>
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
</span>
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
<span class="summary_desc"><div class='inline'>
|
272
|
+
<p>Compare for equality.</p>
|
273
|
+
</div></span>
|
274
|
+
|
275
|
+
</li>
|
276
|
+
|
277
|
+
|
278
|
+
<li class="public ">
|
279
|
+
<span class="summary_signature">
|
280
|
+
|
281
|
+
<a href="#[]-instance_method" title="#[] (instance method)">#<strong>[]</strong>(key) ⇒ Object </a>
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
</span>
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
<span class="summary_desc"><div class='inline'>
|
296
|
+
<p>Retrieve a field value by name.</p>
|
297
|
+
</div></span>
|
298
|
+
|
299
|
+
</li>
|
300
|
+
|
301
|
+
|
302
|
+
<li class="public ">
|
303
|
+
<span class="summary_signature">
|
304
|
+
|
305
|
+
<a href="#[]=-instance_method" title="#[]= (instance method)">#<strong>[]=</strong>(key, value) ⇒ Object </a>
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
</span>
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
<span class="summary_desc"><div class='inline'>
|
320
|
+
<p>Set a field value by name.</p>
|
321
|
+
</div></span>
|
322
|
+
|
323
|
+
</li>
|
324
|
+
|
325
|
+
|
326
|
+
<li class="public ">
|
327
|
+
<span class="summary_signature">
|
328
|
+
|
329
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong> ⇒ Entity </a>
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
</span>
|
334
|
+
|
335
|
+
|
336
|
+
<span class="note title constructor">constructor</span>
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
<span class="summary_desc"><div class='inline'>
|
346
|
+
<p>Default constructor; creates an empty instance.</p>
|
347
|
+
</div></span>
|
348
|
+
|
349
|
+
</li>
|
350
|
+
|
351
|
+
|
352
|
+
<li class="public ">
|
353
|
+
<span class="summary_signature">
|
354
|
+
|
355
|
+
<a href="#print-instance_method" title="#print (instance method)">#<strong>print</strong> ⇒ Object </a>
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
</span>
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
<span class="summary_desc"><div class='inline'>
|
370
|
+
<p>Wrapper around <code>puts to_long_s()</code>.</p>
|
371
|
+
</div></span>
|
372
|
+
|
373
|
+
</li>
|
374
|
+
|
375
|
+
|
376
|
+
<li class="public ">
|
377
|
+
<span class="summary_signature">
|
378
|
+
|
379
|
+
<a href="#set_from_hash!-instance_method" title="#set_from_hash! (instance method)">#<strong>set_from_hash!</strong>(some_hash, ignore_unknown: false, from_json: false) ⇒ Object </a>
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
</span>
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
<span class="summary_desc"><div class='inline'>
|
394
|
+
<p>Set all fields from a hash.</p>
|
395
|
+
</div></span>
|
396
|
+
|
397
|
+
</li>
|
398
|
+
|
399
|
+
|
400
|
+
<li class="public ">
|
401
|
+
<span class="summary_signature">
|
402
|
+
|
403
|
+
<a href="#to_h-instance_method" title="#to_h (instance method)">#<strong>to_h</strong>(json_compatible = false) ⇒ Hash </a>
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
</span>
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
<span class="summary_desc"><div class='inline'>
|
418
|
+
<p>Return a hash of the contents mapping field name to value.</p>
|
419
|
+
</div></span>
|
420
|
+
|
421
|
+
</li>
|
422
|
+
|
423
|
+
|
424
|
+
<li class="public ">
|
425
|
+
<span class="summary_signature">
|
426
|
+
|
427
|
+
<a href="#to_long_s-instance_method" title="#to_long_s (instance method)">#<strong>to_long_s</strong>(indent_level = 0) ⇒ String </a>
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
</span>
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
<span class="summary_desc"><div class='inline'>
|
442
|
+
<p>Produce a long-form human-friendly description of this Entity.</p>
|
443
|
+
</div></span>
|
444
|
+
|
445
|
+
</li>
|
446
|
+
|
447
|
+
|
448
|
+
<li class="public ">
|
449
|
+
<span class="summary_signature">
|
450
|
+
|
451
|
+
<a href="#to_s-instance_method" title="#to_s (instance method)">#<strong>to_s</strong> ⇒ String </a>
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
(also: #inspect)
|
456
|
+
|
457
|
+
</span>
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
<span class="summary_desc"><div class='inline'>
|
468
|
+
<p>Produce a <strong>short</strong> human-friendly description.</p>
|
469
|
+
</div></span>
|
470
|
+
|
471
|
+
</li>
|
472
|
+
|
473
|
+
|
474
|
+
</ul>
|
475
|
+
|
476
|
+
|
477
|
+
<div id="constructor_details" class="method_details_list">
|
478
|
+
<h2>Constructor Details</h2>
|
479
|
+
|
480
|
+
<div class="method_details first">
|
481
|
+
<h3 class="signature first" id="initialize-instance_method">
|
482
|
+
|
483
|
+
#<strong>initialize</strong> ⇒ <tt><span class='object_link'><a href="" title="Shep::Entity (class)">Entity</a></span></tt>
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
</h3><div class="docstring">
|
490
|
+
<div class="discussion">
|
491
|
+
|
492
|
+
<p>Default constructor; creates an empty instance. You’ll probably want to use <span class='object_link'><a href="#with-class_method" title="Shep::Entity.with (method)">with</a></span> or <span class='object_link'><a href="#from-class_method" title="Shep::Entity.from (method)">from</a></span> instead.</p>
|
493
|
+
|
494
|
+
|
495
|
+
</div>
|
496
|
+
</div>
|
497
|
+
<div class="tags">
|
498
|
+
|
499
|
+
|
500
|
+
</div><table class="source_code">
|
501
|
+
<tr>
|
502
|
+
<td>
|
503
|
+
<pre class="lines">
|
504
|
+
|
505
|
+
|
506
|
+
62
|
507
|
+
63
|
508
|
+
64</pre>
|
509
|
+
</td>
|
510
|
+
<td>
|
511
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 62</span>
|
512
|
+
|
513
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
|
514
|
+
<span class='id identifier rubyid_init_fields'>init_fields</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
515
|
+
<span class='kw'>end</span></pre>
|
516
|
+
</td>
|
517
|
+
</tr>
|
518
|
+
</table>
|
519
|
+
</div>
|
520
|
+
|
521
|
+
</div>
|
522
|
+
|
523
|
+
|
524
|
+
<div id="class_method_details" class="method_details_list">
|
525
|
+
<h2>Class Method Details</h2>
|
526
|
+
|
527
|
+
|
528
|
+
<div class="method_details first">
|
529
|
+
<h3 class="signature first" id="fields-class_method">
|
530
|
+
|
531
|
+
.<strong>fields</strong>(*flds) ⇒ <tt>Object</tt>
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
</h3><div class="docstring">
|
538
|
+
<div class="discussion">
|
539
|
+
<p class="note private">
|
540
|
+
<strong>This method is part of a private API.</strong>
|
541
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
542
|
+
</p>
|
543
|
+
|
544
|
+
<p>Cool metaprogramming thing for defining <span class='object_link'><a href="" title="Shep::Entity (class)">Shep::Entity</a></span> subclasses.</p>
|
545
|
+
|
546
|
+
<p>A typical <span class='object_link'><a href="" title="Shep::Entity (class)">Shep::Entity</a></span> subclass should contain only a call to this method. For example:</p>
|
547
|
+
|
548
|
+
<pre class="code ruby"><code class="ruby"> <span class='kw'>class</span> <span class='const'>Thingy</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="" title="Shep::Entity (class)">Entity</a></span></span>
|
549
|
+
<span class='id identifier rubyid_fields'>fields</span><span class='lparen'>(</span>
|
550
|
+
<span class='symbol'>:id</span><span class='comma'>,</span> <span class='qsymbols_beg'>%i{</span><span class='tstring_content'>show</span><span class='tstring_end'>}</span></span><span class='comma'>,</span> <span class='const'>StringBox</span><span class='comma'>,</span>
|
551
|
+
<span class='symbol'>:timestamp</span><span class='comma'>,</span> <span class='const'>TimeBox</span><span class='comma'>,</span>
|
552
|
+
<span class='symbol'>:count</span><span class='comma'>,</span> <span class='qsymbols_beg'>%i{</span><span class='tstring_content'>show</span><span class='tstring_end'>}</span></span><span class='comma'>,</span> <span class='const'>NumBox</span><span class='comma'>,</span>
|
553
|
+
<span class='symbol'>:url</span><span class='comma'>,</span> <span class='const'>URIBox</span><span class='comma'>,</span>
|
554
|
+
<span class='rparen'>)</span>
|
555
|
+
<span class='kw'>end</span>
|
556
|
+
</code></pre>
|
557
|
+
|
558
|
+
<p><span class='object_link'><a href="#fields-class_method" title="Shep::Entity.fields (method)">fields</a></span> takes a variable sequence of arguments that must be grouped as follows:</p>
|
559
|
+
<ol><li>
|
560
|
+
<p>The field name. This <strong>must</strong> be a symbol.</p>
|
561
|
+
</li><li>
|
562
|
+
<p>An optional Array containing the symbol :show. If given, this field will be included in the string returned by <code>to_s</code>. (This is actually a mechanism for setting various properties, but all we need is <code>:show</code>, so that's it for now.)</p>
|
563
|
+
</li><li>
|
564
|
+
<p>The type specifier. If omitted, defaults to StringBox.</p>
|
565
|
+
</li></ol>
|
566
|
+
|
567
|
+
<p>The type specifier must be either:</p>
|
568
|
+
<ol><li>
|
569
|
+
<p>One of the following classes: <code>TypeBox</code>, <code>StringBox</code>, <code>TimeBox</code>, <code>URIBox</code>, or <code>NumBox</code>, corresponding to the type this field will be.</p>
|
570
|
+
</li><li>
|
571
|
+
<p>A subclass of Entity, indicating that this field holds another Mastodon object.</p>
|
572
|
+
</li><li>
|
573
|
+
<p>An Array holding a single element which must be one of the above classes, indicating that the field holds an array of items of that type.</p>
|
574
|
+
</li></ol>
|
575
|
+
|
576
|
+
|
577
|
+
</div>
|
578
|
+
</div>
|
579
|
+
<div class="tags">
|
580
|
+
|
581
|
+
|
582
|
+
</div><table class="source_code">
|
583
|
+
<tr>
|
584
|
+
<td>
|
585
|
+
<pre class="lines">
|
586
|
+
|
587
|
+
|
588
|
+
276
|
589
|
+
277
|
590
|
+
278
|
591
|
+
279
|
592
|
+
280
|
593
|
+
281
|
594
|
+
282
|
595
|
+
283
|
596
|
+
284
|
597
|
+
285
|
598
|
+
286
|
599
|
+
287
|
600
|
+
288
|
601
|
+
289
|
602
|
+
290
|
603
|
+
291
|
604
|
+
292
|
605
|
+
293
|
606
|
+
294
|
607
|
+
295
|
608
|
+
296
|
609
|
+
297
|
610
|
+
298
|
611
|
+
299
|
612
|
+
300
|
613
|
+
301
|
614
|
+
302
|
615
|
+
303
|
616
|
+
304
|
617
|
+
305
|
618
|
+
306
|
619
|
+
307
|
620
|
+
308
|
621
|
+
309
|
622
|
+
310
|
623
|
+
311
|
624
|
+
312
|
625
|
+
313
|
626
|
+
314
|
627
|
+
315
|
628
|
+
316
|
629
|
+
317
|
630
|
+
318
|
631
|
+
319
|
632
|
+
320
|
633
|
+
321
|
634
|
+
322
|
635
|
+
323
|
636
|
+
324
|
637
|
+
325
|
638
|
+
326
|
639
|
+
327
|
640
|
+
328
|
641
|
+
329
|
642
|
+
330
|
643
|
+
331
|
644
|
+
332
|
645
|
+
333
|
646
|
+
334
|
647
|
+
335
|
648
|
+
336
|
649
|
+
337
|
650
|
+
338
|
651
|
+
339
|
652
|
+
340</pre>
|
653
|
+
</td>
|
654
|
+
<td>
|
655
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 276</span>
|
656
|
+
|
657
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_fields'>fields</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_flds'>flds</span><span class='rparen'>)</span>
|
658
|
+
<span class='id identifier rubyid_known_props'>known_props</span> <span class='op'>=</span> <span class='qsymbols_beg'>%i{</span><span class='tstring_content'>show</span><span class='tstring_end'>}</span></span><span class='period'>.</span><span class='id identifier rubyid_to_set'>to_set</span>
|
659
|
+
|
660
|
+
<span class='id identifier rubyid_names_and_types'>names_and_types</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
661
|
+
<span class='id identifier rubyid_notables'>notables</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
662
|
+
<span class='kw'>until</span> <span class='id identifier rubyid_flds'>flds</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
663
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_flds'>flds</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
664
|
+
<span class='id identifier rubyid_assert'>assert</span><span class='lbrace'>{</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>==</span> <span class='const'>Symbol</span> <span class='rbrace'>}</span>
|
665
|
+
|
666
|
+
<span class='id identifier rubyid_properties'>properties</span> <span class='op'>=</span> <span class='const'>Set</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
667
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_flds'>flds</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Array</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_flds'>flds</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Symbol</span><span class='rparen'>)</span>
|
668
|
+
<span class='id identifier rubyid_properties'>properties</span> <span class='op'>+=</span> <span class='id identifier rubyid_flds'>flds</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
669
|
+
|
670
|
+
<span class='id identifier rubyid_assert'>assert</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown properti(es): </span><span class='embexpr_beg'>#{</span><span class='lparen'>(</span><span class='id identifier rubyid_properties'>properties</span> <span class='op'>-</span> <span class='id identifier rubyid_known_props'>known_props</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_a'>to_a</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
|
671
|
+
<span class='lparen'>(</span><span class='id identifier rubyid_properties'>properties</span> <span class='op'>-</span> <span class='id identifier rubyid_known_props'>known_props</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
672
|
+
<span class='rbrace'>}</span>
|
673
|
+
|
674
|
+
<span class='id identifier rubyid_flds'>flds</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
675
|
+
<span class='kw'>end</span>
|
676
|
+
|
677
|
+
<span class='id identifier rubyid_notables'>notables</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_properties'>properties</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span> <span class='symbol'>:show</span>
|
678
|
+
|
679
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_flds'>flds</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span> <span class='op'>&&</span> <span class='id identifier rubyid_flds'>flds</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>!=</span> <span class='const'>Symbol</span>
|
680
|
+
<span class='id identifier rubyid_typefld'>typefld</span> <span class='op'>=</span> <span class='id identifier rubyid_flds'>flds</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
681
|
+
|
682
|
+
<span class='comment'># Array means ArrayBox with the element as type
|
683
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid_typefld'>typefld</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Array</span>
|
684
|
+
<span class='id identifier rubyid_assert'>assert</span><span class='lbrace'>{</span><span class='id identifier rubyid_typefld'>typefld</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>==</span> <span class='int'>1</span> <span class='op'>&&</span> <span class='id identifier rubyid_typefld'>typefld</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Class</span><span class='rparen'>)</span><span class='rbrace'>}</span>
|
685
|
+
<span class='id identifier rubyid_atype'>atype</span> <span class='op'>=</span> <span class='id identifier rubyid_typefld'>typefld</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
686
|
+
|
687
|
+
<span class='comment'># If this is an array of entity boxes, handle that
|
688
|
+
</span> <span class='id identifier rubyid_atype'>atype</span> <span class='op'>=</span> <span class='const'>EntityBox</span><span class='period'>.</span><span class='id identifier rubyid_wrapping'>wrapping</span><span class='lparen'>(</span><span class='id identifier rubyid_atype'>atype</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_atype'>atype</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="" title="Shep::Entity (class)">Entity</a></span></span>
|
689
|
+
|
690
|
+
<span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='const'>ArrayBox</span><span class='period'>.</span><span class='id identifier rubyid_wrapping'>wrapping</span><span class='lparen'>(</span><span class='id identifier rubyid_atype'>atype</span><span class='rparen'>)</span>
|
691
|
+
|
692
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_typefld'>typefld</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Class</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_typefld'>typefld</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="" title="Shep::Entity (class)">Entity</a></span></span>
|
693
|
+
<span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='const'>EntityBox</span><span class='period'>.</span><span class='id identifier rubyid_wrapping'>wrapping</span><span class='lparen'>(</span><span class='id identifier rubyid_typefld'>typefld</span><span class='rparen'>)</span>
|
694
|
+
|
695
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_typefld'>typefld</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Class</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_typefld'>typefld</span> <span class='op'><</span> <span class='const'>TypeBox</span>
|
696
|
+
<span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_typefld'>typefld</span>
|
697
|
+
|
698
|
+
<span class='kw'>else</span>
|
699
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="Error.html" title="Shep::Error (class)">Error</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Error/Caller.html" title="Shep::Error::Caller (class)">Caller</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown field type '</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_typefld'>typefld</span><span class='embexpr_end'>}</span><span class='tstring_content'>'</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
700
|
+
<span class='kw'>end</span>
|
701
|
+
<span class='kw'>else</span>
|
702
|
+
<span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='const'>StringBox</span>
|
703
|
+
<span class='kw'>end</span>
|
704
|
+
|
705
|
+
<span class='id identifier rubyid_add_fld'>add_fld</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='rparen'>)</span>
|
706
|
+
<span class='id identifier rubyid_names_and_types'>names_and_types</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='rbracket'>]</span>
|
707
|
+
<span class='kw'>end</span>
|
708
|
+
|
709
|
+
<span class='id identifier rubyid_names_and_types'>names_and_types</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>
|
710
|
+
<span class='id identifier rubyid_notables'>notables</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>
|
711
|
+
|
712
|
+
<span class='id identifier rubyid_add_init'>add_init</span><span class='lparen'>(</span><span class='id identifier rubyid_names_and_types'>names_and_types</span><span class='rparen'>)</span>
|
713
|
+
<span class='id identifier rubyid_make_has_name'>make_has_name</span><span class='lparen'>(</span><span class='id identifier rubyid_names_and_types'>names_and_types</span><span class='rparen'>)</span>
|
714
|
+
<span class='id identifier rubyid_make_disp_fields'>make_disp_fields</span><span class='lparen'>(</span><span class='id identifier rubyid_notables'>notables</span><span class='rparen'>)</span>
|
715
|
+
<span class='id identifier rubyid_make_keys'>make_keys</span><span class='lparen'>(</span><span class='id identifier rubyid_names_and_types'>names_and_types</span><span class='rparen'>)</span>
|
716
|
+
|
717
|
+
<span class='comment'># This gets used to generate documentation so we make it private
|
718
|
+
</span> <span class='comment'># and (ab)use Object.send to call it later
|
719
|
+
</span> <span class='id identifier rubyid_define_singleton_method'>define_singleton_method</span><span class='lparen'>(</span><span class='symbol'>:names_and_types</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_names_and_types'>names_and_types</span> <span class='rbrace'>}</span>
|
720
|
+
<span class='id identifier rubyid_singleton_class'>singleton_class</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:private</span><span class='comma'>,</span> <span class='symbol'>:names_and_types</span><span class='rparen'>)</span>
|
721
|
+
<span class='kw'>end</span></pre>
|
722
|
+
</td>
|
723
|
+
</tr>
|
724
|
+
</table>
|
725
|
+
</div>
|
726
|
+
|
727
|
+
<div class="method_details ">
|
728
|
+
<h3 class="signature " id="from-class_method">
|
729
|
+
|
730
|
+
.<strong>from</strong>(json_hash) ⇒ <tt>Object</tt>
|
731
|
+
|
732
|
+
|
733
|
+
|
734
|
+
|
735
|
+
|
736
|
+
</h3><div class="docstring">
|
737
|
+
<div class="discussion">
|
738
|
+
|
739
|
+
<p>Construct an instance from the (parsed) JSON object returned by Mastodon.</p>
|
740
|
+
|
741
|
+
<p>Values must be of the expected types as they appear in the Mastodon object (i.e. the JSON Hash described above). Missing key/value pairs are allowed and treated as nil; unknown keys are ignored.</p>
|
742
|
+
|
743
|
+
|
744
|
+
</div>
|
745
|
+
</div>
|
746
|
+
<div class="tags">
|
747
|
+
|
748
|
+
|
749
|
+
</div><table class="source_code">
|
750
|
+
<tr>
|
751
|
+
<td>
|
752
|
+
<pre class="lines">
|
753
|
+
|
754
|
+
|
755
|
+
87
|
756
|
+
88</pre>
|
757
|
+
</td>
|
758
|
+
<td>
|
759
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 87</span>
|
760
|
+
|
761
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_from'>from</span><span class='lparen'>(</span><span class='id identifier rubyid_json_hash'>json_hash</span><span class='rparen'>)</span> <span class='op'>=</span>
|
762
|
+
<span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_set_from_hash!'>set_from_hash!</span><span class='lparen'>(</span><span class='id identifier rubyid_json_hash'>json_hash</span><span class='comma'>,</span> <span class='label'>ignore_unknown:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>from_json:</span> <span class='kw'>true</span><span class='rparen'>)</span></pre>
|
763
|
+
</td>
|
764
|
+
</tr>
|
765
|
+
</table>
|
766
|
+
</div>
|
767
|
+
|
768
|
+
<div class="method_details ">
|
769
|
+
<h3 class="signature " id="with-class_method">
|
770
|
+
|
771
|
+
.<strong>with</strong>(**fields) ⇒ <tt>Object</tt>
|
772
|
+
|
773
|
+
|
774
|
+
|
775
|
+
|
776
|
+
|
777
|
+
</h3><div class="docstring">
|
778
|
+
<div class="discussion">
|
779
|
+
|
780
|
+
<p>Construct an instance initialized with Ruby objects.</p>
|
781
|
+
|
782
|
+
<p>This intended for creating <span class='object_link'><a href="" title="Shep::Entity (class)">Shep::Entity</a></span> subobjects in Ruby code. Keys of <span class='object_link'><a href="#fields-class_method" title="Shep::Entity.fields (method)">fields</a></span> must correspond to the class’s supported fields and be of the correct type. No fields may be omitted.</p>
|
783
|
+
|
784
|
+
|
785
|
+
</div>
|
786
|
+
</div>
|
787
|
+
<div class="tags">
|
788
|
+
|
789
|
+
|
790
|
+
</div><table class="source_code">
|
791
|
+
<tr>
|
792
|
+
<td>
|
793
|
+
<pre class="lines">
|
794
|
+
|
795
|
+
|
796
|
+
75
|
797
|
+
76
|
798
|
+
77
|
799
|
+
78</pre>
|
800
|
+
</td>
|
801
|
+
<td>
|
802
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 75</span>
|
803
|
+
|
804
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_fields'>fields</span><span class='rparen'>)</span> <span class='op'>=</span>
|
805
|
+
<span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_set_from_hash!'>set_from_hash!</span><span class='lparen'>(</span><span class='id identifier rubyid_fields'>fields</span><span class='comma'>,</span>
|
806
|
+
<span class='label'>ignore_unknown:</span> <span class='kw'>false</span><span class='comma'>,</span>
|
807
|
+
<span class='label'>from_json:</span> <span class='kw'>false</span><span class='rparen'>)</span></pre>
|
808
|
+
</td>
|
809
|
+
</tr>
|
810
|
+
</table>
|
811
|
+
</div>
|
812
|
+
|
813
|
+
</div>
|
814
|
+
|
815
|
+
<div id="instance_method_details" class="method_details_list">
|
816
|
+
<h2>Instance Method Details</h2>
|
817
|
+
|
818
|
+
|
819
|
+
<div class="method_details first">
|
820
|
+
<h3 class="signature first" id="==-instance_method">
|
821
|
+
|
822
|
+
#<strong>==</strong>(other) ⇒ <tt>Boolean</tt>
|
823
|
+
|
824
|
+
|
825
|
+
|
826
|
+
|
827
|
+
|
828
|
+
</h3><div class="docstring">
|
829
|
+
<div class="discussion">
|
830
|
+
|
831
|
+
<p>Compare for equality.</p>
|
832
|
+
|
833
|
+
<p>Two Entity subinstances are identical if they are of the same class and all of their field values are also equal according to <code>:==</code></p>
|
834
|
+
|
835
|
+
|
836
|
+
</div>
|
837
|
+
</div>
|
838
|
+
<div class="tags">
|
839
|
+
|
840
|
+
<p class="tag_title">Returns:</p>
|
841
|
+
<ul class="return">
|
842
|
+
|
843
|
+
<li>
|
844
|
+
|
845
|
+
|
846
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
847
|
+
|
848
|
+
|
849
|
+
|
850
|
+
</li>
|
851
|
+
|
852
|
+
</ul>
|
853
|
+
|
854
|
+
</div><table class="source_code">
|
855
|
+
<tr>
|
856
|
+
<td>
|
857
|
+
<pre class="lines">
|
858
|
+
|
859
|
+
|
860
|
+
176
|
861
|
+
177
|
862
|
+
178
|
863
|
+
179
|
864
|
+
180</pre>
|
865
|
+
</td>
|
866
|
+
<td>
|
867
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 176</span>
|
868
|
+
|
869
|
+
<span class='kw'>def</span> <span class='op'>==</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
|
870
|
+
<span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</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>
|
871
|
+
<span class='id identifier rubyid_keys'>keys</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='op'>|</span> <span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='kw'>self</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='id identifier rubyid_other'>other</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span> <span class='rbrace'>}</span>
|
872
|
+
<span class='kw'>return</span> <span class='kw'>true</span>
|
873
|
+
<span class='kw'>end</span></pre>
|
874
|
+
</td>
|
875
|
+
</tr>
|
876
|
+
</table>
|
877
|
+
</div>
|
878
|
+
|
879
|
+
<div class="method_details ">
|
880
|
+
<h3 class="signature " id="[]-instance_method">
|
881
|
+
|
882
|
+
#<strong>[]</strong>(key) ⇒ <tt>Object</tt>
|
883
|
+
|
884
|
+
|
885
|
+
|
886
|
+
|
887
|
+
|
888
|
+
</h3><div class="docstring">
|
889
|
+
<div class="discussion">
|
890
|
+
|
891
|
+
<p>Retrieve a field value by name</p>
|
892
|
+
|
893
|
+
|
894
|
+
</div>
|
895
|
+
</div>
|
896
|
+
<div class="tags">
|
897
|
+
<p class="tag_title">Parameters:</p>
|
898
|
+
<ul class="param">
|
899
|
+
|
900
|
+
<li>
|
901
|
+
|
902
|
+
<span class='name'>key</span>
|
903
|
+
|
904
|
+
|
905
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
906
|
+
|
907
|
+
|
908
|
+
|
909
|
+
</li>
|
910
|
+
|
911
|
+
</ul>
|
912
|
+
|
913
|
+
<p class="tag_title">Returns:</p>
|
914
|
+
<ul class="return">
|
915
|
+
|
916
|
+
<li>
|
917
|
+
|
918
|
+
|
919
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
920
|
+
|
921
|
+
|
922
|
+
|
923
|
+
</li>
|
924
|
+
|
925
|
+
</ul>
|
926
|
+
|
927
|
+
</div><table class="source_code">
|
928
|
+
<tr>
|
929
|
+
<td>
|
930
|
+
<pre class="lines">
|
931
|
+
|
932
|
+
|
933
|
+
156</pre>
|
934
|
+
</td>
|
935
|
+
<td>
|
936
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 156</span>
|
937
|
+
|
938
|
+
<span class='kw'>def</span> <span class='op'>[]</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='op'>=</span> <span class='id identifier rubyid_getbox'>getbox</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span></pre>
|
939
|
+
</td>
|
940
|
+
</tr>
|
941
|
+
</table>
|
942
|
+
</div>
|
943
|
+
|
944
|
+
<div class="method_details ">
|
945
|
+
<h3 class="signature " id="[]=-instance_method">
|
946
|
+
|
947
|
+
#<strong>[]=</strong>(key, value) ⇒ <tt>Object</tt>
|
948
|
+
|
949
|
+
|
950
|
+
|
951
|
+
|
952
|
+
|
953
|
+
</h3><div class="docstring">
|
954
|
+
<div class="discussion">
|
955
|
+
|
956
|
+
<p>Set a field value by name</p>
|
957
|
+
|
958
|
+
|
959
|
+
</div>
|
960
|
+
</div>
|
961
|
+
<div class="tags">
|
962
|
+
<p class="tag_title">Parameters:</p>
|
963
|
+
<ul class="param">
|
964
|
+
|
965
|
+
<li>
|
966
|
+
|
967
|
+
<span class='name'>key</span>
|
968
|
+
|
969
|
+
|
970
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
971
|
+
|
972
|
+
|
973
|
+
|
974
|
+
</li>
|
975
|
+
|
976
|
+
<li>
|
977
|
+
|
978
|
+
<span class='name'>value</span>
|
979
|
+
|
980
|
+
|
981
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
982
|
+
|
983
|
+
|
984
|
+
|
985
|
+
</li>
|
986
|
+
|
987
|
+
</ul>
|
988
|
+
|
989
|
+
<p class="tag_title">Returns:</p>
|
990
|
+
<ul class="return">
|
991
|
+
|
992
|
+
<li>
|
993
|
+
|
994
|
+
|
995
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
996
|
+
|
997
|
+
|
998
|
+
|
999
|
+
—
|
1000
|
+
<div class='inline'>
|
1001
|
+
<p>the <code>value</code> parameter</p>
|
1002
|
+
</div>
|
1003
|
+
|
1004
|
+
</li>
|
1005
|
+
|
1006
|
+
</ul>
|
1007
|
+
|
1008
|
+
</div><table class="source_code">
|
1009
|
+
<tr>
|
1010
|
+
<td>
|
1011
|
+
<pre class="lines">
|
1012
|
+
|
1013
|
+
|
1014
|
+
164
|
1015
|
+
165
|
1016
|
+
166
|
1017
|
+
167</pre>
|
1018
|
+
</td>
|
1019
|
+
<td>
|
1020
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 164</span>
|
1021
|
+
|
1022
|
+
<span class='kw'>def</span> <span class='op'>[]=</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
1023
|
+
<span class='id identifier rubyid_getbox'>getbox</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_set'>set</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
1024
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span>
|
1025
|
+
<span class='kw'>end</span></pre>
|
1026
|
+
</td>
|
1027
|
+
</tr>
|
1028
|
+
</table>
|
1029
|
+
</div>
|
1030
|
+
|
1031
|
+
<div class="method_details ">
|
1032
|
+
<h3 class="signature " id="print-instance_method">
|
1033
|
+
|
1034
|
+
#<strong>print</strong> ⇒ <tt>Object</tt>
|
1035
|
+
|
1036
|
+
|
1037
|
+
|
1038
|
+
|
1039
|
+
|
1040
|
+
</h3><div class="docstring">
|
1041
|
+
<div class="discussion">
|
1042
|
+
|
1043
|
+
<p>Wrapper around <code>puts to_long_s()</code></p>
|
1044
|
+
|
1045
|
+
|
1046
|
+
</div>
|
1047
|
+
</div>
|
1048
|
+
<div class="tags">
|
1049
|
+
|
1050
|
+
|
1051
|
+
</div><table class="source_code">
|
1052
|
+
<tr>
|
1053
|
+
<td>
|
1054
|
+
<pre class="lines">
|
1055
|
+
|
1056
|
+
|
1057
|
+
227</pre>
|
1058
|
+
</td>
|
1059
|
+
<td>
|
1060
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 227</span>
|
1061
|
+
|
1062
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_print'>print</span> <span class='op'>=</span> <span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='id identifier rubyid_to_long_s'>to_long_s</span><span class='rparen'>)</span></pre>
|
1063
|
+
</td>
|
1064
|
+
</tr>
|
1065
|
+
</table>
|
1066
|
+
</div>
|
1067
|
+
|
1068
|
+
<div class="method_details ">
|
1069
|
+
<h3 class="signature " id="set_from_hash!-instance_method">
|
1070
|
+
|
1071
|
+
#<strong>set_from_hash!</strong>(some_hash, ignore_unknown: false, from_json: false) ⇒ <tt>Object</tt>
|
1072
|
+
|
1073
|
+
|
1074
|
+
|
1075
|
+
|
1076
|
+
|
1077
|
+
</h3><div class="docstring">
|
1078
|
+
<div class="discussion">
|
1079
|
+
|
1080
|
+
<p>Set all fields from a hash.</p>
|
1081
|
+
|
1082
|
+
<p>This is the back-end for <span class='object_link'><a href="#from-class_method" title="Shep::Entity.from (method)">from</a></span> and <span class='object_link'><a href="#with-class_method" title="Shep::Entity.with (method)">with</a></span>.</p>
|
1083
|
+
|
1084
|
+
|
1085
|
+
</div>
|
1086
|
+
</div>
|
1087
|
+
<div class="tags">
|
1088
|
+
<p class="tag_title">Parameters:</p>
|
1089
|
+
<ul class="param">
|
1090
|
+
|
1091
|
+
<li>
|
1092
|
+
|
1093
|
+
<span class='name'>some_hash</span>
|
1094
|
+
|
1095
|
+
|
1096
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
1097
|
+
|
1098
|
+
|
1099
|
+
|
1100
|
+
—
|
1101
|
+
<div class='inline'>
|
1102
|
+
<p>the Hash containing the contents</p>
|
1103
|
+
</div>
|
1104
|
+
|
1105
|
+
</li>
|
1106
|
+
|
1107
|
+
<li>
|
1108
|
+
|
1109
|
+
<span class='name'>ignore_unknown</span>
|
1110
|
+
|
1111
|
+
|
1112
|
+
<span class='type'>(<tt>Bool</tt>)</span>
|
1113
|
+
|
1114
|
+
|
1115
|
+
<em class="default">(defaults to: <tt>false</tt>)</em>
|
1116
|
+
|
1117
|
+
|
1118
|
+
—
|
1119
|
+
<div class='inline'>
|
1120
|
+
<p>if false, unknown keys cause an error</p>
|
1121
|
+
</div>
|
1122
|
+
|
1123
|
+
</li>
|
1124
|
+
|
1125
|
+
<li>
|
1126
|
+
|
1127
|
+
<span class='name'>from_json</span>
|
1128
|
+
|
1129
|
+
|
1130
|
+
<span class='type'>(<tt>Bool</tt>)</span>
|
1131
|
+
|
1132
|
+
|
1133
|
+
<em class="default">(defaults to: <tt>false</tt>)</em>
|
1134
|
+
|
1135
|
+
|
1136
|
+
—
|
1137
|
+
<div class='inline'>
|
1138
|
+
<p>if true, expect values in the format provided by the Mastodon API and convert accordingly. Otherwise, expect Ruby types.</p>
|
1139
|
+
</div>
|
1140
|
+
|
1141
|
+
</li>
|
1142
|
+
|
1143
|
+
</ul>
|
1144
|
+
|
1145
|
+
|
1146
|
+
</div><table class="source_code">
|
1147
|
+
<tr>
|
1148
|
+
<td>
|
1149
|
+
<pre class="lines">
|
1150
|
+
|
1151
|
+
|
1152
|
+
103
|
1153
|
+
104
|
1154
|
+
105
|
1155
|
+
106
|
1156
|
+
107
|
1157
|
+
108
|
1158
|
+
109
|
1159
|
+
110
|
1160
|
+
111
|
1161
|
+
112
|
1162
|
+
113
|
1163
|
+
114
|
1164
|
+
115
|
1165
|
+
116
|
1166
|
+
117
|
1167
|
+
118
|
1168
|
+
119
|
1169
|
+
120</pre>
|
1170
|
+
</td>
|
1171
|
+
<td>
|
1172
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 103</span>
|
1173
|
+
|
1174
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_set_from_hash!'>set_from_hash!</span><span class='lparen'>(</span><span class='id identifier rubyid_some_hash'>some_hash</span><span class='comma'>,</span> <span class='label'>ignore_unknown:</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='label'>from_json:</span> <span class='kw'>false</span><span class='rparen'>)</span>
|
1175
|
+
<span class='id identifier rubyid_some_hash'>some_hash</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_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
|
1176
|
+
<span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_intern'>intern</span>
|
1177
|
+
<span class='kw'>unless</span> <span class='id identifier rubyid_has_fld?'>has_fld?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
1178
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="Error.html" title="Shep::Error (class)">Error</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Error/Caller.html" title="Shep::Error::Caller (class)">Caller</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown field: '</span><span class='embexpr_beg'>#{</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'>unless</span>
|
1179
|
+
<span class='id identifier rubyid_ignore_unknown'>ignore_unknown</span>
|
1180
|
+
<span class='kw'>next</span>
|
1181
|
+
<span class='kw'>end</span>
|
1182
|
+
|
1183
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_from_json'>from_json</span>
|
1184
|
+
<span class='id identifier rubyid_getbox'>getbox</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_set_from_json'>set_from_json</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
1185
|
+
<span class='kw'>else</span>
|
1186
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</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='period'>.</span><span class='id identifier rubyid_intern'>intern</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
1187
|
+
<span class='kw'>end</span>
|
1188
|
+
<span class='kw'>end</span>
|
1189
|
+
|
1190
|
+
<span class='kw'>return</span> <span class='kw'>self</span>
|
1191
|
+
<span class='kw'>end</span></pre>
|
1192
|
+
</td>
|
1193
|
+
</tr>
|
1194
|
+
</table>
|
1195
|
+
</div>
|
1196
|
+
|
1197
|
+
<div class="method_details ">
|
1198
|
+
<h3 class="signature " id="to_h-instance_method">
|
1199
|
+
|
1200
|
+
#<strong>to_h</strong>(json_compatible = false) ⇒ <tt>Hash</tt>
|
1201
|
+
|
1202
|
+
|
1203
|
+
|
1204
|
+
|
1205
|
+
|
1206
|
+
</h3><div class="docstring">
|
1207
|
+
<div class="discussion">
|
1208
|
+
|
1209
|
+
<p>Return a hash of the contents mapping field name to value.</p>
|
1210
|
+
|
1211
|
+
<p>If <code>json_compatible</code> is true, the resulting hash will be easily convertable to Mastodon-format JSON. See above.</p>
|
1212
|
+
|
1213
|
+
<p>Unset (i.e. nil) values appear as entries with nil values.</p>
|
1214
|
+
|
1215
|
+
|
1216
|
+
</div>
|
1217
|
+
</div>
|
1218
|
+
<div class="tags">
|
1219
|
+
<p class="tag_title">Parameters:</p>
|
1220
|
+
<ul class="param">
|
1221
|
+
|
1222
|
+
<li>
|
1223
|
+
|
1224
|
+
<span class='name'>json_compatible</span>
|
1225
|
+
|
1226
|
+
|
1227
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
1228
|
+
|
1229
|
+
|
1230
|
+
<em class="default">(defaults to: <tt>false</tt>)</em>
|
1231
|
+
|
1232
|
+
|
1233
|
+
—
|
1234
|
+
<div class='inline'>
|
1235
|
+
<p>if true, convert to JSON-friendly form</p>
|
1236
|
+
</div>
|
1237
|
+
|
1238
|
+
</li>
|
1239
|
+
|
1240
|
+
</ul>
|
1241
|
+
|
1242
|
+
<p class="tag_title">Returns:</p>
|
1243
|
+
<ul class="return">
|
1244
|
+
|
1245
|
+
<li>
|
1246
|
+
|
1247
|
+
|
1248
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
1249
|
+
|
1250
|
+
|
1251
|
+
|
1252
|
+
</li>
|
1253
|
+
|
1254
|
+
</ul>
|
1255
|
+
|
1256
|
+
</div><table class="source_code">
|
1257
|
+
<tr>
|
1258
|
+
<td>
|
1259
|
+
<pre class="lines">
|
1260
|
+
|
1261
|
+
|
1262
|
+
192
|
1263
|
+
193
|
1264
|
+
194
|
1265
|
+
195
|
1266
|
+
196
|
1267
|
+
197
|
1268
|
+
198
|
1269
|
+
199
|
1270
|
+
200
|
1271
|
+
201
|
1272
|
+
202
|
1273
|
+
203
|
1274
|
+
204
|
1275
|
+
205</pre>
|
1276
|
+
</td>
|
1277
|
+
<td>
|
1278
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 192</span>
|
1279
|
+
|
1280
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_to_h'>to_h</span><span class='lparen'>(</span><span class='id identifier rubyid_json_compatible'>json_compatible</span> <span class='op'>=</span> <span class='kw'>false</span><span class='rparen'>)</span>
|
1281
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
1282
|
+
|
1283
|
+
<span class='id identifier rubyid_keys'>keys</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_name'>name</span><span class='op'>|</span>
|
1284
|
+
<span class='id identifier rubyid_hkey'>hkey</span> <span class='op'>=</span> <span class='id identifier rubyid_json_compatible'>json_compatible</span> <span class='op'>?</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>:</span> <span class='id identifier rubyid_name'>name</span>
|
1285
|
+
|
1286
|
+
<span class='id identifier rubyid_box'>box</span> <span class='op'>=</span> <span class='id identifier rubyid_getbox'>getbox</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
1287
|
+
<span class='id identifier rubyid_val'>val</span> <span class='op'>=</span> <span class='id identifier rubyid_json_compatible'>json_compatible</span> <span class='op'>?</span> <span class='id identifier rubyid_box'>box</span><span class='period'>.</span><span class='id identifier rubyid_get_for_json'>get_for_json</span> <span class='op'>:</span> <span class='id identifier rubyid_box'>box</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span>
|
1288
|
+
|
1289
|
+
<span class='id identifier rubyid_result'>result</span><span class='lbracket'>[</span><span class='id identifier rubyid_hkey'>hkey</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_val'>val</span>
|
1290
|
+
<span class='rbrace'>}</span>
|
1291
|
+
|
1292
|
+
<span class='id identifier rubyid_result'>result</span>
|
1293
|
+
<span class='kw'>end</span></pre>
|
1294
|
+
</td>
|
1295
|
+
</tr>
|
1296
|
+
</table>
|
1297
|
+
</div>
|
1298
|
+
|
1299
|
+
<div class="method_details ">
|
1300
|
+
<h3 class="signature " id="to_long_s-instance_method">
|
1301
|
+
|
1302
|
+
#<strong>to_long_s</strong>(indent_level = 0) ⇒ <tt>String</tt>
|
1303
|
+
|
1304
|
+
|
1305
|
+
|
1306
|
+
|
1307
|
+
|
1308
|
+
</h3><div class="docstring">
|
1309
|
+
<div class="discussion">
|
1310
|
+
|
1311
|
+
<p>Produce a long-form human-friendly description of this Entity.</p>
|
1312
|
+
|
1313
|
+
<p>This is mostly here for debugging.</p>
|
1314
|
+
|
1315
|
+
|
1316
|
+
</div>
|
1317
|
+
</div>
|
1318
|
+
<div class="tags">
|
1319
|
+
|
1320
|
+
<p class="tag_title">Returns:</p>
|
1321
|
+
<ul class="return">
|
1322
|
+
|
1323
|
+
<li>
|
1324
|
+
|
1325
|
+
|
1326
|
+
<span class='type'>(<tt>String</tt>)</span>
|
1327
|
+
|
1328
|
+
|
1329
|
+
|
1330
|
+
</li>
|
1331
|
+
|
1332
|
+
</ul>
|
1333
|
+
|
1334
|
+
</div><table class="source_code">
|
1335
|
+
<tr>
|
1336
|
+
<td>
|
1337
|
+
<pre class="lines">
|
1338
|
+
|
1339
|
+
|
1340
|
+
212
|
1341
|
+
213
|
1342
|
+
214
|
1343
|
+
215
|
1344
|
+
216
|
1345
|
+
217
|
1346
|
+
218
|
1347
|
+
219
|
1348
|
+
220
|
1349
|
+
221
|
1350
|
+
222
|
1351
|
+
223
|
1352
|
+
224</pre>
|
1353
|
+
</td>
|
1354
|
+
<td>
|
1355
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 212</span>
|
1356
|
+
|
1357
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_to_long_s'>to_long_s</span><span class='lparen'>(</span><span class='id identifier rubyid_indent_level'>indent_level</span> <span class='op'>=</span> <span class='int'>0</span><span class='rparen'>)</span>
|
1358
|
+
<span class='id identifier rubyid_name_pad'>name_pad</span> <span class='op'>=</span> <span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:size</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_max'>max</span> <span class='op'>+</span> <span class='int'>2</span>
|
1359
|
+
|
1360
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='op'>|</span>
|
1361
|
+
<span class='id identifier rubyid_line'>line</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='op'>*</span> <span class='lparen'>(</span><span class='id identifier rubyid_indent_level'>indent_level</span> <span class='op'>*</span> <span class='int'>2</span><span class='rparen'>)</span>
|
1362
|
+
<span class='id identifier rubyid_line'>line</span> <span class='op'>+=</span> <span class='id identifier rubyid_sprintf'>sprintf</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>%-*s</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_name_pad'>name_pad</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</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>
|
1363
|
+
|
1364
|
+
<span class='id identifier rubyid_val'>val</span> <span class='op'>=</span> <span class='kw'>self</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span>
|
1365
|
+
<span class='id identifier rubyid_line'>line</span> <span class='op'>+=</span> <span class='id identifier rubyid_val'>val</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="" title="Shep::Entity (class)">Entity</a></span></span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_val'>val</span><span class='period'>.</span><span class='id identifier rubyid_to_long_s'>to_long_s</span><span class='lparen'>(</span><span class='id identifier rubyid_indent_level'>indent_level</span> <span class='op'>+</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_val'>val</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
1366
|
+
<span class='kw'>end</span>
|
1367
|
+
|
1368
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_result'>result</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'>\n</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1369
|
+
<span class='kw'>end</span></pre>
|
1370
|
+
</td>
|
1371
|
+
</tr>
|
1372
|
+
</table>
|
1373
|
+
</div>
|
1374
|
+
|
1375
|
+
<div class="method_details ">
|
1376
|
+
<h3 class="signature " id="to_s-instance_method">
|
1377
|
+
|
1378
|
+
#<strong>to_s</strong> ⇒ <tt>String</tt>
|
1379
|
+
|
1380
|
+
|
1381
|
+
|
1382
|
+
<span class="aliases">Also known as:
|
1383
|
+
<span class="names"><span id='inspect-instance_method'>inspect</span></span>
|
1384
|
+
</span>
|
1385
|
+
|
1386
|
+
|
1387
|
+
|
1388
|
+
</h3><div class="docstring">
|
1389
|
+
<div class="discussion">
|
1390
|
+
|
1391
|
+
<p>Produce a <strong>short</strong> human-friendly description.</p>
|
1392
|
+
|
1393
|
+
|
1394
|
+
</div>
|
1395
|
+
</div>
|
1396
|
+
<div class="tags">
|
1397
|
+
|
1398
|
+
<p class="tag_title">Returns:</p>
|
1399
|
+
<ul class="return">
|
1400
|
+
|
1401
|
+
<li>
|
1402
|
+
|
1403
|
+
|
1404
|
+
<span class='type'>(<tt>String</tt>)</span>
|
1405
|
+
|
1406
|
+
|
1407
|
+
|
1408
|
+
</li>
|
1409
|
+
|
1410
|
+
</ul>
|
1411
|
+
|
1412
|
+
</div><table class="source_code">
|
1413
|
+
<tr>
|
1414
|
+
<td>
|
1415
|
+
<pre class="lines">
|
1416
|
+
|
1417
|
+
|
1418
|
+
130
|
1419
|
+
131
|
1420
|
+
132
|
1421
|
+
133
|
1422
|
+
134
|
1423
|
+
135
|
1424
|
+
136
|
1425
|
+
137
|
1426
|
+
138</pre>
|
1427
|
+
</td>
|
1428
|
+
<td>
|
1429
|
+
<pre class="code"><span class="info file"># File 'lib/shep/entity_base.rb', line 130</span>
|
1430
|
+
|
1431
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_to_s'>to_s</span>
|
1432
|
+
<span class='id identifier rubyid_notable'>notable</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_disp_fields'>disp_fields</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
1433
|
+
<span class='period'>.</span><span class='id identifier rubyid_reject'>reject</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_fld'>fld</span><span class='op'>|</span> <span class='id identifier rubyid_getbox'>getbox</span><span class='lparen'>(</span><span class='id identifier rubyid_fld'>fld</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_get_for_json'>get_for_json</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span> <span class='rbrace'>}</span>
|
1434
|
+
<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_fld'>fld</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_fld'>fld</span><span class='embexpr_end'>}</span><span class='tstring_content'>=</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_getbox'>getbox</span><span class='lparen'>(</span><span class='id identifier rubyid_fld'>fld</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rbrace'>}</span>
|
1435
|
+
<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>
|
1436
|
+
<span class='id identifier rubyid_notable'>notable</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0x</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_object_id'>object_id</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='int'>16</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_notable'>notable</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
1437
|
+
|
1438
|
+
<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'><</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_notable'>notable</span><span class='embexpr_end'>}</span><span class='tstring_content'>></span><span class='tstring_end'>"</span></span>
|
1439
|
+
<span class='kw'>end</span></pre>
|
1440
|
+
</td>
|
1441
|
+
</tr>
|
1442
|
+
</table>
|
1443
|
+
</div>
|
1444
|
+
|
1445
|
+
</div>
|
1446
|
+
|
1447
|
+
</div>
|
1448
|
+
|
1449
|
+
<div id="footer">
|
1450
|
+
Generated on Sun Jun 4 13:40:31 2023 by
|
1451
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1452
|
+
0.9.34 (ruby-3.1.0).
|
1453
|
+
</div>
|
1454
|
+
|
1455
|
+
</div>
|
1456
|
+
</body>
|
1457
|
+
</html>
|