env_parser 1.3.1 → 1.3.2
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 +4 -4
- data/.circleci/config.yml +1 -1
- data/.rubocop.yml +22 -35
- data/.ruby-version +1 -1
- data/Gemfile.lock +44 -42
- data/README.md +1 -1
- data/docs/EnvParser/AutoregisterFileNotFound.html +6 -6
- data/docs/EnvParser/Error.html +5 -6
- data/docs/EnvParser/TypeAlreadyDefinedError.html +5 -6
- data/docs/EnvParser/Types/BaseTypes.html +9 -7
- data/docs/EnvParser/Types/ChronologyTypes.html +7 -6
- data/docs/EnvParser/Types/InternetTypes.html +7 -6
- data/docs/EnvParser/Types.html +6 -6
- data/docs/EnvParser/UnknownTypeError.html +5 -6
- data/docs/EnvParser/UnparseableAutoregisterSpec.html +6 -6
- data/docs/EnvParser/ValueNotAllowedError.html +7 -6
- data/docs/EnvParser/ValueNotConvertibleError.html +5 -6
- data/docs/EnvParser.html +117 -121
- data/docs/_index.html +5 -7
- data/docs/file.README.html +241 -143
- data/docs/frames.html +1 -1
- data/docs/index.html +241 -143
- data/docs/method_list.html +1 -9
- data/docs/top-level-namespace.html +4 -82
- data/env_parser.gemspec +14 -14
- data/lib/env_parser/errors.rb +18 -18
- data/lib/env_parser/types/base_types.rb +69 -69
- data/lib/env_parser/types/chronology_types.rb +54 -54
- data/lib/env_parser/types/internet_types.rb +50 -50
- data/lib/env_parser/types.rb +2 -2
- data/lib/env_parser/version.rb +1 -1
- data/lib/env_parser.rb +205 -213
- data/spec/env_parser/types/base_types_spec.rb +98 -0
- data/spec/env_parser/types/chronology_types_spec.rb +49 -0
- data/spec/env_parser/types/internet_types_spec.rb +45 -0
- data/spec/env_parser_spec.rb +192 -0
- data/spec/spec_helper.rb +14 -0
- metadata +53 -48
- data/.travis.yml +0 -5
data/docs/EnvParser.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Class: EnvParser
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.28
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -103,8 +103,7 @@
|
|
103
103
|
|
104
104
|
<h2>Overview</h2><div class="docstring">
|
105
105
|
<div class="discussion">
|
106
|
-
|
107
|
-
<p>The EnvParser class simplifies parsing of environment variables as different data types.</p>
|
106
|
+
<p>The EnvParser class simplifies parsing of environment variables as different data types.</p>
|
108
107
|
|
109
108
|
|
110
109
|
</div>
|
@@ -136,8 +135,7 @@
|
|
136
135
|
<dt id="AUTOREGISTER_FILE-constant" class="">AUTOREGISTER_FILE =
|
137
136
|
<div class="docstring">
|
138
137
|
<div class="discussion">
|
139
|
-
|
140
|
-
<p>The default filename to use for <span class='object_link'><a href="#autoregister-class_method" title="EnvParser.autoregister (method)">autoregister</a></span> requests.</p>
|
138
|
+
<p>The default filename to use for <span class='object_link'><a href="#autoregister-class_method" title="EnvParser.autoregister (method)">autoregister</a></span> requests.</p>
|
141
139
|
|
142
140
|
|
143
141
|
</div>
|
@@ -152,7 +150,7 @@
|
|
152
150
|
<dt id="VERSION-constant" class="">VERSION =
|
153
151
|
|
154
152
|
</dt>
|
155
|
-
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1.3.
|
153
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1.3.2</span><span class='tstring_end'>'</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
|
156
154
|
|
157
155
|
</dl>
|
158
156
|
|
@@ -188,8 +186,7 @@
|
|
188
186
|
|
189
187
|
|
190
188
|
|
191
|
-
<span class="summary_desc"><div class='inline'>
|
192
|
-
<p>Creates ENV bindings for <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">EnvParser.parse</a></span> and <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">EnvParser.register</a></span> proxy methods.</p>
|
189
|
+
<span class="summary_desc"><div class='inline'><p>Creates ENV bindings for <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">EnvParser.parse</a></span> and <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">EnvParser.register</a></span> proxy methods.</p>
|
193
190
|
</div></span>
|
194
191
|
|
195
192
|
</li>
|
@@ -212,8 +209,7 @@
|
|
212
209
|
|
213
210
|
|
214
211
|
|
215
|
-
<span class="summary_desc"><div class='inline'>
|
216
|
-
<p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
212
|
+
<span class="summary_desc"><div class='inline'><p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
217
213
|
</div></span>
|
218
214
|
|
219
215
|
</li>
|
@@ -236,8 +232,7 @@
|
|
236
232
|
|
237
233
|
|
238
234
|
|
239
|
-
<span class="summary_desc"><div class='inline'>
|
240
|
-
<p>Defines a new type for use as the “as” option on a subsequent <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">EnvParser.parse</a></span> or <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">EnvParser.register</a></span> call.</p>
|
235
|
+
<span class="summary_desc"><div class='inline'><p>Defines a new type for use as the “as” option on a subsequent <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">EnvParser.parse</a></span> or <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">EnvParser.register</a></span> call.</p>
|
241
236
|
</div></span>
|
242
237
|
|
243
238
|
</li>
|
@@ -260,8 +255,7 @@
|
|
260
255
|
|
261
256
|
|
262
257
|
|
263
|
-
<span class="summary_desc"><div class='inline'>
|
264
|
-
<p>Interprets the given value as the specified type.</p>
|
258
|
+
<span class="summary_desc"><div class='inline'><p>Interprets the given value as the specified type.</p>
|
265
259
|
</div></span>
|
266
260
|
|
267
261
|
</li>
|
@@ -284,8 +278,7 @@
|
|
284
278
|
|
285
279
|
|
286
280
|
|
287
|
-
<span class="summary_desc"><div class='inline'>
|
288
|
-
<p>Parses the referenced value and creates a matching constant in the requested context.</p>
|
281
|
+
<span class="summary_desc"><div class='inline'><p>Parses the referenced value and creates a matching constant in the requested context.</p>
|
289
282
|
</div></span>
|
290
283
|
|
291
284
|
</li>
|
@@ -311,10 +304,11 @@
|
|
311
304
|
|
312
305
|
</h3><div class="docstring">
|
313
306
|
<div class="discussion">
|
314
|
-
|
315
|
-
<p>Creates ENV bindings for <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span> and <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> proxy methods.</p>
|
307
|
+
<p>Creates ENV bindings for <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span> and <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> proxy methods.</p>
|
316
308
|
|
317
|
-
<p>The sole difference between these proxy methods and their EnvParser counterparts is that
|
309
|
+
<p>The sole difference between these proxy methods and their EnvParser counterparts is that
|
310
|
+
ENV.parse will interpret any value given as an ENV key (as a String), not the given value
|
311
|
+
itself. i.e. ENV.parse(‘XYZ’, …) is equivalent to EnvParser.parse(ENV[‘XYZ’], …)</p>
|
318
312
|
|
319
313
|
|
320
314
|
</div>
|
@@ -332,8 +326,7 @@
|
|
332
326
|
|
333
327
|
|
334
328
|
—
|
335
|
-
<div class='inline'>
|
336
|
-
<p>This generates no usable value.</p>
|
329
|
+
<div class='inline'><p>This generates no usable value.</p>
|
337
330
|
</div>
|
338
331
|
|
339
332
|
</li>
|
@@ -346,6 +339,9 @@
|
|
346
339
|
<pre class="lines">
|
347
340
|
|
348
341
|
|
342
|
+
216
|
343
|
+
217
|
344
|
+
218
|
349
345
|
219
|
350
346
|
220
|
351
347
|
221
|
@@ -355,13 +351,10 @@
|
|
355
351
|
225
|
356
352
|
226
|
357
353
|
227
|
358
|
-
228
|
359
|
-
229
|
360
|
-
230
|
361
|
-
231</pre>
|
354
|
+
228</pre>
|
362
355
|
</td>
|
363
356
|
<td>
|
364
|
-
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line
|
357
|
+
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 216</span>
|
365
358
|
|
366
359
|
<span class='kw'>def</span> <span class='id identifier rubyid_add_env_bindings'>add_env_bindings</span>
|
367
360
|
<span class='const'>ENV</span><span class='period'>.</span><span class='id identifier rubyid_instance_eval'>instance_eval</span> <span class='kw'>do</span>
|
@@ -392,10 +385,11 @@
|
|
392
385
|
|
393
386
|
</h3><div class="docstring">
|
394
387
|
<div class="discussion">
|
395
|
-
|
396
|
-
<p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
388
|
+
<p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
397
389
|
|
398
|
-
<p>The “autoregister” file is read, parsed as YAML, sanitized for use as a parameter to
|
390
|
+
<p>The “autoregister” file is read, parsed as YAML, sanitized for use as a parameter to
|
391
|
+
<span class='object_link'>register_all</span>, and then passed along for processing. The return value from that
|
392
|
+
<span class='object_link'>register_all</span> call is passed through.</p>
|
399
393
|
|
400
394
|
|
401
395
|
</div>
|
@@ -416,8 +410,8 @@
|
|
416
410
|
|
417
411
|
|
418
412
|
—
|
419
|
-
<div class='inline'>
|
420
|
-
<
|
413
|
+
<div class='inline'><p>A path for the autoregister file to parse and process. Defaults to
|
414
|
+
<span class='object_link'><a href="#AUTOREGISTER_FILE-constant" title="EnvParser::AUTOREGISTER_FILE (constant)">AUTOREGISTER_FILE</a></span> if unset.</p>
|
421
415
|
</div>
|
422
416
|
|
423
417
|
</li>
|
@@ -435,8 +429,7 @@
|
|
435
429
|
|
436
430
|
|
437
431
|
—
|
438
|
-
<div class='inline'>
|
439
|
-
<p>The return value from the <span class='object_link'>register_all</span> call that handles the actual registration.</p>
|
432
|
+
<div class='inline'><p>The return value from the <span class='object_link'>register_all</span> call that handles the actual registration.</p>
|
440
433
|
</div>
|
441
434
|
|
442
435
|
</li>
|
@@ -462,6 +455,9 @@
|
|
462
455
|
<pre class="lines">
|
463
456
|
|
464
457
|
|
458
|
+
245
|
459
|
+
246
|
460
|
+
247
|
465
461
|
248
|
466
462
|
249
|
467
463
|
250
|
@@ -483,17 +479,14 @@
|
|
483
479
|
266
|
484
480
|
267
|
485
481
|
268
|
486
|
-
269
|
487
|
-
270
|
488
|
-
271
|
489
|
-
272</pre>
|
482
|
+
269</pre>
|
490
483
|
</td>
|
491
484
|
<td>
|
492
|
-
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line
|
485
|
+
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 245</span>
|
493
486
|
|
494
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_autoregister'>autoregister</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'
|
495
|
-
<span class='id identifier rubyid_filename'
|
496
|
-
<span class='id identifier rubyid_autoregister_spec'>autoregister_spec</span> <span class='op'>=</span> <span class='const'>Psych</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'
|
487
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_autoregister'>autoregister</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
488
|
+
<span class='id identifier rubyid_filename'>filename</span> <span class='op'>||=</span> <span class='const'><span class='object_link'><a href="#AUTOREGISTER_FILE-constant" title="EnvParser::AUTOREGISTER_FILE (constant)">AUTOREGISTER_FILE</a></span></span>
|
489
|
+
<span class='id identifier rubyid_autoregister_spec'>autoregister_spec</span> <span class='op'>=</span> <span class='const'>Psych</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
|
497
490
|
|
498
491
|
<span class='id identifier rubyid_autoregister_spec'>autoregister_spec</span><span class='period'>.</span><span class='id identifier rubyid_deep_symbolize_keys!'>deep_symbolize_keys!</span>
|
499
492
|
<span class='id identifier rubyid_autoregister_spec'>autoregister_spec</span><span class='period'>.</span><span class='id identifier rubyid_transform_values!'>transform_values!</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_spec'>spec</span><span class='op'>|</span>
|
@@ -506,13 +499,13 @@
|
|
506
499
|
|
507
500
|
<span class='id identifier rubyid_register_all'>register_all</span> <span class='id identifier rubyid_autoregister_spec'>autoregister_spec</span>
|
508
501
|
|
509
|
-
<span class='comment'
|
510
|
-
</span><span class='comment'
|
502
|
+
<span class='comment'># Psych raises an Errno::ENOENT on file-not-found.
|
503
|
+
</span><span class='comment'>#
|
511
504
|
</span><span class='kw'>rescue</span> <span class='const'>Errno</span><span class='op'>::</span><span class='const'>ENOENT</span>
|
512
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="" title="EnvParser (class)">EnvParser</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="EnvParser/AutoregisterFileNotFound.html" title="EnvParser::AutoregisterFileNotFound (class)">AutoregisterFileNotFound</a></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>%(</span><span class='tstring_content'>file not found: "</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_filename'
|
505
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="" title="EnvParser (class)">EnvParser</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="EnvParser/AutoregisterFileNotFound.html" title="EnvParser::AutoregisterFileNotFound (class)">AutoregisterFileNotFound</a></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>%(</span><span class='tstring_content'>file not found: "</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_filename'>filename</span><span class='embexpr_end'>}</span><span class='tstring_content'>"</span><span class='tstring_end'>)</span></span>
|
513
506
|
|
514
|
-
<span class='comment'
|
515
|
-
</span><span class='comment'
|
507
|
+
<span class='comment'># Psych raises a Psych::SyntaxError on unparseable YAML.
|
508
|
+
</span><span class='comment'>#
|
516
509
|
</span><span class='kw'>rescue</span> <span class='const'>Psych</span><span class='op'>::</span><span class='const'>SyntaxError</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
517
510
|
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="" title="EnvParser (class)">EnvParser</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="EnvParser/UnparseableAutoregisterSpec.html" title="EnvParser::UnparseableAutoregisterSpec (class)">UnparseableAutoregisterSpec</a></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>malformed YAML in spec file: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
518
511
|
<span class='kw'>end</span></pre>
|
@@ -532,8 +525,7 @@
|
|
532
525
|
|
533
526
|
</h3><div class="docstring">
|
534
527
|
<div class="discussion">
|
535
|
-
|
536
|
-
<p>Defines a new type for use as the “as” option on a subsequent <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span> or <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> call.</p>
|
528
|
+
<p>Defines a new type for use as the “as” option on a subsequent <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span> or <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> call.</p>
|
537
529
|
|
538
530
|
|
539
531
|
</div>
|
@@ -552,8 +544,7 @@
|
|
552
544
|
|
553
545
|
|
554
546
|
—
|
555
|
-
<div class='inline'>
|
556
|
-
<p>The name to assign to the type.</p>
|
547
|
+
<div class='inline'><p>The name to assign to the type.</p>
|
557
548
|
</div>
|
558
549
|
|
559
550
|
</li>
|
@@ -570,8 +561,7 @@
|
|
570
561
|
|
571
562
|
|
572
563
|
—
|
573
|
-
<div class='inline'>
|
574
|
-
<p>a customizable set of options</p>
|
564
|
+
<div class='inline'><p>a customizable set of options</p>
|
575
565
|
</div>
|
576
566
|
|
577
567
|
</li>
|
@@ -593,8 +583,7 @@
|
|
593
583
|
|
594
584
|
</span>
|
595
585
|
|
596
|
-
— <div class='inline'>
|
597
|
-
<p>An array of additional names you'd like to see refer to this same type.</p>
|
586
|
+
— <div class='inline'><p>An array of additional names you’d like to see refer to this same type.</p>
|
598
587
|
</div>
|
599
588
|
|
600
589
|
</li>
|
@@ -609,8 +598,9 @@
|
|
609
598
|
|
610
599
|
</span>
|
611
600
|
|
612
|
-
— <div class='inline'>
|
613
|
-
<
|
601
|
+
— <div class='inline'><p>Specifies a “sensible default” to return for this type if the value being parsed (via
|
602
|
+
<span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span> or <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span>) is either unset (<code>nil</code>) or blank (<code>''</code>). Note this may be
|
603
|
+
overridden by the user via the <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>/<span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> “if_unset” option.</p>
|
614
604
|
</div>
|
615
605
|
|
616
606
|
</li>
|
@@ -629,12 +619,16 @@
|
|
629
619
|
|
630
620
|
|
631
621
|
—
|
632
|
-
<div class='inline'>
|
633
|
-
|
622
|
+
<div class='inline'><p>A block to act as the parser for the this type. If no block is given, an ArgumentError is
|
623
|
+
raised.</p>
|
634
624
|
|
635
|
-
<p>When the type defined is used via a <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>/<span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> call, this block is invoked with
|
625
|
+
<p>When the type defined is used via a <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>/<span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> call, this block is invoked with
|
626
|
+
the value to be parsed. Said value is guaranteed to be a non-empty String (the “if_unset”
|
627
|
+
check will have already run), but no other assurances as to content are given. The block
|
628
|
+
should return the final output of parsing the given String value as the type being defined.</p>
|
636
629
|
|
637
|
-
<p>If the value given cannot be sensibly parsed into the type defined, the block should raise
|
630
|
+
<p>If the value given cannot be sensibly parsed into the type defined, the block should raise
|
631
|
+
an <span class='object_link'><a href="EnvParser/ValueNotConvertibleError.html" title="EnvParser::ValueNotConvertibleError (class)">ValueNotConvertibleError</a></span>.</p>
|
638
632
|
</div>
|
639
633
|
|
640
634
|
</li>
|
@@ -651,8 +645,7 @@
|
|
651
645
|
|
652
646
|
|
653
647
|
—
|
654
|
-
<div class='inline'>
|
655
|
-
<p>This generates no usable value.</p>
|
648
|
+
<div class='inline'><p>This generates no usable value.</p>
|
656
649
|
</div>
|
657
650
|
|
658
651
|
</li>
|
@@ -728,8 +721,7 @@
|
|
728
721
|
|
729
722
|
</h3><div class="docstring">
|
730
723
|
<div class="discussion">
|
731
|
-
|
732
|
-
<p>Interprets the given value as the specified type.</p>
|
724
|
+
<p>Interprets the given value as the specified type.</p>
|
733
725
|
|
734
726
|
|
735
727
|
</div>
|
@@ -748,8 +740,8 @@
|
|
748
740
|
|
749
741
|
|
750
742
|
—
|
751
|
-
<div class='inline'>
|
752
|
-
|
743
|
+
<div class='inline'><p>The value to parse/interpret. If a String is given, the value will be used as-is. If a
|
744
|
+
Symbol is given, the ENV value for the matching string key will be used.</p>
|
753
745
|
</div>
|
754
746
|
|
755
747
|
</li>
|
@@ -766,8 +758,7 @@
|
|
766
758
|
|
767
759
|
|
768
760
|
—
|
769
|
-
<div class='inline'>
|
770
|
-
<p>a customizable set of options</p>
|
761
|
+
<div class='inline'><p>a customizable set of options</p>
|
771
762
|
</div>
|
772
763
|
|
773
764
|
</li>
|
@@ -789,10 +780,12 @@
|
|
789
780
|
|
790
781
|
</span>
|
791
782
|
|
792
|
-
— <div class='inline'>
|
793
|
-
|
783
|
+
— <div class='inline'><p>The expected return type. A best-effort attempt is made to convert the source String to the
|
784
|
+
requested type.</p>
|
794
785
|
|
795
|
-
<p>If no “as” option is given, an ArgumentError is raised. If the “as” option given is unknown
|
786
|
+
<p>If no “as” option is given, an ArgumentError is raised. If the “as” option given is unknown
|
787
|
+
(the given type has not been previously defined via <span class='object_link'><a href="#define_type-class_method" title="EnvParser.define_type (method)">define_type</a></span>), an
|
788
|
+
<span class='object_link'><a href="EnvParser/UnknownTypeError.html" title="EnvParser::UnknownTypeError (class)">UnknownTypeError</a></span> is raised.</p>
|
796
789
|
</div>
|
797
790
|
|
798
791
|
</li>
|
@@ -804,8 +797,10 @@
|
|
804
797
|
|
805
798
|
</span>
|
806
799
|
|
807
|
-
— <div class='inline'>
|
808
|
-
|
800
|
+
— <div class='inline'><p>Specifies the default value to return if the given “value” is either unset (<code>nil</code>) or blank
|
801
|
+
(<code>''</code>). Any “if_unset” value given will be returned as-is, with no type conversion or other
|
802
|
+
change having been made. If unspecified, the “default” value for <code>nil</code>/<code>''</code> input will
|
803
|
+
depend on the “as” type.</p>
|
809
804
|
</div>
|
810
805
|
|
811
806
|
</li>
|
@@ -817,12 +812,16 @@
|
|
817
812
|
|
818
813
|
</span>
|
819
814
|
|
820
|
-
— <div class='inline'>
|
821
|
-
|
815
|
+
— <div class='inline'><p>Gives a limited set of allowed values (after type conversion). If, after parsing, the final
|
816
|
+
value is not included in the “from_set” list/range, an <span class='object_link'><a href="EnvParser/ValueNotAllowedError.html" title="EnvParser::ValueNotAllowedError (class)">ValueNotAllowedError</a></span> is
|
817
|
+
raised.</p>
|
822
818
|
|
823
|
-
<p>Note that if the “if_unset” option is given and the value to parse is <code>nil</code>/<code
|
819
|
+
<p>Note that if the “if_unset” option is given and the value to parse is <code>nil</code>/<code>''</code>, the
|
820
|
+
“if_unset” value will be returned, even if it is not part of the “from_set” list/range.</p>
|
824
821
|
|
825
|
-
<p>Also note that, due to the nature of the lookup, the “from_set” option is only available
|
822
|
+
<p>Also note that, due to the nature of the lookup, the “from_set” option is only available
|
823
|
+
for scalar values (i.e. not arrays, hashes, or other enumerables). An attempt to use the
|
824
|
+
“from_set” option with a non-scalar value will raise an ArgumentError.</p>
|
826
825
|
</div>
|
827
826
|
|
828
827
|
</li>
|
@@ -834,10 +833,15 @@
|
|
834
833
|
|
835
834
|
</span>
|
836
835
|
|
837
|
-
— <div class='inline'>
|
838
|
-
|
839
|
-
|
840
|
-
<
|
836
|
+
— <div class='inline'><p>If given, the “validated_by” Proc is called with the parsed value (after type conversion)
|
837
|
+
as its sole argument. This allows for user-defined validation of the parsed value beyond
|
838
|
+
what can be enforced by use of the “from_set” option alone. If the Proc’s return value is
|
839
|
+
<code>#blank?</code>, an <span class='object_link'><a href="EnvParser/ValueNotAllowedError.html" title="EnvParser::ValueNotAllowedError (class)">ValueNotAllowedError</a></span> is raised. To accomodate your syntax of
|
840
|
+
choice, this validation Proc may be given as a block instead.</p>
|
841
|
+
|
842
|
+
<p>Note that this option is intended to provide an inspection mechanism only – no mutation
|
843
|
+
of the parsed value should occur within the given Proc. To that end, the argument passed is
|
844
|
+
a <em>frozen</em> duplicate of the parsed value.</p>
|
841
845
|
</div>
|
842
846
|
|
843
847
|
</li>
|
@@ -856,10 +860,11 @@
|
|
856
860
|
|
857
861
|
|
858
862
|
—
|
859
|
-
<div class='inline'>
|
860
|
-
<p>A block (if given) is treated exactly as the “validated_by” Proc would.</p>
|
863
|
+
<div class='inline'><p>A block (if given) is treated exactly as the “validated_by” Proc would.</p>
|
861
864
|
|
862
|
-
<p>Although there is no compelling reason to provide both a “validated_by” Proc <em>and</em> a
|
865
|
+
<p>Although there is no compelling reason to provide both a “validated_by” Proc <em>and</em> a
|
866
|
+
validation block, there is no technical limitation preventing this. <strong>If both are given,
|
867
|
+
both validation checks must pass.</strong></p>
|
863
868
|
</div>
|
864
869
|
|
865
870
|
</li>
|
@@ -937,10 +942,11 @@
|
|
937
942
|
|
938
943
|
</h3><div class="docstring">
|
939
944
|
<div class="discussion">
|
940
|
-
|
941
|
-
|
945
|
+
<p>Parses the referenced value and creates a matching constant in the requested context.</p>
|
946
|
+
|
947
|
+
<p>Multiple calls to <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> may be shortcutted by passing in a Hash whose keys are the
|
948
|
+
variable names and whose values are the options set for each variable’s <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> call.</p>
|
942
949
|
|
943
|
-
<p>Multiple calls to <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> may be shortcutted by passing in a Hash whose keys are the variable names and whose values are the options set for each variable's <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> call.</p>
|
944
950
|
<pre class="code ruby"><code class="ruby">
|
945
951
|
## Example shortcut usage:
|
946
952
|
|
@@ -955,6 +961,7 @@
|
|
955
961
|
)
|
956
962
|
</code></pre>
|
957
963
|
|
964
|
+
|
958
965
|
</div>
|
959
966
|
</div>
|
960
967
|
<div class="tags">
|
@@ -971,8 +978,8 @@
|
|
971
978
|
|
972
979
|
|
973
980
|
—
|
974
|
-
<div class='inline'>
|
975
|
-
<
|
981
|
+
<div class='inline'><p>The name of the value to parse/interpret from the “from” Hash. If the “from” value is
|
982
|
+
<code>ENV</code>, you may give a Symbol and the corresponding String key will be used instead.</p>
|
976
983
|
</div>
|
977
984
|
|
978
985
|
</li>
|
@@ -989,8 +996,7 @@
|
|
989
996
|
|
990
997
|
|
991
998
|
—
|
992
|
-
<div class='inline'>
|
993
|
-
<p>a customizable set of options</p>
|
999
|
+
<div class='inline'><p>a customizable set of options</p>
|
994
1000
|
</div>
|
995
1001
|
|
996
1002
|
</li>
|
@@ -1015,8 +1021,7 @@
|
|
1015
1021
|
|
1016
1022
|
</span>
|
1017
1023
|
|
1018
|
-
— <div class='inline'>
|
1019
|
-
<p>The source Hash from which to pull the value referenced by the “name” key.</p>
|
1024
|
+
— <div class='inline'><p>The source Hash from which to pull the value referenced by the “name” key.</p>
|
1020
1025
|
</div>
|
1021
1026
|
|
1022
1027
|
</li>
|
@@ -1031,8 +1036,8 @@
|
|
1031
1036
|
|
1032
1037
|
</span>
|
1033
1038
|
|
1034
|
-
— <div class='inline'>
|
1035
|
-
|
1039
|
+
— <div class='inline'><p>The module or class in which the constant should be created. Creates global constants by
|
1040
|
+
default.</p>
|
1036
1041
|
</div>
|
1037
1042
|
|
1038
1043
|
</li>
|
@@ -1044,8 +1049,7 @@
|
|
1044
1049
|
|
1045
1050
|
</span>
|
1046
1051
|
|
1047
|
-
— <div class='inline'>
|
1048
|
-
<p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
1052
|
+
— <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
1049
1053
|
</div>
|
1050
1054
|
|
1051
1055
|
</li>
|
@@ -1057,8 +1061,7 @@
|
|
1057
1061
|
|
1058
1062
|
</span>
|
1059
1063
|
|
1060
|
-
— <div class='inline'>
|
1061
|
-
<p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
1064
|
+
— <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
1062
1065
|
</div>
|
1063
1066
|
|
1064
1067
|
</li>
|
@@ -1070,8 +1073,7 @@
|
|
1070
1073
|
|
1071
1074
|
</span>
|
1072
1075
|
|
1073
|
-
— <div class='inline'>
|
1074
|
-
<p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
1076
|
+
— <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
1075
1077
|
</div>
|
1076
1078
|
|
1077
1079
|
</li>
|
@@ -1083,8 +1085,7 @@
|
|
1083
1085
|
|
1084
1086
|
</span>
|
1085
1087
|
|
1086
|
-
— <div class='inline'>
|
1087
|
-
<p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
1088
|
+
— <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
1088
1089
|
</div>
|
1089
1090
|
|
1090
1091
|
</li>
|
@@ -1103,8 +1104,9 @@
|
|
1103
1104
|
|
1104
1105
|
|
1105
1106
|
—
|
1106
|
-
<div class='inline'>
|
1107
|
-
|
1107
|
+
<div class='inline'><p>A block (if given) is treated exactly as in <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>. Note, however, that a single block
|
1108
|
+
cannot be used to register multiple constants simultaneously – each value needing
|
1109
|
+
validation must give its own “validated_by” Proc.</p>
|
1108
1110
|
</div>
|
1109
1111
|
|
1110
1112
|
</li>
|
@@ -1157,16 +1159,13 @@
|
|
1157
1159
|
202
|
1158
1160
|
203
|
1159
1161
|
204
|
1160
|
-
205
|
1161
|
-
206
|
1162
|
-
207
|
1163
|
-
208</pre>
|
1162
|
+
205</pre>
|
1164
1163
|
</td>
|
1165
1164
|
<td>
|
1166
1165
|
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 178</span>
|
1167
1166
|
|
1168
1167
|
<span class='kw'>def</span> <span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_validation_block'>validation_block</span><span class='rparen'>)</span>
|
1169
|
-
<span class='comment'
|
1168
|
+
<span class='comment'># Allow for registering multiple variables simultaneously via a single call.
|
1170
1169
|
</span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Hash</span>
|
1171
1170
|
<span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cannot register multiple values with one block</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
|
1172
1171
|
<span class='kw'>return</span> <span class='id identifier rubyid_register_all'>register_all</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
@@ -1175,20 +1174,17 @@
|
|
1175
1174
|
<span class='id identifier rubyid_from'>from</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='symbol'>:from</span><span class='comma'>,</span> <span class='const'>ENV</span><span class='rparen'>)</span>
|
1176
1175
|
<span class='id identifier rubyid_within'>within</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='symbol'>:within</span><span class='comma'>,</span> <span class='const'>Kernel</span><span class='rparen'>)</span>
|
1177
1176
|
|
1178
|
-
<span class='comment'
|
1179
|
-
</span> <span class='comment'
|
1180
|
-
</span> <span class='comment'
|
1181
|
-
</span> <span class='comment'
|
1177
|
+
<span class='comment'># ENV *seems* like a Hash and it does *some* Hash-y things, but it is NOT a Hash and that can
|
1178
|
+
</span> <span class='comment'># bite you in some cases. Making sure we're working with a straight-up Hash saves a lot of
|
1179
|
+
</span> <span class='comment'># sanity checks later on. This is also a good place to make sure we're working with a String
|
1180
|
+
</span> <span class='comment'># key.
|
1182
1181
|
</span> <span class='kw'>if</span> <span class='id identifier rubyid_from'>from</span> <span class='op'>==</span> <span class='const'>ENV</span>
|
1183
1182
|
<span class='id identifier rubyid_from'>from</span> <span class='op'>=</span> <span class='id identifier rubyid_from'>from</span><span class='period'>.</span><span class='id identifier rubyid_to_h'>to_h</span>
|
1184
1183
|
<span class='id identifier rubyid_name'>name</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>
|
1185
1184
|
<span class='kw'>end</span>
|
1186
1185
|
|
1187
1186
|
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>invalid `from` parameter: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_from'>from</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_from'>from</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Hash</span>
|
1188
|
-
|
1189
|
-
<span class='kw'>unless</span> <span class='id identifier rubyid_within'>within</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Module</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id identifier rubyid_within'>within</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>
|
1190
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>invalid `within` parameter: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_within'>within</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
1191
|
-
<span class='kw'>end</span>
|
1187
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>invalid `within` parameter: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_within'>within</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_within'>within</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Module</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id identifier rubyid_within'>within</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>
|
1192
1188
|
|
1193
1189
|
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_from'>from</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span>
|
1194
1190
|
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_validation_block'>validation_block</span><span class='rparen'>)</span>
|
@@ -1206,9 +1202,9 @@
|
|
1206
1202
|
</div>
|
1207
1203
|
|
1208
1204
|
<div id="footer">
|
1209
|
-
Generated on
|
1210
|
-
<a href="
|
1211
|
-
0.9.
|
1205
|
+
Generated on Sun Dec 25 19:19:23 2022 by
|
1206
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1207
|
+
0.9.28 (ruby-3.0.4).
|
1212
1208
|
</div>
|
1213
1209
|
|
1214
1210
|
</div>
|