env_parser 1.3.1 → 1.3.3
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 +2 -2
- data/.gitignore +3 -0
- 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 -126
- 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 +61 -47
- 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
|
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
<dl>
|
|
96
96
|
<dt>Defined in:</dt>
|
|
97
97
|
<dd>lib/env_parser.rb<span class="defines">,<br />
|
|
98
|
-
lib/env_parser/errors.rb
|
|
98
|
+
lib/env_parser/errors.rb</span>
|
|
99
99
|
</dd>
|
|
100
100
|
</dl>
|
|
101
101
|
|
|
@@ -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>
|
|
@@ -149,11 +147,6 @@
|
|
|
149
147
|
</dt>
|
|
150
148
|
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.env_parser.yml</span><span class='tstring_end'>'</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
|
|
151
149
|
|
|
152
|
-
<dt id="VERSION-constant" class="">VERSION =
|
|
153
|
-
|
|
154
|
-
</dt>
|
|
155
|
-
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1.3.1</span><span class='tstring_end'>'</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
|
|
156
|
-
|
|
157
150
|
</dl>
|
|
158
151
|
|
|
159
152
|
|
|
@@ -188,8 +181,7 @@
|
|
|
188
181
|
|
|
189
182
|
|
|
190
183
|
|
|
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>
|
|
184
|
+
<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
185
|
</div></span>
|
|
194
186
|
|
|
195
187
|
</li>
|
|
@@ -212,8 +204,7 @@
|
|
|
212
204
|
|
|
213
205
|
|
|
214
206
|
|
|
215
|
-
<span class="summary_desc"><div class='inline'>
|
|
216
|
-
<p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
|
207
|
+
<span class="summary_desc"><div class='inline'><p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
|
217
208
|
</div></span>
|
|
218
209
|
|
|
219
210
|
</li>
|
|
@@ -236,8 +227,7 @@
|
|
|
236
227
|
|
|
237
228
|
|
|
238
229
|
|
|
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>
|
|
230
|
+
<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
231
|
</div></span>
|
|
242
232
|
|
|
243
233
|
</li>
|
|
@@ -260,8 +250,7 @@
|
|
|
260
250
|
|
|
261
251
|
|
|
262
252
|
|
|
263
|
-
<span class="summary_desc"><div class='inline'>
|
|
264
|
-
<p>Interprets the given value as the specified type.</p>
|
|
253
|
+
<span class="summary_desc"><div class='inline'><p>Interprets the given value as the specified type.</p>
|
|
265
254
|
</div></span>
|
|
266
255
|
|
|
267
256
|
</li>
|
|
@@ -284,8 +273,7 @@
|
|
|
284
273
|
|
|
285
274
|
|
|
286
275
|
|
|
287
|
-
<span class="summary_desc"><div class='inline'>
|
|
288
|
-
<p>Parses the referenced value and creates a matching constant in the requested context.</p>
|
|
276
|
+
<span class="summary_desc"><div class='inline'><p>Parses the referenced value and creates a matching constant in the requested context.</p>
|
|
289
277
|
</div></span>
|
|
290
278
|
|
|
291
279
|
</li>
|
|
@@ -311,10 +299,11 @@
|
|
|
311
299
|
|
|
312
300
|
</h3><div class="docstring">
|
|
313
301
|
<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>
|
|
302
|
+
<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
303
|
|
|
317
|
-
<p>The sole difference between these proxy methods and their EnvParser counterparts is that
|
|
304
|
+
<p>The sole difference between these proxy methods and their EnvParser counterparts is that
|
|
305
|
+
ENV.parse will interpret any value given as an ENV key (as a String), not the given value
|
|
306
|
+
itself. i.e. ENV.parse(‘XYZ’, …) is equivalent to EnvParser.parse(ENV[‘XYZ’], …)</p>
|
|
318
307
|
|
|
319
308
|
|
|
320
309
|
</div>
|
|
@@ -332,8 +321,7 @@
|
|
|
332
321
|
|
|
333
322
|
|
|
334
323
|
—
|
|
335
|
-
<div class='inline'>
|
|
336
|
-
<p>This generates no usable value.</p>
|
|
324
|
+
<div class='inline'><p>This generates no usable value.</p>
|
|
337
325
|
</div>
|
|
338
326
|
|
|
339
327
|
</li>
|
|
@@ -346,6 +334,9 @@
|
|
|
346
334
|
<pre class="lines">
|
|
347
335
|
|
|
348
336
|
|
|
337
|
+
216
|
|
338
|
+
217
|
|
339
|
+
218
|
|
349
340
|
219
|
|
350
341
|
220
|
|
351
342
|
221
|
|
@@ -355,13 +346,10 @@
|
|
|
355
346
|
225
|
|
356
347
|
226
|
|
357
348
|
227
|
|
358
|
-
228
|
|
359
|
-
229
|
|
360
|
-
230
|
|
361
|
-
231</pre>
|
|
349
|
+
228</pre>
|
|
362
350
|
</td>
|
|
363
351
|
<td>
|
|
364
|
-
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line
|
|
352
|
+
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 216</span>
|
|
365
353
|
|
|
366
354
|
<span class='kw'>def</span> <span class='id identifier rubyid_add_env_bindings'>add_env_bindings</span>
|
|
367
355
|
<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 +380,11 @@
|
|
|
392
380
|
|
|
393
381
|
</h3><div class="docstring">
|
|
394
382
|
<div class="discussion">
|
|
395
|
-
|
|
396
|
-
<p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
|
383
|
+
<p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
|
397
384
|
|
|
398
|
-
<p>The “autoregister” file is read, parsed as YAML, sanitized for use as a parameter to
|
|
385
|
+
<p>The “autoregister” file is read, parsed as YAML, sanitized for use as a parameter to
|
|
386
|
+
<span class='object_link'>register_all</span>, and then passed along for processing. The return value from that
|
|
387
|
+
<span class='object_link'>register_all</span> call is passed through.</p>
|
|
399
388
|
|
|
400
389
|
|
|
401
390
|
</div>
|
|
@@ -416,8 +405,8 @@
|
|
|
416
405
|
|
|
417
406
|
|
|
418
407
|
—
|
|
419
|
-
<div class='inline'>
|
|
420
|
-
<
|
|
408
|
+
<div class='inline'><p>A path for the autoregister file to parse and process. Defaults to
|
|
409
|
+
<span class='object_link'><a href="#AUTOREGISTER_FILE-constant" title="EnvParser::AUTOREGISTER_FILE (constant)">AUTOREGISTER_FILE</a></span> if unset.</p>
|
|
421
410
|
</div>
|
|
422
411
|
|
|
423
412
|
</li>
|
|
@@ -435,8 +424,7 @@
|
|
|
435
424
|
|
|
436
425
|
|
|
437
426
|
—
|
|
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>
|
|
427
|
+
<div class='inline'><p>The return value from the <span class='object_link'>register_all</span> call that handles the actual registration.</p>
|
|
440
428
|
</div>
|
|
441
429
|
|
|
442
430
|
</li>
|
|
@@ -462,6 +450,9 @@
|
|
|
462
450
|
<pre class="lines">
|
|
463
451
|
|
|
464
452
|
|
|
453
|
+
245
|
|
454
|
+
246
|
|
455
|
+
247
|
|
465
456
|
248
|
|
466
457
|
249
|
|
467
458
|
250
|
|
@@ -483,17 +474,14 @@
|
|
|
483
474
|
266
|
|
484
475
|
267
|
|
485
476
|
268
|
|
486
|
-
269
|
|
487
|
-
270
|
|
488
|
-
271
|
|
489
|
-
272</pre>
|
|
477
|
+
269</pre>
|
|
490
478
|
</td>
|
|
491
479
|
<td>
|
|
492
|
-
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line
|
|
480
|
+
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 245</span>
|
|
493
481
|
|
|
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'
|
|
482
|
+
<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>
|
|
483
|
+
<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>
|
|
484
|
+
<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
485
|
|
|
498
486
|
<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
487
|
<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 +494,13 @@
|
|
|
506
494
|
|
|
507
495
|
<span class='id identifier rubyid_register_all'>register_all</span> <span class='id identifier rubyid_autoregister_spec'>autoregister_spec</span>
|
|
508
496
|
|
|
509
|
-
<span class='comment'
|
|
510
|
-
</span><span class='comment'
|
|
497
|
+
<span class='comment'># Psych raises an Errno::ENOENT on file-not-found.
|
|
498
|
+
</span><span class='comment'>#
|
|
511
499
|
</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'
|
|
500
|
+
<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
501
|
|
|
514
|
-
<span class='comment'
|
|
515
|
-
</span><span class='comment'
|
|
502
|
+
<span class='comment'># Psych raises a Psych::SyntaxError on unparseable YAML.
|
|
503
|
+
</span><span class='comment'>#
|
|
516
504
|
</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
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/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
506
|
<span class='kw'>end</span></pre>
|
|
@@ -532,8 +520,7 @@
|
|
|
532
520
|
|
|
533
521
|
</h3><div class="docstring">
|
|
534
522
|
<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>
|
|
523
|
+
<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
524
|
|
|
538
525
|
|
|
539
526
|
</div>
|
|
@@ -552,8 +539,7 @@
|
|
|
552
539
|
|
|
553
540
|
|
|
554
541
|
—
|
|
555
|
-
<div class='inline'>
|
|
556
|
-
<p>The name to assign to the type.</p>
|
|
542
|
+
<div class='inline'><p>The name to assign to the type.</p>
|
|
557
543
|
</div>
|
|
558
544
|
|
|
559
545
|
</li>
|
|
@@ -570,8 +556,7 @@
|
|
|
570
556
|
|
|
571
557
|
|
|
572
558
|
—
|
|
573
|
-
<div class='inline'>
|
|
574
|
-
<p>a customizable set of options</p>
|
|
559
|
+
<div class='inline'><p>a customizable set of options</p>
|
|
575
560
|
</div>
|
|
576
561
|
|
|
577
562
|
</li>
|
|
@@ -593,8 +578,7 @@
|
|
|
593
578
|
|
|
594
579
|
</span>
|
|
595
580
|
|
|
596
|
-
— <div class='inline'>
|
|
597
|
-
<p>An array of additional names you'd like to see refer to this same type.</p>
|
|
581
|
+
— <div class='inline'><p>An array of additional names you’d like to see refer to this same type.</p>
|
|
598
582
|
</div>
|
|
599
583
|
|
|
600
584
|
</li>
|
|
@@ -609,8 +593,9 @@
|
|
|
609
593
|
|
|
610
594
|
</span>
|
|
611
595
|
|
|
612
|
-
— <div class='inline'>
|
|
613
|
-
<
|
|
596
|
+
— <div class='inline'><p>Specifies a “sensible default” to return for this type if the value being parsed (via
|
|
597
|
+
<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
|
|
598
|
+
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
599
|
</div>
|
|
615
600
|
|
|
616
601
|
</li>
|
|
@@ -629,12 +614,16 @@
|
|
|
629
614
|
|
|
630
615
|
|
|
631
616
|
—
|
|
632
|
-
<div class='inline'>
|
|
633
|
-
|
|
617
|
+
<div class='inline'><p>A block to act as the parser for the this type. If no block is given, an ArgumentError is
|
|
618
|
+
raised.</p>
|
|
634
619
|
|
|
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
|
|
620
|
+
<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
|
|
621
|
+
the value to be parsed. Said value is guaranteed to be a non-empty String (the “if_unset”
|
|
622
|
+
check will have already run), but no other assurances as to content are given. The block
|
|
623
|
+
should return the final output of parsing the given String value as the type being defined.</p>
|
|
636
624
|
|
|
637
|
-
<p>If the value given cannot be sensibly parsed into the type defined, the block should raise
|
|
625
|
+
<p>If the value given cannot be sensibly parsed into the type defined, the block should raise
|
|
626
|
+
an <span class='object_link'><a href="EnvParser/ValueNotConvertibleError.html" title="EnvParser::ValueNotConvertibleError (class)">ValueNotConvertibleError</a></span>.</p>
|
|
638
627
|
</div>
|
|
639
628
|
|
|
640
629
|
</li>
|
|
@@ -651,8 +640,7 @@
|
|
|
651
640
|
|
|
652
641
|
|
|
653
642
|
—
|
|
654
|
-
<div class='inline'>
|
|
655
|
-
<p>This generates no usable value.</p>
|
|
643
|
+
<div class='inline'><p>This generates no usable value.</p>
|
|
656
644
|
</div>
|
|
657
645
|
|
|
658
646
|
</li>
|
|
@@ -728,8 +716,7 @@
|
|
|
728
716
|
|
|
729
717
|
</h3><div class="docstring">
|
|
730
718
|
<div class="discussion">
|
|
731
|
-
|
|
732
|
-
<p>Interprets the given value as the specified type.</p>
|
|
719
|
+
<p>Interprets the given value as the specified type.</p>
|
|
733
720
|
|
|
734
721
|
|
|
735
722
|
</div>
|
|
@@ -748,8 +735,8 @@
|
|
|
748
735
|
|
|
749
736
|
|
|
750
737
|
—
|
|
751
|
-
<div class='inline'>
|
|
752
|
-
|
|
738
|
+
<div class='inline'><p>The value to parse/interpret. If a String is given, the value will be used as-is. If a
|
|
739
|
+
Symbol is given, the ENV value for the matching string key will be used.</p>
|
|
753
740
|
</div>
|
|
754
741
|
|
|
755
742
|
</li>
|
|
@@ -766,8 +753,7 @@
|
|
|
766
753
|
|
|
767
754
|
|
|
768
755
|
—
|
|
769
|
-
<div class='inline'>
|
|
770
|
-
<p>a customizable set of options</p>
|
|
756
|
+
<div class='inline'><p>a customizable set of options</p>
|
|
771
757
|
</div>
|
|
772
758
|
|
|
773
759
|
</li>
|
|
@@ -789,10 +775,12 @@
|
|
|
789
775
|
|
|
790
776
|
</span>
|
|
791
777
|
|
|
792
|
-
— <div class='inline'>
|
|
793
|
-
|
|
778
|
+
— <div class='inline'><p>The expected return type. A best-effort attempt is made to convert the source String to the
|
|
779
|
+
requested type.</p>
|
|
794
780
|
|
|
795
|
-
<p>If no “as” option is given, an ArgumentError is raised. If the “as” option given is unknown
|
|
781
|
+
<p>If no “as” option is given, an ArgumentError is raised. If the “as” option given is unknown
|
|
782
|
+
(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
|
|
783
|
+
<span class='object_link'><a href="EnvParser/UnknownTypeError.html" title="EnvParser::UnknownTypeError (class)">UnknownTypeError</a></span> is raised.</p>
|
|
796
784
|
</div>
|
|
797
785
|
|
|
798
786
|
</li>
|
|
@@ -804,8 +792,10 @@
|
|
|
804
792
|
|
|
805
793
|
</span>
|
|
806
794
|
|
|
807
|
-
— <div class='inline'>
|
|
808
|
-
|
|
795
|
+
— <div class='inline'><p>Specifies the default value to return if the given “value” is either unset (<code>nil</code>) or blank
|
|
796
|
+
(<code>''</code>). Any “if_unset” value given will be returned as-is, with no type conversion or other
|
|
797
|
+
change having been made. If unspecified, the “default” value for <code>nil</code>/<code>''</code> input will
|
|
798
|
+
depend on the “as” type.</p>
|
|
809
799
|
</div>
|
|
810
800
|
|
|
811
801
|
</li>
|
|
@@ -817,12 +807,16 @@
|
|
|
817
807
|
|
|
818
808
|
</span>
|
|
819
809
|
|
|
820
|
-
— <div class='inline'>
|
|
821
|
-
|
|
810
|
+
— <div class='inline'><p>Gives a limited set of allowed values (after type conversion). If, after parsing, the final
|
|
811
|
+
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
|
|
812
|
+
raised.</p>
|
|
822
813
|
|
|
823
|
-
<p>Note that if the “if_unset” option is given and the value to parse is <code>nil</code>/<code
|
|
814
|
+
<p>Note that if the “if_unset” option is given and the value to parse is <code>nil</code>/<code>''</code>, the
|
|
815
|
+
“if_unset” value will be returned, even if it is not part of the “from_set” list/range.</p>
|
|
824
816
|
|
|
825
|
-
<p>Also note that, due to the nature of the lookup, the “from_set” option is only available
|
|
817
|
+
<p>Also note that, due to the nature of the lookup, the “from_set” option is only available
|
|
818
|
+
for scalar values (i.e. not arrays, hashes, or other enumerables). An attempt to use the
|
|
819
|
+
“from_set” option with a non-scalar value will raise an ArgumentError.</p>
|
|
826
820
|
</div>
|
|
827
821
|
|
|
828
822
|
</li>
|
|
@@ -834,10 +828,15 @@
|
|
|
834
828
|
|
|
835
829
|
</span>
|
|
836
830
|
|
|
837
|
-
— <div class='inline'>
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
<
|
|
831
|
+
— <div class='inline'><p>If given, the “validated_by” Proc is called with the parsed value (after type conversion)
|
|
832
|
+
as its sole argument. This allows for user-defined validation of the parsed value beyond
|
|
833
|
+
what can be enforced by use of the “from_set” option alone. If the Proc’s return value is
|
|
834
|
+
<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
|
|
835
|
+
choice, this validation Proc may be given as a block instead.</p>
|
|
836
|
+
|
|
837
|
+
<p>Note that this option is intended to provide an inspection mechanism only – no mutation
|
|
838
|
+
of the parsed value should occur within the given Proc. To that end, the argument passed is
|
|
839
|
+
a <em>frozen</em> duplicate of the parsed value.</p>
|
|
841
840
|
</div>
|
|
842
841
|
|
|
843
842
|
</li>
|
|
@@ -856,10 +855,11 @@
|
|
|
856
855
|
|
|
857
856
|
|
|
858
857
|
—
|
|
859
|
-
<div class='inline'>
|
|
860
|
-
<p>A block (if given) is treated exactly as the “validated_by” Proc would.</p>
|
|
858
|
+
<div class='inline'><p>A block (if given) is treated exactly as the “validated_by” Proc would.</p>
|
|
861
859
|
|
|
862
|
-
<p>Although there is no compelling reason to provide both a “validated_by” Proc <em>and</em> a
|
|
860
|
+
<p>Although there is no compelling reason to provide both a “validated_by” Proc <em>and</em> a
|
|
861
|
+
validation block, there is no technical limitation preventing this. <strong>If both are given,
|
|
862
|
+
both validation checks must pass.</strong></p>
|
|
863
863
|
</div>
|
|
864
864
|
|
|
865
865
|
</li>
|
|
@@ -937,10 +937,11 @@
|
|
|
937
937
|
|
|
938
938
|
</h3><div class="docstring">
|
|
939
939
|
<div class="discussion">
|
|
940
|
-
|
|
941
|
-
|
|
940
|
+
<p>Parses the referenced value and creates a matching constant in the requested context.</p>
|
|
941
|
+
|
|
942
|
+
<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
|
|
943
|
+
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
944
|
|
|
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
945
|
<pre class="code ruby"><code class="ruby">
|
|
945
946
|
## Example shortcut usage:
|
|
946
947
|
|
|
@@ -955,6 +956,7 @@
|
|
|
955
956
|
)
|
|
956
957
|
</code></pre>
|
|
957
958
|
|
|
959
|
+
|
|
958
960
|
</div>
|
|
959
961
|
</div>
|
|
960
962
|
<div class="tags">
|
|
@@ -971,8 +973,8 @@
|
|
|
971
973
|
|
|
972
974
|
|
|
973
975
|
—
|
|
974
|
-
<div class='inline'>
|
|
975
|
-
<
|
|
976
|
+
<div class='inline'><p>The name of the value to parse/interpret from the “from” Hash. If the “from” value is
|
|
977
|
+
<code>ENV</code>, you may give a Symbol and the corresponding String key will be used instead.</p>
|
|
976
978
|
</div>
|
|
977
979
|
|
|
978
980
|
</li>
|
|
@@ -989,8 +991,7 @@
|
|
|
989
991
|
|
|
990
992
|
|
|
991
993
|
—
|
|
992
|
-
<div class='inline'>
|
|
993
|
-
<p>a customizable set of options</p>
|
|
994
|
+
<div class='inline'><p>a customizable set of options</p>
|
|
994
995
|
</div>
|
|
995
996
|
|
|
996
997
|
</li>
|
|
@@ -1015,8 +1016,7 @@
|
|
|
1015
1016
|
|
|
1016
1017
|
</span>
|
|
1017
1018
|
|
|
1018
|
-
— <div class='inline'>
|
|
1019
|
-
<p>The source Hash from which to pull the value referenced by the “name” key.</p>
|
|
1019
|
+
— <div class='inline'><p>The source Hash from which to pull the value referenced by the “name” key.</p>
|
|
1020
1020
|
</div>
|
|
1021
1021
|
|
|
1022
1022
|
</li>
|
|
@@ -1031,8 +1031,8 @@
|
|
|
1031
1031
|
|
|
1032
1032
|
</span>
|
|
1033
1033
|
|
|
1034
|
-
— <div class='inline'>
|
|
1035
|
-
|
|
1034
|
+
— <div class='inline'><p>The module or class in which the constant should be created. Creates global constants by
|
|
1035
|
+
default.</p>
|
|
1036
1036
|
</div>
|
|
1037
1037
|
|
|
1038
1038
|
</li>
|
|
@@ -1044,8 +1044,7 @@
|
|
|
1044
1044
|
|
|
1045
1045
|
</span>
|
|
1046
1046
|
|
|
1047
|
-
— <div class='inline'>
|
|
1048
|
-
<p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
|
1047
|
+
— <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
|
1049
1048
|
</div>
|
|
1050
1049
|
|
|
1051
1050
|
</li>
|
|
@@ -1057,8 +1056,7 @@
|
|
|
1057
1056
|
|
|
1058
1057
|
</span>
|
|
1059
1058
|
|
|
1060
|
-
— <div class='inline'>
|
|
1061
|
-
<p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
|
1059
|
+
— <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
|
1062
1060
|
</div>
|
|
1063
1061
|
|
|
1064
1062
|
</li>
|
|
@@ -1070,8 +1068,7 @@
|
|
|
1070
1068
|
|
|
1071
1069
|
</span>
|
|
1072
1070
|
|
|
1073
|
-
— <div class='inline'>
|
|
1074
|
-
<p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
|
1071
|
+
— <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
|
1075
1072
|
</div>
|
|
1076
1073
|
|
|
1077
1074
|
</li>
|
|
@@ -1083,8 +1080,7 @@
|
|
|
1083
1080
|
|
|
1084
1081
|
</span>
|
|
1085
1082
|
|
|
1086
|
-
— <div class='inline'>
|
|
1087
|
-
<p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
|
1083
|
+
— <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
|
|
1088
1084
|
</div>
|
|
1089
1085
|
|
|
1090
1086
|
</li>
|
|
@@ -1103,8 +1099,9 @@
|
|
|
1103
1099
|
|
|
1104
1100
|
|
|
1105
1101
|
—
|
|
1106
|
-
<div class='inline'>
|
|
1107
|
-
|
|
1102
|
+
<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
|
|
1103
|
+
cannot be used to register multiple constants simultaneously – each value needing
|
|
1104
|
+
validation must give its own “validated_by” Proc.</p>
|
|
1108
1105
|
</div>
|
|
1109
1106
|
|
|
1110
1107
|
</li>
|
|
@@ -1157,16 +1154,13 @@
|
|
|
1157
1154
|
202
|
|
1158
1155
|
203
|
|
1159
1156
|
204
|
|
1160
|
-
205
|
|
1161
|
-
206
|
|
1162
|
-
207
|
|
1163
|
-
208</pre>
|
|
1157
|
+
205</pre>
|
|
1164
1158
|
</td>
|
|
1165
1159
|
<td>
|
|
1166
1160
|
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 178</span>
|
|
1167
1161
|
|
|
1168
1162
|
<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'
|
|
1163
|
+
<span class='comment'># Allow for registering multiple variables simultaneously via a single call.
|
|
1170
1164
|
</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
1165
|
<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
1166
|
<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 +1169,17 @@
|
|
|
1175
1169
|
<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
1170
|
<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
1171
|
|
|
1178
|
-
<span class='comment'
|
|
1179
|
-
</span> <span class='comment'
|
|
1180
|
-
</span> <span class='comment'
|
|
1181
|
-
</span> <span class='comment'
|
|
1172
|
+
<span class='comment'># ENV *seems* like a Hash and it does *some* Hash-y things, but it is NOT a Hash and that can
|
|
1173
|
+
</span> <span class='comment'># bite you in some cases. Making sure we're working with a straight-up Hash saves a lot of
|
|
1174
|
+
</span> <span class='comment'># sanity checks later on. This is also a good place to make sure we're working with a String
|
|
1175
|
+
</span> <span class='comment'># key.
|
|
1182
1176
|
</span> <span class='kw'>if</span> <span class='id identifier rubyid_from'>from</span> <span class='op'>==</span> <span class='const'>ENV</span>
|
|
1183
1177
|
<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
1178
|
<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
1179
|
<span class='kw'>end</span>
|
|
1186
1180
|
|
|
1187
1181
|
<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>
|
|
1182
|
+
<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
1183
|
|
|
1193
1184
|
<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
1185
|
<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 +1197,9 @@
|
|
|
1206
1197
|
</div>
|
|
1207
1198
|
|
|
1208
1199
|
<div id="footer">
|
|
1209
|
-
Generated on
|
|
1210
|
-
<a href="
|
|
1211
|
-
0.9.
|
|
1200
|
+
Generated on Sun Dec 25 21:09:36 2022 by
|
|
1201
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
1202
|
+
0.9.28 (ruby-3.0.4).
|
|
1212
1203
|
</div>
|
|
1213
1204
|
|
|
1214
1205
|
</div>
|