otoroshi 0.0.7 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1511 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Module: Otoroshi::Sanctuary::ClassMethods
8
-
9
- &mdash; Documentation by YARD 0.9.25
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 = "Otoroshi::Sanctuary::ClassMethods";
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 (C)</a> &raquo;
40
- <span class='title'><span class='object_link'><a href="../../Otoroshi.html" title="Otoroshi (module)">Otoroshi</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Sanctuary.html" title="Otoroshi::Sanctuary (module)">Sanctuary</a></span></span>
41
- &raquo;
42
- <span class="title">ClassMethods</span>
43
-
44
- </div>
45
-
46
- <div id="search">
47
-
48
- <a class="full_list_link" id="class_list_link"
49
- href="../../class_list.html">
50
-
51
- <svg width="24" height="24">
52
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
- </svg>
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <div id="content"><h1>Module: Otoroshi::Sanctuary::ClassMethods
63
-
64
-
65
-
66
- </h1>
67
- <div class="box_info">
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
- <dl>
80
- <dt>Defined in:</dt>
81
- <dd>lib/otoroshi/sanctuary.rb</dd>
82
- </dl>
83
-
84
- </div>
85
-
86
- <h2>Overview</h2><div class="docstring">
87
- <div class="discussion">
88
-
89
- <p>Class methods extended for the base class</p>
90
-
91
-
92
- </div>
93
- </div>
94
- <div class="tags">
95
-
96
-
97
- </div>
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
- <h2>
106
- Instance Method Summary
107
- <small><a href="#" class="summary_toggle">collapse</a></small>
108
- </h2>
109
-
110
- <ul class="summary">
111
-
112
- <li class="private ">
113
- <span class="summary_signature">
114
-
115
- <a href="#add_to_properties-instance_method" title="#add_to_properties (instance method)">#<strong>add_to_properties</strong>(name, allow_nil, default) &#x21d2; void </a>
116
-
117
-
118
-
119
- </span>
120
-
121
-
122
-
123
- <span class="note title private">private</span>
124
-
125
-
126
-
127
-
128
-
129
- <span class="summary_desc"><div class='inline'>
130
- <p>Updates <span class='object_link'><a href="#properties-instance_method" title="Otoroshi::Sanctuary::ClassMethods#properties (method)">#properties</a></span> to add new property to the returned ones.</p>
131
- </div></span>
132
-
133
- </li>
134
-
135
-
136
- <li class="private ">
137
- <span class="summary_signature">
138
-
139
- <a href="#default_parameter_for-instance_method" title="#default_parameter_for (instance method)">#<strong>default_parameter_for</strong>(allow_nil, default) &#x21d2; String </a>
140
-
141
-
142
-
143
- </span>
144
-
145
-
146
-
147
- <span class="note title private">private</span>
148
-
149
-
150
-
151
-
152
-
153
- <span class="summary_desc"><div class='inline'>
154
- <p>Defines the default value of a parameter depending on options.</p>
155
- </div></span>
156
-
157
- </li>
158
-
159
-
160
- <li class="private ">
161
- <span class="summary_signature">
162
-
163
- <a href="#define_getter-instance_method" title="#define_getter (instance method)">#<strong>define_getter</strong>(name) &#x21d2; void </a>
164
-
165
-
166
-
167
- </span>
168
-
169
-
170
-
171
- <span class="note title private">private</span>
172
-
173
-
174
-
175
-
176
-
177
- <span class="summary_desc"><div class='inline'>
178
- <p>Defines a getter method for the property.</p>
179
- </div></span>
180
-
181
- </li>
182
-
183
-
184
- <li class="private ">
185
- <span class="summary_signature">
186
-
187
- <a href="#define_setter-instance_method" title="#define_setter (instance method)">#<strong>define_setter</strong>(name) &#x21d2; void </a>
188
-
189
-
190
-
191
- </span>
192
-
193
-
194
-
195
- <span class="note title private">private</span>
196
-
197
-
198
-
199
-
200
-
201
- <span class="summary_desc"><div class='inline'>
202
- <p>Defines a setter method for the property.</p>
203
- </div></span>
204
-
205
- </li>
206
-
207
-
208
- <li class="private ">
209
- <span class="summary_signature">
210
-
211
- <a href="#define_validate_lambda!-instance_method" title="#define_validate_lambda! (instance method)">#<strong>define_validate_lambda!</strong>(name, validate, allow_nil) &#x21d2; void </a>
212
-
213
-
214
-
215
- </span>
216
-
217
-
218
-
219
- <span class="note title private">private</span>
220
-
221
-
222
-
223
-
224
-
225
- <span class="summary_desc"><div class='inline'>
226
- <p>Defines a private method that raises an error if validate block returns false.</p>
227
- </div></span>
228
-
229
- </li>
230
-
231
-
232
- <li class="private ">
233
- <span class="summary_signature">
234
-
235
- <a href="#define_validate_type!-instance_method" title="#define_validate_type! (instance method)">#<strong>define_validate_type!</strong>(name, type, allow_nil) &#x21d2; void </a>
236
-
237
-
238
-
239
- </span>
240
-
241
-
242
-
243
- <span class="note title private">private</span>
244
-
245
-
246
-
247
-
248
-
249
- <span class="summary_desc"><div class='inline'>
250
- <p>Defines a private method that raises an error if type is not respected.</p>
251
- </div></span>
252
-
253
- </li>
254
-
255
-
256
- <li class="private ">
257
- <span class="summary_signature">
258
-
259
- <a href="#initialize_body-instance_method" title="#initialize_body (instance method)">#<strong>initialize_body</strong> &#x21d2; String </a>
260
-
261
-
262
-
263
- </span>
264
-
265
-
266
-
267
- <span class="note title private">private</span>
268
-
269
-
270
-
271
-
272
-
273
- <span class="summary_desc"><div class='inline'>
274
- <p>Defines initialize method body.</p>
275
- </div></span>
276
-
277
- </li>
278
-
279
-
280
- <li class="private ">
281
- <span class="summary_signature">
282
-
283
- <a href="#initialize_parameters-instance_method" title="#initialize_parameters (instance method)">#<strong>initialize_parameters</strong> &#x21d2; String </a>
284
-
285
-
286
-
287
- </span>
288
-
289
-
290
-
291
- <span class="note title private">private</span>
292
-
293
-
294
-
295
-
296
-
297
- <span class="summary_desc"><div class='inline'>
298
- <p>Defines initialize method parameters.</p>
299
- </div></span>
300
-
301
- </li>
302
-
303
-
304
- <li class="public ">
305
- <span class="summary_signature">
306
-
307
- <a href="#properties-instance_method" title="#properties (instance method)">#<strong>properties</strong> &#x21d2; Hash </a>
308
-
309
-
310
-
311
- </span>
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
- <span class="summary_desc"><div class='inline'>
322
- <p>Returns the class properties.</p>
323
- </div></span>
324
-
325
- </li>
326
-
327
-
328
- <li class="public ">
329
- <span class="summary_signature">
330
-
331
- <a href="#property-instance_method" title="#property (instance method)">#<strong>property</strong>(name, type = Object, validate: -&gt;(_) { true }, allow_nil: false, default: nil) &#x21d2; void </a>
332
-
333
-
334
-
335
- </span>
336
-
337
-
338
-
339
-
340
-
341
-
342
-
343
-
344
-
345
- <span class="summary_desc"><div class='inline'>
346
- <p>Adds a new “property” to the class.</p>
347
- </div></span>
348
-
349
- </li>
350
-
351
-
352
- <li class="private ">
353
- <span class="summary_signature">
354
-
355
- <a href="#redefine_initialize-instance_method" title="#redefine_initialize (instance method)">#<strong>redefine_initialize</strong> &#x21d2; void </a>
356
-
357
-
358
-
359
- </span>
360
-
361
-
362
-
363
- <span class="note title private">private</span>
364
-
365
-
366
-
367
-
368
-
369
- <span class="summary_desc"><div class='inline'>
370
- <p>Redefines initialize method.</p>
371
- </div></span>
372
-
373
- </li>
374
-
375
-
376
- <li class="private ">
377
- <span class="summary_signature">
378
-
379
- <a href="#type_validation-instance_method" title="#type_validation (instance method)">#<strong>type_validation</strong>(type) &#x21d2; Proc </a>
380
-
381
-
382
-
383
- </span>
384
-
385
-
386
-
387
- <span class="note title private">private</span>
388
-
389
-
390
-
391
-
392
-
393
- <span class="summary_desc"><div class='inline'>
394
- <p>Defines a lambda to be call to validate that value matches the type.</p>
395
- </div></span>
396
-
397
- </li>
398
-
399
-
400
- </ul>
401
-
402
-
403
-
404
-
405
- <div id="instance_method_details" class="method_details_list">
406
- <h2>Instance Method Details</h2>
407
-
408
-
409
- <div class="method_details first">
410
- <h3 class="signature first" id="add_to_properties-instance_method">
411
-
412
- #<strong>add_to_properties</strong>(name, allow_nil, default) &#x21d2; <tt>void</tt> <span class="extras">(private)</span>
413
-
414
-
415
-
416
-
417
-
418
- </h3><div class="docstring">
419
- <div class="discussion">
420
- <p class="note returns_void">This method returns an undefined value.</p>
421
- <p>Updates <span class='object_link'><a href="#properties-instance_method" title="Otoroshi::Sanctuary::ClassMethods#properties (method)">#properties</a></span> to add new property to the returned ones</p>
422
-
423
-
424
- </div>
425
- </div>
426
- <div class="tags">
427
-
428
-
429
- </div><table class="source_code">
430
- <tr>
431
- <td>
432
- <pre class="lines">
433
-
434
-
435
- 56
436
- 57
437
- 58
438
- 59
439
- 60</pre>
440
- </td>
441
- <td>
442
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 56</span>
443
-
444
- <span class='kw'>def</span> <span class='id identifier rubyid_add_to_properties'>add_to_properties</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='comma'>,</span> <span class='id identifier rubyid_default'>default</span><span class='rparen'>)</span>
445
- <span class='id identifier rubyid_current_state'>current_state</span> <span class='op'>=</span> <span class='id identifier rubyid_properties'>properties</span>
446
- <span class='id identifier rubyid_current_state'>current_state</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>allow_nil:</span> <span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='comma'>,</span> <span class='label'>default:</span> <span class='id identifier rubyid_default'>default</span> <span class='rbrace'>}</span>
447
- <span class='id identifier rubyid_define_singleton_method'>define_singleton_method</span><span class='lparen'>(</span><span class='symbol'>:properties</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_current_state'>current_state</span> <span class='rbrace'>}</span>
448
- <span class='kw'>end</span></pre>
449
- </td>
450
- </tr>
451
- </table>
452
- </div>
453
-
454
- <div class="method_details ">
455
- <h3 class="signature " id="default_parameter_for-instance_method">
456
-
457
- #<strong>default_parameter_for</strong>(allow_nil, default) &#x21d2; <tt>String</tt> <span class="extras">(private)</span>
458
-
459
-
460
-
461
-
462
-
463
- </h3><div class="docstring">
464
- <div class="discussion">
465
-
466
- <p>Defines the default value of a parameter depending on options</p>
467
-
468
-
469
- </div>
470
- </div>
471
- <div class="tags">
472
-
473
- <div class="examples">
474
- <p class="tag_title">Examples:</p>
475
-
476
-
477
- <p class="example_title"><div class='inline'>
478
- <p>when nil is allowed and default is set</p>
479
- </div></p>
480
-
481
- <pre class="example code"><code><span class='id identifier rubyid_default_parameter_for'>default_parameter_for</span><span class='lparen'>(</span><span class='kw'>true</span><span class='comma'>,</span> <span class='int'>0</span><span class='rparen'>)</span> <span class='comment'>#=&gt; &quot; 0&quot;</span></code></pre>
482
-
483
-
484
- <p class="example_title"><div class='inline'>
485
- <p>when nil is allowed and default is not set</p>
486
- </div></p>
487
-
488
- <pre class="example code"><code><span class='id identifier rubyid_default_parameter_for'>default_parameter_for</span><span class='lparen'>(</span><span class='kw'>true</span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='comment'>#=&gt; &quot; nil&quot;</span></code></pre>
489
-
490
-
491
- <p class="example_title"><div class='inline'>
492
- <p>when nil is not allowed</p>
493
- </div></p>
494
-
495
- <pre class="example code"><code><span class='id identifier rubyid_default_parameter_for'>default_parameter_for</span><span class='lparen'>(</span><span class='kw'>false</span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='comment'>#=&gt; &quot;&quot;</span></code></pre>
496
-
497
- </div>
498
- <p class="tag_title">Parameters:</p>
499
- <ul class="param">
500
-
501
- <li>
502
-
503
- <span class='name'>options</span>
504
-
505
-
506
- <span class='type'>(<tt>Hash</tt>)</span>
507
-
508
-
509
-
510
- </li>
511
-
512
- </ul>
513
-
514
- <p class="tag_title">Returns:</p>
515
- <ul class="return">
516
-
517
- <li>
518
-
519
-
520
- <span class='type'>(<tt>String</tt>)</span>
521
-
522
-
523
-
524
- </li>
525
-
526
- </ul>
527
-
528
- </div><table class="source_code">
529
- <tr>
530
- <td>
531
- <pre class="lines">
532
-
533
-
534
- 196
535
- 197
536
- 198
537
- 199
538
- 200</pre>
539
- </td>
540
- <td>
541
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 196</span>
542
-
543
- <span class='kw'>def</span> <span class='id identifier rubyid_default_parameter_for'>default_parameter_for</span><span class='lparen'>(</span><span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='comma'>,</span> <span class='id identifier rubyid_default'>default</span><span class='rparen'>)</span>
544
- <span class='kw'>return</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_default'>default</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_default'>default</span>
545
-
546
- <span class='id identifier rubyid_allow_nil'>allow_nil</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'> nil</span><span class='tstring_end'>&#39;</span></span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span>
547
- <span class='kw'>end</span></pre>
548
- </td>
549
- </tr>
550
- </table>
551
- </div>
552
-
553
- <div class="method_details ">
554
- <h3 class="signature " id="define_getter-instance_method">
555
-
556
- #<strong>define_getter</strong>(name) &#x21d2; <tt>void</tt> <span class="extras">(private)</span>
557
-
558
-
559
-
560
-
561
-
562
- </h3><div class="docstring">
563
- <div class="discussion">
564
- <p class="note returns_void">This method returns an undefined value.</p>
565
- <p>Defines a getter method for the property</p>
566
-
567
-
568
- </div>
569
- </div>
570
- <div class="tags">
571
-
572
- <div class="examples">
573
- <p class="tag_title">Examples:</p>
574
-
575
-
576
- <pre class="example code"><code><span class='id identifier rubyid_define_getter'>define_getter</span><span class='lparen'>(</span><span class='symbol'>:score</span><span class='rparen'>)</span> <span class='comment'>#=&gt; def score ...</span></code></pre>
577
-
578
-
579
- <p class="example_title"><div class='inline'>
580
- <p>Generated instance method</p>
581
- </div></p>
582
-
583
- <pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_score'>score</span>
584
- <span class='id identifier rubyid_instance_variable_get'>instance_variable_get</span><span class='lparen'>(</span><span class='ivar'>@score</span><span class='rparen'>)</span>
585
- <span class='kw'>end</span></code></pre>
586
-
587
- </div>
588
- <p class="tag_title">Parameters:</p>
589
- <ul class="param">
590
-
591
- <li>
592
-
593
- <span class='name'>name</span>
594
-
595
-
596
- <span class='type'>(<tt>Symbol</tt>)</span>
597
-
598
-
599
-
600
- &mdash;
601
- <div class='inline'>
602
- <p>the property name</p>
603
- </div>
604
-
605
- </li>
606
-
607
- </ul>
608
-
609
-
610
- </div><table class="source_code">
611
- <tr>
612
- <td>
613
- <pre class="lines">
614
-
615
-
616
- 135
617
- 136
618
- 137</pre>
619
- </td>
620
- <td>
621
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 135</span>
622
-
623
- <span class='kw'>def</span> <span class='id identifier rubyid_define_getter'>define_getter</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
624
- <span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_instance_variable_get'>instance_variable_get</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>@</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span>
625
- <span class='kw'>end</span></pre>
626
- </td>
627
- </tr>
628
- </table>
629
- </div>
630
-
631
- <div class="method_details ">
632
- <h3 class="signature " id="define_setter-instance_method">
633
-
634
- #<strong>define_setter</strong>(name) &#x21d2; <tt>void</tt> <span class="extras">(private)</span>
635
-
636
-
637
-
638
-
639
-
640
- </h3><div class="docstring">
641
- <div class="discussion">
642
- <p class="note returns_void">This method returns an undefined value.</p>
643
- <p>Defines a setter method for the property</p>
644
-
645
-
646
- </div>
647
- </div>
648
- <div class="tags">
649
-
650
- <div class="examples">
651
- <p class="tag_title">Examples:</p>
652
-
653
-
654
- <pre class="example code"><code><span class='id identifier rubyid_define_getter'>define_getter</span><span class='lparen'>(</span><span class='symbol'>:score</span><span class='rparen'>)</span> <span class='comment'>#=&gt; def score=(value) ...</span></code></pre>
655
-
656
-
657
- <p class="example_title"><div class='inline'>
658
- <p>Generated instance method</p>
659
- </div></p>
660
-
661
- <pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_score='>score=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
662
- <span class='id identifier rubyid_validate_score_type!'>validate_score_type!</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
663
- <span class='id identifier rubyid_validate_score!'>validate_score!</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
664
- <span class='id identifier rubyid_instance_variable_set'>instance_variable_set</span><span class='lparen'>(</span><span class='ivar'>@score</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
665
- <span class='kw'>end</span></code></pre>
666
-
667
- </div>
668
- <p class="tag_title">Parameters:</p>
669
- <ul class="param">
670
-
671
- <li>
672
-
673
- <span class='name'>name</span>
674
-
675
-
676
- <span class='type'>(<tt>Symbol</tt>)</span>
677
-
678
-
679
-
680
- &mdash;
681
- <div class='inline'>
682
- <p>the property name</p>
683
- </div>
684
-
685
- </li>
686
-
687
- </ul>
688
-
689
-
690
- </div><table class="source_code">
691
- <tr>
692
- <td>
693
- <pre class="lines">
694
-
695
-
696
- 150
697
- 151
698
- 152
699
- 153
700
- 154
701
- 155
702
- 156</pre>
703
- </td>
704
- <td>
705
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 150</span>
706
-
707
- <span class='kw'>def</span> <span class='id identifier rubyid_define_setter'>define_setter</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
708
- <span class='id identifier rubyid_define_method'>define_method</span> <span class='symbol'>:&quot;#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>=</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
709
- <span class='id identifier rubyid___send__'>__send__</span><span class='lparen'>(</span><span class='symbol'>:&quot;validate_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>_type!</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
710
- <span class='id identifier rubyid___send__'>__send__</span><span class='lparen'>(</span><span class='symbol'>:&quot;validate_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>_lambda!</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
711
- <span class='id identifier rubyid_instance_variable_set'>instance_variable_set</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>@</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
712
- <span class='kw'>end</span>
713
- <span class='kw'>end</span></pre>
714
- </td>
715
- </tr>
716
- </table>
717
- </div>
718
-
719
- <div class="method_details ">
720
- <h3 class="signature " id="define_validate_lambda!-instance_method">
721
-
722
- #<strong>define_validate_lambda!</strong>(name, validate, allow_nil) &#x21d2; <tt>void</tt> <span class="extras">(private)</span>
723
-
724
-
725
-
726
-
727
-
728
- </h3><div class="docstring">
729
- <div class="discussion">
730
- <p class="note returns_void">This method returns an undefined value.</p>
731
- <p>Defines a private method that raises an error if validate block returns false</p>
732
-
733
-
734
- </div>
735
- </div>
736
- <div class="tags">
737
-
738
- <div class="examples">
739
- <p class="tag_title">Examples:</p>
740
-
741
-
742
- <pre class="example code"><code><span class='id identifier rubyid_define_validate_lambda!'>define_validate_lambda!</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>score</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_v'>v</span> <span class='op'>&gt;=</span> <span class='int'>0</span> <span class='rbrace'>}</span><span class='comma'>,</span> <span class='kw'>false</span><span class='rparen'>)</span> <span class='comment'>#=&gt; def validate_score_lambda!(value) ...</span></code></pre>
743
-
744
-
745
- <p class="example_title"><div class='inline'>
746
- <p>Generated instance method</p>
747
- </div></p>
748
-
749
- <pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_validate_score_lambda!'>validate_score_lambda!</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
750
- <span class='kw'>return</span> <span class='kw'>if</span> <span class='kw'>false</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
751
- <span class='kw'>return</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span> <span class='op'>&gt;=</span> <span class='int'>0</span>
752
-
753
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>:score does not match validation</span><span class='tstring_end'>&quot;</span></span>
754
- <span class='kw'>end</span></code></pre>
755
-
756
- </div>
757
- <p class="tag_title">Parameters:</p>
758
- <ul class="param">
759
-
760
- <li>
761
-
762
- <span class='name'>name</span>
763
-
764
-
765
- <span class='type'>(<tt>Symbol</tt>)</span>
766
-
767
-
768
-
769
- &mdash;
770
- <div class='inline'>
771
- <p>the property name</p>
772
- </div>
773
-
774
- </li>
775
-
776
- <li>
777
-
778
- <span class='name'>validate</span>
779
-
780
-
781
- <span class='type'>(<tt>Proc</tt>)</span>
782
-
783
-
784
-
785
- &mdash;
786
- <div class='inline'>
787
- <p>a lambda processing the value and returning true or false</p>
788
- </div>
789
-
790
- </li>
791
-
792
- <li>
793
-
794
- <span class='name'>allow_nil</span>
795
-
796
-
797
- <span class='type'>(<tt>true</tt>, <tt>false</tt>)</span>
798
-
799
-
800
-
801
- &mdash;
802
- <div class='inline'>
803
- <p>allow nil as a value</p>
804
- </div>
805
-
806
- </li>
807
-
808
- </ul>
809
-
810
-
811
- </div><table class="source_code">
812
- <tr>
813
- <td>
814
- <pre class="lines">
815
-
816
-
817
- 116
818
- 117
819
- 118
820
- 119
821
- 120
822
- 121
823
- 122
824
- 123
825
- 124</pre>
826
- </td>
827
- <td>
828
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 116</span>
829
-
830
- <span class='kw'>def</span> <span class='id identifier rubyid_define_validate_lambda!'>define_validate_lambda!</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_validate'>validate</span><span class='comma'>,</span> <span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='rparen'>)</span>
831
- <span class='id identifier rubyid_define_method'>define_method</span> <span class='symbol'>:&quot;validate_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>_lambda!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
832
- <span class='kw'>return</span> <span class='kw'>if</span> <span class='id identifier rubyid_allow_nil'>allow_nil</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
833
- <span class='kw'>return</span> <span class='kw'>if</span> <span class='id identifier rubyid_instance_exec'>instance_exec</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_validate'>validate</span><span class='rparen'>)</span>
834
-
835
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'> does not match validation</span><span class='tstring_end'>&quot;</span></span>
836
- <span class='kw'>end</span>
837
- <span class='id identifier rubyid_private'>private</span> <span class='symbol'>:&quot;validate_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>_lambda!</span><span class='tstring_end'>&quot;</span></span>
838
- <span class='kw'>end</span></pre>
839
- </td>
840
- </tr>
841
- </table>
842
- </div>
843
-
844
- <div class="method_details ">
845
- <h3 class="signature " id="define_validate_type!-instance_method">
846
-
847
- #<strong>define_validate_type!</strong>(name, type, allow_nil) &#x21d2; <tt>void</tt> <span class="extras">(private)</span>
848
-
849
-
850
-
851
-
852
-
853
- </h3><div class="docstring">
854
- <div class="discussion">
855
- <p class="note returns_void">This method returns an undefined value.</p>
856
- <p>Defines a private method that raises an error if type is not respected</p>
857
-
858
-
859
- </div>
860
- </div>
861
- <div class="tags">
862
-
863
- <div class="examples">
864
- <p class="tag_title">Examples:</p>
865
-
866
-
867
- <pre class="example code"><code>define_validate_type!(score, Integer, false) =&gt; def validate_score_type!(value) ...</code></pre>
868
-
869
-
870
- <p class="example_title"><div class='inline'>
871
- <p>Generated method</p>
872
- </div></p>
873
-
874
- <pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_validate_score_type!'>validate_score_type!</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
875
- <span class='kw'>return</span> <span class='kw'>if</span> <span class='const'>Integer</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>||</span> <span class='kw'>false</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
876
- <span class='kw'>return</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Integer</span>
877
-
878
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>:score does not match required type</span><span class='tstring_end'>&quot;</span></span>
879
- <span class='kw'>end</span></code></pre>
880
-
881
- </div>
882
- <p class="tag_title">Parameters:</p>
883
- <ul class="param">
884
-
885
- <li>
886
-
887
- <span class='name'>name</span>
888
-
889
-
890
- <span class='type'>(<tt>Symbol</tt>)</span>
891
-
892
-
893
-
894
- &mdash;
895
- <div class='inline'>
896
- <p>the property name</p>
897
- </div>
898
-
899
- </li>
900
-
901
- <li>
902
-
903
- <span class='name'>type</span>
904
-
905
-
906
- <span class='type'>(<tt>Class</tt>)</span>
907
-
908
-
909
-
910
- &mdash;
911
- <div class='inline'>
912
- <p>the type to test against</p>
913
- </div>
914
-
915
- </li>
916
-
917
- <li>
918
-
919
- <span class='name'>allow_nil</span>
920
-
921
-
922
- <span class='type'>(<tt>true</tt>, <tt>false</tt>)</span>
923
-
924
-
925
-
926
- &mdash;
927
- <div class='inline'>
928
- <p>allow nil as a value</p>
929
- </div>
930
-
931
- </li>
932
-
933
- </ul>
934
-
935
-
936
- </div><table class="source_code">
937
- <tr>
938
- <td>
939
- <pre class="lines">
940
-
941
-
942
- 76
943
- 77
944
- 78
945
- 79
946
- 80
947
- 81
948
- 82
949
- 83
950
- 84
951
- 85</pre>
952
- </td>
953
- <td>
954
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 76</span>
955
-
956
- <span class='kw'>def</span> <span class='id identifier rubyid_define_validate_type!'>define_validate_type!</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='comma'>,</span> <span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='rparen'>)</span>
957
- <span class='id identifier rubyid_lambda'>lambda</span> <span class='op'>=</span> <span class='id identifier rubyid_type_validation'>type_validation</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='rparen'>)</span>
958
- <span class='id identifier rubyid_define_method'>define_method</span> <span class='symbol'>:&quot;validate_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>_type!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
959
- <span class='kw'>return</span> <span class='kw'>if</span> <span class='id identifier rubyid_type'>type</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>||</span> <span class='id identifier rubyid_allow_nil'>allow_nil</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
960
- <span class='kw'>return</span> <span class='kw'>if</span> <span class='id identifier rubyid_lambda'>lambda</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
961
-
962
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'> does not match required type</span><span class='tstring_end'>&quot;</span></span>
963
- <span class='kw'>end</span>
964
- <span class='id identifier rubyid_private'>private</span> <span class='symbol'>:&quot;validate_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>_type!</span><span class='tstring_end'>&quot;</span></span>
965
- <span class='kw'>end</span></pre>
966
- </td>
967
- </tr>
968
- </table>
969
- </div>
970
-
971
- <div class="method_details ">
972
- <h3 class="signature " id="initialize_body-instance_method">
973
-
974
- #<strong>initialize_body</strong> &#x21d2; <tt>String</tt> <span class="extras">(private)</span>
975
-
976
-
977
-
978
-
979
-
980
- </h3><div class="docstring">
981
- <div class="discussion">
982
-
983
- <p>Defines initialize method body</p>
984
-
985
-
986
- </div>
987
- </div>
988
- <div class="tags">
989
-
990
- <div class="examples">
991
- <p class="tag_title">Examples:</p>
992
-
993
-
994
- <p class="example_title"><div class='inline'>
995
- <p>Given properties { foo: { allow_nil: false, default: nil }, { allow_nil: true, default: 0 } }</p>
996
- </div></p>
997
-
998
- <pre class="example code"><code><span class='id identifier rubyid_initialize_body'>initialize_body</span> <span class='comment'>#=&gt; &quot;self.foo = foo\nself.bar = bar&quot;</span></code></pre>
999
-
1000
- </div>
1001
-
1002
- <p class="tag_title">Returns:</p>
1003
- <ul class="return">
1004
-
1005
- <li>
1006
-
1007
-
1008
- <span class='type'>(<tt>String</tt>)</span>
1009
-
1010
-
1011
-
1012
- </li>
1013
-
1014
- </ul>
1015
-
1016
- </div><table class="source_code">
1017
- <tr>
1018
- <td>
1019
- <pre class="lines">
1020
-
1021
-
1022
- 206
1023
- 207
1024
- 208</pre>
1025
- </td>
1026
- <td>
1027
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 206</span>
1028
-
1029
- <span class='kw'>def</span> <span class='id identifier rubyid_initialize_body'>initialize_body</span>
1030
- <span class='id identifier rubyid_properties'>properties</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</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='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>self.</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='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</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'>&quot;</span><span class='tstring_content'>\n</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
1031
- <span class='kw'>end</span></pre>
1032
- </td>
1033
- </tr>
1034
- </table>
1035
- </div>
1036
-
1037
- <div class="method_details ">
1038
- <h3 class="signature " id="initialize_parameters-instance_method">
1039
-
1040
- #<strong>initialize_parameters</strong> &#x21d2; <tt>String</tt> <span class="extras">(private)</span>
1041
-
1042
-
1043
-
1044
-
1045
-
1046
- </h3><div class="docstring">
1047
- <div class="discussion">
1048
-
1049
- <p>Defines initialize method parameters</p>
1050
-
1051
-
1052
- </div>
1053
- </div>
1054
- <div class="tags">
1055
-
1056
- <div class="examples">
1057
- <p class="tag_title">Examples:</p>
1058
-
1059
-
1060
- <p class="example_title"><div class='inline'>
1061
- <p>Given properties { foo: { allow_nil: false, default: nil }, { allow_nil: true, default: 0 } }</p>
1062
- </div></p>
1063
-
1064
- <pre class="example code"><code><span class='id identifier rubyid_redefine_initialize'>redefine_initialize</span> <span class='comment'>#=&gt; &quot;foo:, bar: 0&quot;</span></code></pre>
1065
-
1066
- </div>
1067
-
1068
- <p class="tag_title">Returns:</p>
1069
- <ul class="return">
1070
-
1071
- <li>
1072
-
1073
-
1074
- <span class='type'>(<tt>String</tt>)</span>
1075
-
1076
-
1077
-
1078
- </li>
1079
-
1080
- </ul>
1081
-
1082
- </div><table class="source_code">
1083
- <tr>
1084
- <td>
1085
- <pre class="lines">
1086
-
1087
-
1088
- 178
1089
- 179
1090
- 180
1091
- 181
1092
- 182
1093
- 183
1094
- 184
1095
- 185</pre>
1096
- </td>
1097
- <td>
1098
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 178</span>
1099
-
1100
- <span class='kw'>def</span> <span class='id identifier rubyid_initialize_parameters'>initialize_parameters</span>
1101
- <span class='id identifier rubyid_parameters'>parameters</span> <span class='op'>=</span>
1102
- <span class='id identifier rubyid_properties'>properties</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='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>|</span>
1103
- <span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='comma'>,</span> <span class='id identifier rubyid_default'>default</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span>
1104
- <span class='tstring'><span class='tstring_beg'>&quot;</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='embexpr_beg'>#{</span><span class='id identifier rubyid_default_parameter_for'>default_parameter_for</span><span class='lparen'>(</span><span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='comma'>,</span> <span class='id identifier rubyid_default'>default</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
1105
- <span class='kw'>end</span>
1106
- <span class='id identifier rubyid_parameters'>parameters</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>, </span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
1107
- <span class='kw'>end</span></pre>
1108
- </td>
1109
- </tr>
1110
- </table>
1111
- </div>
1112
-
1113
- <div class="method_details ">
1114
- <h3 class="signature " id="properties-instance_method">
1115
-
1116
- #<strong>properties</strong> &#x21d2; <tt>Hash</tt>
1117
-
1118
-
1119
-
1120
-
1121
-
1122
- </h3><div class="docstring">
1123
- <div class="discussion">
1124
-
1125
- <div class="note notetag">
1126
- <strong>Note:</strong>
1127
- <div class='inline'>
1128
- <p>this method will be updated by <span class='object_link'><a href="#add_to_properties-instance_method" title="Otoroshi::Sanctuary::ClassMethods#add_to_properties (method)">#add_to_properties</a></span></p>
1129
- </div>
1130
- </div>
1131
-
1132
-
1133
- <p>Returns the class properties</p>
1134
-
1135
-
1136
- </div>
1137
- </div>
1138
- <div class="tags">
1139
-
1140
- <p class="tag_title">Returns:</p>
1141
- <ul class="return">
1142
-
1143
- <li>
1144
-
1145
-
1146
- <span class='type'>(<tt>Hash</tt>)</span>
1147
-
1148
-
1149
-
1150
- </li>
1151
-
1152
- </ul>
1153
-
1154
- </div><table class="source_code">
1155
- <tr>
1156
- <td>
1157
- <pre class="lines">
1158
-
1159
-
1160
- 48
1161
- 49
1162
- 50</pre>
1163
- </td>
1164
- <td>
1165
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 48</span>
1166
-
1167
- <span class='kw'>def</span> <span class='id identifier rubyid_properties'>properties</span>
1168
- <span class='lbrace'>{</span><span class='rbrace'>}</span>
1169
- <span class='kw'>end</span></pre>
1170
- </td>
1171
- </tr>
1172
- </table>
1173
- </div>
1174
-
1175
- <div class="method_details ">
1176
- <h3 class="signature " id="property-instance_method">
1177
-
1178
- #<strong>property</strong>(name, type = Object, validate: -&gt;(_) { true }, allow_nil: false, default: nil) &#x21d2; <tt>void</tt>
1179
-
1180
-
1181
-
1182
-
1183
-
1184
- </h3><div class="docstring">
1185
- <div class="discussion">
1186
- <p class="note returns_void">This method returns an undefined value.</p>
1187
- <p>Adds a new “property” to the class</p>
1188
-
1189
-
1190
- </div>
1191
- </div>
1192
- <div class="tags">
1193
-
1194
- <div class="examples">
1195
- <p class="tag_title">Examples:</p>
1196
-
1197
-
1198
- <pre class="example code"><code><span class='id identifier rubyid_property'>property</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='const'>String</span><span class='comma'>,</span> <span class='label'>validate:</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>&gt;</span> <span class='int'>3</span> <span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>allow_nil:</span> <span class='kw'>true</span></code></pre>
1199
-
1200
-
1201
- <pre class="example code"><code><span class='id identifier rubyid_property'>property</span> <span class='id identifier rubyid_score'>score</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='const'>Integer</span><span class='comma'>,</span> <span class='label'>validate:</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_v'>v</span> <span class='op'>&gt;=</span> <span class='int'>0</span> <span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>default:</span> <span class='int'>0</span></code></pre>
1202
-
1203
- </div>
1204
- <p class="tag_title">Parameters:</p>
1205
- <ul class="param">
1206
-
1207
- <li>
1208
-
1209
- <span class='name'>name</span>
1210
-
1211
-
1212
- <span class='type'>(<tt>Symbol</tt>)</span>
1213
-
1214
-
1215
-
1216
- &mdash;
1217
- <div class='inline'>
1218
- <p>the property name</p>
1219
- </div>
1220
-
1221
- </li>
1222
-
1223
- <li>
1224
-
1225
- <span class='name'>type</span>
1226
-
1227
-
1228
- <span class='type'>(<tt>Class</tt>)</span>
1229
-
1230
-
1231
- <em class="default">(defaults to: <tt>Object</tt>)</em>
1232
-
1233
-
1234
- &mdash;
1235
- <div class='inline'>
1236
- <p>the expected value type</p>
1237
- </div>
1238
-
1239
- </li>
1240
-
1241
- <li>
1242
-
1243
- <span class='name'>validate</span>
1244
-
1245
-
1246
- <span class='type'>(<tt>Proc</tt>)</span>
1247
-
1248
-
1249
- <em class="default">(defaults to: <tt>-&gt;(_) { true }</tt>)</em>
1250
-
1251
-
1252
- &mdash;
1253
- <div class='inline'>
1254
- <p>a lambda processing the value and returning true or false</p>
1255
- </div>
1256
-
1257
- </li>
1258
-
1259
- <li>
1260
-
1261
- <span class='name'>allow_nil</span>
1262
-
1263
-
1264
- <span class='type'>(<tt>true</tt>, <tt>false</tt>)</span>
1265
-
1266
-
1267
- <em class="default">(defaults to: <tt>false</tt>)</em>
1268
-
1269
-
1270
- &mdash;
1271
- <div class='inline'>
1272
- <p>allow nil as a value</p>
1273
- </div>
1274
-
1275
- </li>
1276
-
1277
- <li>
1278
-
1279
- <span class='name'>default</span>
1280
-
1281
-
1282
- <span class='type'>(<tt>Object</tt>)</span>
1283
-
1284
-
1285
- <em class="default">(defaults to: <tt>nil</tt>)</em>
1286
-
1287
-
1288
- &mdash;
1289
- <div class='inline'>
1290
- <p>default value if not set on initialization</p>
1291
- </div>
1292
-
1293
- </li>
1294
-
1295
- </ul>
1296
-
1297
-
1298
- </div><table class="source_code">
1299
- <tr>
1300
- <td>
1301
- <pre class="lines">
1302
-
1303
-
1304
- 36
1305
- 37
1306
- 38
1307
- 39
1308
- 40
1309
- 41
1310
- 42
1311
- 43</pre>
1312
- </td>
1313
- <td>
1314
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 36</span>
1315
-
1316
- <span class='kw'>def</span> <span class='id identifier rubyid_property'>property</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='op'>=</span> <span class='const'>Object</span><span class='comma'>,</span> <span class='label'>validate:</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid__'>_</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='kw'>true</span> <span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>allow_nil:</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='label'>default:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
1317
- <span class='id identifier rubyid_add_to_properties'>add_to_properties</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='comma'>,</span> <span class='id identifier rubyid_default'>default</span><span class='rparen'>)</span>
1318
- <span class='id identifier rubyid_define_validate_type!'>define_validate_type!</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='comma'>,</span> <span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='rparen'>)</span>
1319
- <span class='id identifier rubyid_define_validate_lambda!'>define_validate_lambda!</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_validate'>validate</span><span class='comma'>,</span> <span class='id identifier rubyid_allow_nil'>allow_nil</span><span class='rparen'>)</span>
1320
- <span class='id identifier rubyid_define_getter'>define_getter</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
1321
- <span class='id identifier rubyid_define_setter'>define_setter</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
1322
- <span class='id identifier rubyid_redefine_initialize'>redefine_initialize</span>
1323
- <span class='kw'>end</span></pre>
1324
- </td>
1325
- </tr>
1326
- </table>
1327
- </div>
1328
-
1329
- <div class="method_details ">
1330
- <h3 class="signature " id="redefine_initialize-instance_method">
1331
-
1332
- #<strong>redefine_initialize</strong> &#x21d2; <tt>void</tt> <span class="extras">(private)</span>
1333
-
1334
-
1335
-
1336
-
1337
-
1338
- </h3><div class="docstring">
1339
- <div class="discussion">
1340
-
1341
- <div class="note notetag">
1342
- <strong>Note:</strong>
1343
- <div class='inline'>
1344
- <p>method is defined with `class_eval`</p>
1345
- </div>
1346
- </div>
1347
-
1348
- <p class="note returns_void">This method returns an undefined value.</p>
1349
- <p>Redefines initialize method</p>
1350
-
1351
-
1352
- </div>
1353
- </div>
1354
- <div class="tags">
1355
-
1356
- <div class="examples">
1357
- <p class="tag_title">Examples:</p>
1358
-
1359
-
1360
- <p class="example_title"><div class='inline'>
1361
- <p>Generated method</p>
1362
- </div></p>
1363
-
1364
- <pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>foo:</span><span class='comma'>,</span> <span class='label'>bar:</span> <span class='int'>0</span><span class='rparen'>)</span>
1365
- <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_foo'>foo</span> <span class='op'>=</span> <span class='id identifier rubyid_foo'>foo</span>
1366
- <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_bar'>bar</span> <span class='op'>=</span> <span class='id identifier rubyid_bar'>bar</span>
1367
- <span class='kw'>end</span></code></pre>
1368
-
1369
- </div>
1370
-
1371
-
1372
- </div><table class="source_code">
1373
- <tr>
1374
- <td>
1375
- <pre class="lines">
1376
-
1377
-
1378
- 166
1379
- 167
1380
- 168
1381
- 169
1382
- 170
1383
- 171
1384
- 172</pre>
1385
- </td>
1386
- <td>
1387
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 166</span>
1388
-
1389
- <span class='kw'>def</span> <span class='id identifier rubyid_redefine_initialize'>redefine_initialize</span>
1390
- <span class='id identifier rubyid_class_eval'>class_eval</span> <span class='heredoc_beg'>&lt;&lt;-RUBY</span><span class='comma'>,</span> <span class='kw'>__FILE__</span><span class='comma'>,</span> <span class='kw'>__LINE__</span> <span class='op'>+</span> <span class='int'>1</span>
1391
- <span class='tstring_content'> def initialize(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_initialize_parameters'>initialize_parameters</span><span class='embexpr_end'>}</span><span class='tstring_content'>)
1392
- </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_initialize_body'>initialize_body</span><span class='embexpr_end'>}</span><span class='tstring_content'>
1393
- end
1394
- </span><span class='heredoc_end'> RUBY
1395
- </span><span class='kw'>end</span></pre>
1396
- </td>
1397
- </tr>
1398
- </table>
1399
- </div>
1400
-
1401
- <div class="method_details ">
1402
- <h3 class="signature " id="type_validation-instance_method">
1403
-
1404
- #<strong>type_validation</strong>(type) &#x21d2; <tt>Proc</tt> <span class="extras">(private)</span>
1405
-
1406
-
1407
-
1408
-
1409
-
1410
- </h3><div class="docstring">
1411
- <div class="discussion">
1412
-
1413
- <p>Defines a lambda to be call to validate that value matches the type</p>
1414
-
1415
-
1416
- </div>
1417
- </div>
1418
- <div class="tags">
1419
-
1420
- <div class="examples">
1421
- <p class="tag_title">Examples:</p>
1422
-
1423
-
1424
- <pre class="example code"><code><span class='id identifier rubyid_type_validation'>type_validation</span><span class='lparen'>(</span><span class='const'>Integer</span><span class='rparen'>)</span> <span class='comment'>#=&gt; -&gt;(v) { v.is_a? Integer }</span></code></pre>
1425
-
1426
-
1427
- <pre class="example code"><code><span class='id identifier rubyid_type_validation'>type_validation</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='const'>String</span><span class='comma'>,</span> <span class='const'>Symbol</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='comment'>#=&gt; -&gt;(v) { [String, Symbol].any? { |t| v.is_a? t } }</span></code></pre>
1428
-
1429
- </div>
1430
- <p class="tag_title">Parameters:</p>
1431
- <ul class="param">
1432
-
1433
- <li>
1434
-
1435
- <span class='name'>type</span>
1436
-
1437
-
1438
- <span class='type'>(<tt>Class</tt>)</span>
1439
-
1440
-
1441
-
1442
- &mdash;
1443
- <div class='inline'>
1444
- <p>the type to test against</p>
1445
- </div>
1446
-
1447
- </li>
1448
-
1449
- </ul>
1450
-
1451
- <p class="tag_title">Returns:</p>
1452
- <ul class="return">
1453
-
1454
- <li>
1455
-
1456
-
1457
- <span class='type'>(<tt>Proc</tt>)</span>
1458
-
1459
-
1460
-
1461
- &mdash;
1462
- <div class='inline'>
1463
- <p>the lambda to use in order to test the value matches the type</p>
1464
- </div>
1465
-
1466
- </li>
1467
-
1468
- </ul>
1469
-
1470
- </div><table class="source_code">
1471
- <tr>
1472
- <td>
1473
- <pre class="lines">
1474
-
1475
-
1476
- 94
1477
- 95
1478
- 96
1479
- 97
1480
- 98
1481
- 99
1482
- 100</pre>
1483
- </td>
1484
- <td>
1485
- <pre class="code"><span class="info file"># File 'lib/otoroshi/sanctuary.rb', line 94</span>
1486
-
1487
- <span class='kw'>def</span> <span class='id identifier rubyid_type_validation'>type_validation</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='rparen'>)</span>
1488
- <span class='kw'>if</span> <span class='id identifier rubyid_type'>type</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Array</span>
1489
- <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_type'>type</span><span class='period'>.</span><span class='id identifier rubyid_any?'>any?</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_t'>t</span><span class='op'>|</span> <span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='id identifier rubyid_t'>t</span> <span class='rbrace'>}</span> <span class='rbrace'>}</span>
1490
- <span class='kw'>else</span>
1491
- <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='id identifier rubyid_type'>type</span> <span class='rbrace'>}</span>
1492
- <span class='kw'>end</span>
1493
- <span class='kw'>end</span></pre>
1494
- </td>
1495
- </tr>
1496
- </table>
1497
- </div>
1498
-
1499
- </div>
1500
-
1501
- </div>
1502
-
1503
- <div id="footer">
1504
- Generated on Wed Oct 14 00:24:01 2020 by
1505
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1506
- 0.9.25 (ruby-2.6.6).
1507
- </div>
1508
-
1509
- </div>
1510
- </body>
1511
- </html>