env_parser 1.3.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +1 -1
- data/.rubocop.yml +25 -30
- data/.ruby-version +1 -1
- data/Gemfile.lock +51 -43
- data/README.md +1 -1
- data/docs/EnvParser/AutoregisterFileNotFound.html +9 -10
- data/docs/EnvParser/Error.html +8 -9
- data/docs/EnvParser/TypeAlreadyDefinedError.html +8 -9
- data/docs/EnvParser/Types/BaseTypes.html +12 -11
- data/docs/EnvParser/Types/ChronologyTypes.html +10 -9
- data/docs/EnvParser/Types/InternetTypes.html +10 -9
- data/docs/EnvParser/Types.html +9 -10
- data/docs/EnvParser/UnknownTypeError.html +8 -9
- data/docs/EnvParser/UnparseableAutoregisterSpec.html +9 -10
- data/docs/EnvParser/ValueNotAllowedError.html +10 -11
- data/docs/EnvParser/ValueNotConvertibleError.html +8 -10
- data/docs/EnvParser.html +123 -186
- data/docs/_index.html +8 -10
- data/docs/class_list.html +2 -2
- data/docs/css/style.css +3 -2
- data/docs/file.README.html +254 -284
- data/docs/file_list.html +2 -2
- data/docs/frames.html +2 -2
- data/docs/index.html +254 -284
- data/docs/js/app.js +14 -3
- data/docs/method_list.html +3 -11
- data/docs/top-level-namespace.html +7 -85
- 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 +51 -51
- data/lib/env_parser/types.rb +2 -2
- data/lib/env_parser/version.rb +1 -1
- data/lib/env_parser.rb +206 -217
- 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 +54 -50
- data/.travis.yml +0 -5
data/docs/EnvParser.html
CHANGED
@@ -6,15 +6,15 @@
|
|
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
|
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css"
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
14
|
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css"
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
16
|
|
17
|
-
<script type="text/javascript"
|
17
|
+
<script type="text/javascript">
|
18
18
|
pathId = "EnvParser";
|
19
19
|
relpath = '';
|
20
20
|
</script>
|
@@ -103,9 +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
|
108
|
-
different data types.</p>
|
106
|
+
<p>The EnvParser class simplifies parsing of environment variables as different data types.</p>
|
109
107
|
|
110
108
|
|
111
109
|
</div>
|
@@ -137,8 +135,7 @@ different data types.</p>
|
|
137
135
|
<dt id="AUTOREGISTER_FILE-constant" class="">AUTOREGISTER_FILE =
|
138
136
|
<div class="docstring">
|
139
137
|
<div class="discussion">
|
140
|
-
|
141
|
-
<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>
|
142
139
|
|
143
140
|
|
144
141
|
</div>
|
@@ -153,7 +150,7 @@ different data types.</p>
|
|
153
150
|
<dt id="VERSION-constant" class="">VERSION =
|
154
151
|
|
155
152
|
</dt>
|
156
|
-
<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>
|
157
154
|
|
158
155
|
</dl>
|
159
156
|
|
@@ -189,8 +186,7 @@ different data types.</p>
|
|
189
186
|
|
190
187
|
|
191
188
|
|
192
|
-
<span class="summary_desc"><div class='inline'>
|
193
|
-
<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>
|
194
190
|
</div></span>
|
195
191
|
|
196
192
|
</li>
|
@@ -213,9 +209,7 @@ different data types.</p>
|
|
213
209
|
|
214
210
|
|
215
211
|
|
216
|
-
<span class="summary_desc"><div class='inline'>
|
217
|
-
<p>Reads an “autoregister” file and registers the ENV constants defined
|
218
|
-
therein.</p>
|
212
|
+
<span class="summary_desc"><div class='inline'><p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
219
213
|
</div></span>
|
220
214
|
|
221
215
|
</li>
|
@@ -238,9 +232,7 @@ therein.</p>
|
|
238
232
|
|
239
233
|
|
240
234
|
|
241
|
-
<span class="summary_desc"><div class='inline'>
|
242
|
-
<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
|
243
|
-
<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>
|
244
236
|
</div></span>
|
245
237
|
|
246
238
|
</li>
|
@@ -263,8 +255,7 @@ therein.</p>
|
|
263
255
|
|
264
256
|
|
265
257
|
|
266
|
-
<span class="summary_desc"><div class='inline'>
|
267
|
-
<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>
|
268
259
|
</div></span>
|
269
260
|
|
270
261
|
</li>
|
@@ -287,9 +278,7 @@ therein.</p>
|
|
287
278
|
|
288
279
|
|
289
280
|
|
290
|
-
<span class="summary_desc"><div class='inline'>
|
291
|
-
<p>Parses the referenced value and creates a matching constant in the
|
292
|
-
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>
|
293
282
|
</div></span>
|
294
283
|
|
295
284
|
</li>
|
@@ -315,13 +304,11 @@ requested context.</p>
|
|
315
304
|
|
316
305
|
</h3><div class="docstring">
|
317
306
|
<div class="discussion">
|
318
|
-
|
319
|
-
<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>
|
320
308
|
|
321
|
-
<p>The sole difference between these proxy methods and their EnvParser
|
322
|
-
|
323
|
-
|
324
|
-
is equivalent to <a href="'XYZ'">EnvParser.parse(ENV</a>, …)</p>
|
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>
|
325
312
|
|
326
313
|
|
327
314
|
</div>
|
@@ -339,8 +326,7 @@ is equivalent to <a href="'XYZ'">EnvParser.parse(ENV</a>, …)</p>
|
|
339
326
|
|
340
327
|
|
341
328
|
—
|
342
|
-
<div class='inline'>
|
343
|
-
<p>This generates no usable value.</p>
|
329
|
+
<div class='inline'><p>This generates no usable value.</p>
|
344
330
|
</div>
|
345
331
|
|
346
332
|
</li>
|
@@ -353,6 +339,9 @@ is equivalent to <a href="'XYZ'">EnvParser.parse(ENV</a>, …)</p>
|
|
353
339
|
<pre class="lines">
|
354
340
|
|
355
341
|
|
342
|
+
216
|
343
|
+
217
|
344
|
+
218
|
356
345
|
219
|
357
346
|
220
|
358
347
|
221
|
@@ -362,13 +351,10 @@ is equivalent to <a href="'XYZ'">EnvParser.parse(ENV</a>, …)</p>
|
|
362
351
|
225
|
363
352
|
226
|
364
353
|
227
|
365
|
-
228
|
366
|
-
229
|
367
|
-
230
|
368
|
-
231</pre>
|
354
|
+
228</pre>
|
369
355
|
</td>
|
370
356
|
<td>
|
371
|
-
<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>
|
372
358
|
|
373
359
|
<span class='kw'>def</span> <span class='id identifier rubyid_add_env_bindings'>add_env_bindings</span>
|
374
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>
|
@@ -399,13 +385,11 @@ is equivalent to <a href="'XYZ'">EnvParser.parse(ENV</a>, …)</p>
|
|
399
385
|
|
400
386
|
</h3><div class="docstring">
|
401
387
|
<div class="discussion">
|
402
|
-
|
403
|
-
<p>Reads an “autoregister” file and registers the ENV constants defined
|
404
|
-
therein.</p>
|
388
|
+
<p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
|
405
389
|
|
406
|
-
<p>The “autoregister” file is read, parsed as YAML, sanitized for use as a
|
407
|
-
|
408
|
-
|
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>
|
409
393
|
|
410
394
|
|
411
395
|
</div>
|
@@ -426,8 +410,7 @@ return value from that <span class='object_link'>register_all</span> call is pas
|
|
426
410
|
|
427
411
|
|
428
412
|
—
|
429
|
-
<div class='inline'>
|
430
|
-
<p>A path for the autoregister file to parse and process. Defaults to
|
413
|
+
<div class='inline'><p>A path for the autoregister file to parse and process. Defaults to
|
431
414
|
<span class='object_link'><a href="#AUTOREGISTER_FILE-constant" title="EnvParser::AUTOREGISTER_FILE (constant)">AUTOREGISTER_FILE</a></span> if unset.</p>
|
432
415
|
</div>
|
433
416
|
|
@@ -446,9 +429,7 @@ return value from that <span class='object_link'>register_all</span> call is pas
|
|
446
429
|
|
447
430
|
|
448
431
|
—
|
449
|
-
<div class='inline'>
|
450
|
-
<p>The return value from the <span class='object_link'>register_all</span> call that handles the actual
|
451
|
-
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>
|
452
433
|
</div>
|
453
434
|
|
454
435
|
</li>
|
@@ -474,6 +455,9 @@ registration.</p>
|
|
474
455
|
<pre class="lines">
|
475
456
|
|
476
457
|
|
458
|
+
245
|
459
|
+
246
|
460
|
+
247
|
477
461
|
248
|
478
462
|
249
|
479
463
|
250
|
@@ -495,17 +479,14 @@ registration.</p>
|
|
495
479
|
266
|
496
480
|
267
|
497
481
|
268
|
498
|
-
269
|
499
|
-
270
|
500
|
-
271
|
501
|
-
272</pre>
|
482
|
+
269</pre>
|
502
483
|
</td>
|
503
484
|
<td>
|
504
|
-
<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>
|
505
486
|
|
506
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_autoregister'>autoregister</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'
|
507
|
-
<span class='id identifier rubyid_filename'
|
508
|
-
<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>
|
509
490
|
|
510
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>
|
511
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>
|
@@ -518,13 +499,13 @@ registration.</p>
|
|
518
499
|
|
519
500
|
<span class='id identifier rubyid_register_all'>register_all</span> <span class='id identifier rubyid_autoregister_spec'>autoregister_spec</span>
|
520
501
|
|
521
|
-
<span class='comment'
|
522
|
-
</span><span class='comment'
|
502
|
+
<span class='comment'># Psych raises an Errno::ENOENT on file-not-found.
|
503
|
+
</span><span class='comment'>#
|
523
504
|
</span><span class='kw'>rescue</span> <span class='const'>Errno</span><span class='op'>::</span><span class='const'>ENOENT</span>
|
524
|
-
<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>
|
525
506
|
|
526
|
-
<span class='comment'
|
527
|
-
</span><span class='comment'
|
507
|
+
<span class='comment'># Psych raises a Psych::SyntaxError on unparseable YAML.
|
508
|
+
</span><span class='comment'>#
|
528
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>
|
529
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>
|
530
511
|
<span class='kw'>end</span></pre>
|
@@ -544,9 +525,7 @@ registration.</p>
|
|
544
525
|
|
545
526
|
</h3><div class="docstring">
|
546
527
|
<div class="discussion">
|
547
|
-
|
548
|
-
<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
|
549
|
-
<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>
|
550
529
|
|
551
530
|
|
552
531
|
</div>
|
@@ -565,8 +544,7 @@ registration.</p>
|
|
565
544
|
|
566
545
|
|
567
546
|
—
|
568
|
-
<div class='inline'>
|
569
|
-
<p>The name to assign to the type.</p>
|
547
|
+
<div class='inline'><p>The name to assign to the type.</p>
|
570
548
|
</div>
|
571
549
|
|
572
550
|
</li>
|
@@ -583,8 +561,7 @@ registration.</p>
|
|
583
561
|
|
584
562
|
|
585
563
|
—
|
586
|
-
<div class='inline'>
|
587
|
-
<p>a customizable set of options</p>
|
564
|
+
<div class='inline'><p>a customizable set of options</p>
|
588
565
|
</div>
|
589
566
|
|
590
567
|
</li>
|
@@ -606,8 +583,7 @@ registration.</p>
|
|
606
583
|
|
607
584
|
</span>
|
608
585
|
|
609
|
-
— <div class='inline'>
|
610
|
-
<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>
|
611
587
|
</div>
|
612
588
|
|
613
589
|
</li>
|
@@ -622,11 +598,9 @@ registration.</p>
|
|
622
598
|
|
623
599
|
</span>
|
624
600
|
|
625
|
-
— <div class='inline'>
|
626
|
-
<
|
627
|
-
|
628
|
-
blank (<code>''</code>). Note this may be overridden by the user
|
629
|
-
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>
|
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>
|
630
604
|
</div>
|
631
605
|
|
632
606
|
</li>
|
@@ -645,18 +619,16 @@ via the <span class='object_link'><a href="#parse-class_method" title="EnvParser
|
|
645
619
|
|
646
620
|
|
647
621
|
—
|
648
|
-
<div class='inline'>
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
<p>If the value given cannot be sensibly parsed into the type defined, the
|
659
|
-
block should raise an <span class='object_link'><a href="EnvParser/ValueNotConvertibleError.html" title="EnvParser::ValueNotConvertibleError (class)">ValueNotConvertibleError</a></span>.</p>
|
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>
|
624
|
+
|
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>
|
629
|
+
|
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>
|
660
632
|
</div>
|
661
633
|
|
662
634
|
</li>
|
@@ -673,8 +645,7 @@ block should raise an <span class='object_link'><a href="EnvParser/ValueNotConve
|
|
673
645
|
|
674
646
|
|
675
647
|
—
|
676
|
-
<div class='inline'>
|
677
|
-
<p>This generates no usable value.</p>
|
648
|
+
<div class='inline'><p>This generates no usable value.</p>
|
678
649
|
</div>
|
679
650
|
|
680
651
|
</li>
|
@@ -750,8 +721,7 @@ block should raise an <span class='object_link'><a href="EnvParser/ValueNotConve
|
|
750
721
|
|
751
722
|
</h3><div class="docstring">
|
752
723
|
<div class="discussion">
|
753
|
-
|
754
|
-
<p>Interprets the given value as the specified type.</p>
|
724
|
+
<p>Interprets the given value as the specified type.</p>
|
755
725
|
|
756
726
|
|
757
727
|
</div>
|
@@ -770,10 +740,8 @@ block should raise an <span class='object_link'><a href="EnvParser/ValueNotConve
|
|
770
740
|
|
771
741
|
|
772
742
|
—
|
773
|
-
<div class='inline'>
|
774
|
-
|
775
|
-
as-is. If a Symbol is given, the ENV value for the matching string key will
|
776
|
-
be used.</p>
|
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>
|
777
745
|
</div>
|
778
746
|
|
779
747
|
</li>
|
@@ -790,8 +758,7 @@ be used.</p>
|
|
790
758
|
|
791
759
|
|
792
760
|
—
|
793
|
-
<div class='inline'>
|
794
|
-
<p>a customizable set of options</p>
|
761
|
+
<div class='inline'><p>a customizable set of options</p>
|
795
762
|
</div>
|
796
763
|
|
797
764
|
</li>
|
@@ -813,13 +780,12 @@ be used.</p>
|
|
813
780
|
|
814
781
|
</span>
|
815
782
|
|
816
|
-
— <div class='inline'>
|
817
|
-
|
818
|
-
source String to the requested type.</p>
|
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>
|
819
785
|
|
820
|
-
<p>If no “as” option is given, an ArgumentError is raised. If the “as” option
|
821
|
-
|
822
|
-
<span class='object_link'><a href="
|
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>
|
823
789
|
</div>
|
824
790
|
|
825
791
|
</li>
|
@@ -831,13 +797,10 @@ given is unknown (the given type has not been previously defined via
|
|
831
797
|
|
832
798
|
</span>
|
833
799
|
|
834
|
-
— <div class='inline'>
|
835
|
-
<
|
836
|
-
|
837
|
-
|
838
|
-
having been made. If unspecified, the “default” value for
|
839
|
-
<code>nil</code>/<code>''</code> input will depend on the “as”
|
840
|
-
type.</p>
|
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>
|
841
804
|
</div>
|
842
805
|
|
843
806
|
</li>
|
@@ -849,19 +812,16 @@ type.</p>
|
|
849
812
|
|
850
813
|
</span>
|
851
814
|
|
852
|
-
— <div class='inline'>
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
only available for scalar values (i.e. not arrays, hashes, or other
|
863
|
-
enumerables). An attempt to use the “from_set” option with a non-scalar
|
864
|
-
value will raise an ArgumentError.</p>
|
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>
|
818
|
+
|
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>
|
821
|
+
|
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>
|
865
825
|
</div>
|
866
826
|
|
867
827
|
</li>
|
@@ -873,19 +833,15 @@ value will raise an ArgumentError.</p>
|
|
873
833
|
|
874
834
|
</span>
|
875
835
|
|
876
|
-
— <div class='inline'>
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
<p>Note that this option is intended to provide an inspection mechanism only –
|
886
|
-
no mutation of the parsed value should occur within the given Proc. To that
|
887
|
-
end, the argument passed is a <em>frozen</em> duplicate of the parsed
|
888
|
-
value.</p>
|
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>
|
889
845
|
</div>
|
890
846
|
|
891
847
|
</li>
|
@@ -904,13 +860,11 @@ value.</p>
|
|
904
860
|
|
905
861
|
|
906
862
|
—
|
907
|
-
<div class='inline'>
|
908
|
-
<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>
|
909
864
|
|
910
|
-
<p>Although there is no compelling reason to provide both a “validated_by”
|
911
|
-
|
912
|
-
|
913
|
-
pass.</strong></p>
|
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>
|
914
868
|
</div>
|
915
869
|
|
916
870
|
</li>
|
@@ -988,13 +942,11 @@ pass.</strong></p>
|
|
988
942
|
|
989
943
|
</h3><div class="docstring">
|
990
944
|
<div class="discussion">
|
991
|
-
|
992
|
-
|
993
|
-
|
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>
|
994
949
|
|
995
|
-
<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
|
996
|
-
keys are the variable names and whose values are the options set for each
|
997
|
-
variable's <span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span> call.</p>
|
998
950
|
<pre class="code ruby"><code class="ruby">
|
999
951
|
## Example shortcut usage:
|
1000
952
|
|
@@ -1009,6 +961,7 @@ variable's <span class='object_link'><a href="#register-class_method" title=
|
|
1009
961
|
)
|
1010
962
|
</code></pre>
|
1011
963
|
|
964
|
+
|
1012
965
|
</div>
|
1013
966
|
</div>
|
1014
967
|
<div class="tags">
|
@@ -1025,10 +978,8 @@ variable's <span class='object_link'><a href="#register-class_method" title=
|
|
1025
978
|
|
1026
979
|
|
1027
980
|
—
|
1028
|
-
<div class='inline'>
|
1029
|
-
<
|
1030
|
-
“from” value is <code>ENV</code>, you may give a Symbol and the
|
1031
|
-
corresponding String key will be used instead.</p>
|
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>
|
1032
983
|
</div>
|
1033
984
|
|
1034
985
|
</li>
|
@@ -1045,8 +996,7 @@ corresponding String key will be used instead.</p>
|
|
1045
996
|
|
1046
997
|
|
1047
998
|
—
|
1048
|
-
<div class='inline'>
|
1049
|
-
<p>a customizable set of options</p>
|
999
|
+
<div class='inline'><p>a customizable set of options</p>
|
1050
1000
|
</div>
|
1051
1001
|
|
1052
1002
|
</li>
|
@@ -1071,8 +1021,7 @@ corresponding String key will be used instead.</p>
|
|
1071
1021
|
|
1072
1022
|
</span>
|
1073
1023
|
|
1074
|
-
— <div class='inline'>
|
1075
|
-
<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>
|
1076
1025
|
</div>
|
1077
1026
|
|
1078
1027
|
</li>
|
@@ -1087,9 +1036,8 @@ corresponding String key will be used instead.</p>
|
|
1087
1036
|
|
1088
1037
|
</span>
|
1089
1038
|
|
1090
|
-
— <div class='inline'>
|
1091
|
-
|
1092
|
-
constants by default.</p>
|
1039
|
+
— <div class='inline'><p>The module or class in which the constant should be created. Creates global constants by
|
1040
|
+
default.</p>
|
1093
1041
|
</div>
|
1094
1042
|
|
1095
1043
|
</li>
|
@@ -1101,8 +1049,7 @@ constants by default.</p>
|
|
1101
1049
|
|
1102
1050
|
</span>
|
1103
1051
|
|
1104
|
-
— <div class='inline'>
|
1105
|
-
<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>
|
1106
1053
|
</div>
|
1107
1054
|
|
1108
1055
|
</li>
|
@@ -1114,8 +1061,7 @@ constants by default.</p>
|
|
1114
1061
|
|
1115
1062
|
</span>
|
1116
1063
|
|
1117
|
-
— <div class='inline'>
|
1118
|
-
<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>
|
1119
1065
|
</div>
|
1120
1066
|
|
1121
1067
|
</li>
|
@@ -1127,8 +1073,7 @@ constants by default.</p>
|
|
1127
1073
|
|
1128
1074
|
</span>
|
1129
1075
|
|
1130
|
-
— <div class='inline'>
|
1131
|
-
<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>
|
1132
1077
|
</div>
|
1133
1078
|
|
1134
1079
|
</li>
|
@@ -1140,8 +1085,7 @@ constants by default.</p>
|
|
1140
1085
|
|
1141
1086
|
</span>
|
1142
1087
|
|
1143
|
-
— <div class='inline'>
|
1144
|
-
<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>
|
1145
1089
|
</div>
|
1146
1090
|
|
1147
1091
|
</li>
|
@@ -1160,10 +1104,9 @@ constants by default.</p>
|
|
1160
1104
|
|
1161
1105
|
|
1162
1106
|
—
|
1163
|
-
<div class='inline'>
|
1164
|
-
|
1165
|
-
|
1166
|
-
each value needing validation must give its own “validated_by” Proc.</p>
|
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>
|
1167
1110
|
</div>
|
1168
1111
|
|
1169
1112
|
</li>
|
@@ -1216,16 +1159,13 @@ each value needing validation must give its own “validated_by” Proc.</p>
|
|
1216
1159
|
202
|
1217
1160
|
203
|
1218
1161
|
204
|
1219
|
-
205
|
1220
|
-
206
|
1221
|
-
207
|
1222
|
-
208</pre>
|
1162
|
+
205</pre>
|
1223
1163
|
</td>
|
1224
1164
|
<td>
|
1225
1165
|
<pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 178</span>
|
1226
1166
|
|
1227
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>
|
1228
|
-
<span class='comment'
|
1168
|
+
<span class='comment'># Allow for registering multiple variables simultaneously via a single call.
|
1229
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>
|
1230
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>
|
1231
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>
|
@@ -1234,20 +1174,17 @@ each value needing validation must give its own “validated_by” Proc.</p>
|
|
1234
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>
|
1235
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>
|
1236
1176
|
|
1237
|
-
<span class='comment'
|
1238
|
-
</span> <span class='comment'
|
1239
|
-
</span> <span class='comment'
|
1240
|
-
</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.
|
1241
1181
|
</span> <span class='kw'>if</span> <span class='id identifier rubyid_from'>from</span> <span class='op'>==</span> <span class='const'>ENV</span>
|
1242
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>
|
1243
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>
|
1244
1184
|
<span class='kw'>end</span>
|
1245
1185
|
|
1246
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>
|
1247
|
-
|
1248
|
-
<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>
|
1249
|
-
<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>
|
1250
|
-
<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>
|
1251
1188
|
|
1252
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>
|
1253
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>
|
@@ -1265,9 +1202,9 @@ each value needing validation must give its own “validated_by” Proc.</p>
|
|
1265
1202
|
</div>
|
1266
1203
|
|
1267
1204
|
<div id="footer">
|
1268
|
-
Generated on Sun
|
1269
|
-
<a href="
|
1270
|
-
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).
|
1271
1208
|
</div>
|
1272
1209
|
|
1273
1210
|
</div>
|