env_parser 1.6.2 → 1.7.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -4
  3. data/Gemfile.lock +104 -30
  4. data/README.md +2 -2
  5. data/env_parser.gemspec +19 -12
  6. data/lib/env_parser/types/chronology_types.rb +1 -1
  7. data/lib/env_parser/types/internet_types.rb +3 -2
  8. data/lib/env_parser/version.rb +1 -1
  9. data/lib/env_parser.rb +18 -18
  10. metadata +5 -119
  11. data/.circleci/config.yml +0 -63
  12. data/.gitignore +0 -14
  13. data/.rspec +0 -3
  14. data/.rubocop.yml +0 -64
  15. data/.ruby-version +0 -1
  16. data/.yardopts +0 -1
  17. data/bin/console +0 -14
  18. data/bin/setup +0 -8
  19. data/docs/EnvParser/AutoregisterFileNotFound.html +0 -143
  20. data/docs/EnvParser/Error.html +0 -138
  21. data/docs/EnvParser/TypeAlreadyDefined.html +0 -143
  22. data/docs/EnvParser/TypeAlreadyDefinedError.html +0 -142
  23. data/docs/EnvParser/Types/BaseTypes.html +0 -179
  24. data/docs/EnvParser/Types/ChronologyTypes.html +0 -160
  25. data/docs/EnvParser/Types/InternetTypes.html +0 -172
  26. data/docs/EnvParser/Types.html +0 -128
  27. data/docs/EnvParser/UnknownTypeError.html +0 -142
  28. data/docs/EnvParser/UnparseableAutoregisterSpec.html +0 -143
  29. data/docs/EnvParser/ValueNotAllowed.html +0 -144
  30. data/docs/EnvParser/ValueNotAllowedError.html +0 -144
  31. data/docs/EnvParser/ValueNotConvertibleError.html +0 -142
  32. data/docs/EnvParser.html +0 -1240
  33. data/docs/EnvParserTypes/BaseTypes.html +0 -178
  34. data/docs/EnvParserTypes/ChronologyTypes.html +0 -159
  35. data/docs/EnvParserTypes/InternetTypes.html +0 -159
  36. data/docs/EnvParserTypes/TimeTypes.html +0 -158
  37. data/docs/EnvParserTypes.html +0 -129
  38. data/docs/_index.html +0 -243
  39. data/docs/class_list.html +0 -54
  40. data/docs/css/common.css +0 -1
  41. data/docs/css/full_list.css +0 -58
  42. data/docs/css/style.css +0 -503
  43. data/docs/file.README.html +0 -419
  44. data/docs/file_list.html +0 -59
  45. data/docs/frames.html +0 -22
  46. data/docs/index.html +0 -419
  47. data/docs/js/app.js +0 -344
  48. data/docs/js/full_list.js +0 -242
  49. data/docs/js/jquery.js +0 -4
  50. data/docs/method_list.html +0 -94
  51. data/docs/top-level-namespace.html +0 -110
  52. data/spec/env_parser/types/base_types_spec.rb +0 -98
  53. data/spec/env_parser/types/chronology_types_spec.rb +0 -49
  54. data/spec/env_parser/types/internet_types_spec.rb +0 -95
  55. data/spec/env_parser_spec.rb +0 -214
  56. data/spec/spec_helper.rb +0 -14
data/docs/EnvParser.html DELETED
@@ -1,1240 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Class: EnvParser
8
-
9
- &mdash; Documentation by YARD 0.9.37
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="css/style.css" type="text/css" />
14
-
15
- <link rel="stylesheet" href="css/common.css" type="text/css" />
16
-
17
- <script type="text/javascript">
18
- pathId = "EnvParser";
19
- relpath = '';
20
- </script>
21
-
22
-
23
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
-
25
- <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
-
27
-
28
- </head>
29
- <body>
30
- <div class="nav_wrap">
31
- <iframe id="nav" src="class_list.html?1"></iframe>
32
- <div id="resizer"></div>
33
- </div>
34
-
35
- <div id="main" tabindex="-1">
36
- <div id="header">
37
- <div id="menu">
38
-
39
- <a href="_index.html">Index (E)</a> &raquo;
40
-
41
-
42
- <span class="title">EnvParser</span>
43
-
44
- </div>
45
-
46
- <div id="search">
47
-
48
- <a class="full_list_link" id="class_list_link"
49
- href="class_list.html">
50
-
51
- <svg width="24" height="24">
52
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
- </svg>
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <div id="content"><h1>Class: EnvParser
63
-
64
-
65
-
66
- </h1>
67
- <div class="box_info">
68
-
69
- <dl>
70
- <dt>Inherits:</dt>
71
- <dd>
72
- <span class="inheritName">Object</span>
73
-
74
- <ul class="fullTree">
75
- <li>Object</li>
76
-
77
- <li class="next">EnvParser</li>
78
-
79
- </ul>
80
- <a href="#" class="inheritanceTree">show all</a>
81
-
82
- </dd>
83
- </dl>
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
- <dl>
96
- <dt>Defined in:</dt>
97
- <dd>lib/env_parser.rb<span class="defines">,<br />
98
- lib/env_parser/errors.rb,<br /> lib/env_parser/version.rb</span>
99
- </dd>
100
- </dl>
101
-
102
- </div>
103
-
104
- <h2>Overview</h2><div class="docstring">
105
- <div class="discussion">
106
- <p>The EnvParser class simplifies parsing of environment variables as different data types.</p>
107
-
108
-
109
- </div>
110
- </div>
111
- <div class="tags">
112
-
113
-
114
- </div><h2>Defined Under Namespace</h2>
115
- <p class="children">
116
-
117
-
118
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="EnvParser/Types.html" title="EnvParser::Types (module)">Types</a></span>
119
-
120
-
121
-
122
- <strong class="classes">Classes:</strong> <span class='object_link'><a href="EnvParser/AutoregisterFileNotFound.html" title="EnvParser::AutoregisterFileNotFound (class)">AutoregisterFileNotFound</a></span>, <span class='object_link'><a href="EnvParser/Error.html" title="EnvParser::Error (class)">Error</a></span>, <span class='object_link'><a href="EnvParser/TypeAlreadyDefinedError.html" title="EnvParser::TypeAlreadyDefinedError (class)">TypeAlreadyDefinedError</a></span>, <span class='object_link'><a href="EnvParser/UnknownTypeError.html" title="EnvParser::UnknownTypeError (class)">UnknownTypeError</a></span>, <span class='object_link'><a href="EnvParser/UnparseableAutoregisterSpec.html" title="EnvParser::UnparseableAutoregisterSpec (class)">UnparseableAutoregisterSpec</a></span>, <span class='object_link'><a href="EnvParser/ValueNotAllowedError.html" title="EnvParser::ValueNotAllowedError (class)">ValueNotAllowedError</a></span>, <span class='object_link'><a href="EnvParser/ValueNotConvertibleError.html" title="EnvParser::ValueNotConvertibleError (class)">ValueNotConvertibleError</a></span>
123
-
124
-
125
- </p>
126
-
127
-
128
- <h2>
129
- Constant Summary
130
- <small><a href="#" class="constants_summary_toggle">collapse</a></small>
131
- </h2>
132
-
133
- <dl class="constants">
134
-
135
- <dt id="AUTOREGISTER_FILE-constant" class="">AUTOREGISTER_FILE =
136
- <div class="docstring">
137
- <div class="discussion">
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>
139
-
140
-
141
- </div>
142
- </div>
143
- <div class="tags">
144
-
145
-
146
- </div>
147
- </dt>
148
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>.env_parser.yml</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
149
-
150
- <dt id="VERSION-constant" class="">VERSION =
151
-
152
- </dt>
153
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>1.6.2</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
154
-
155
- </dl>
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
- <h2>
166
- Class Method Summary
167
- <small><a href="#" class="summary_toggle">collapse</a></small>
168
- </h2>
169
-
170
- <ul class="summary">
171
-
172
- <li class="public ">
173
- <span class="summary_signature">
174
-
175
- <a href="#add_env_bindings-class_method" title="add_env_bindings (class method)">.<strong>add_env_bindings</strong> &#x21d2; ENV </a>
176
-
177
-
178
-
179
- </span>
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
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>
190
- </div></span>
191
-
192
- </li>
193
-
194
-
195
- <li class="public ">
196
- <span class="summary_signature">
197
-
198
- <a href="#autoregister-class_method" title="autoregister (class method)">.<strong>autoregister</strong>(filename = nil) &#x21d2; Hash </a>
199
-
200
-
201
-
202
- </span>
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
- <span class="summary_desc"><div class='inline'><p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
213
- </div></span>
214
-
215
- </li>
216
-
217
-
218
- <li class="public ">
219
- <span class="summary_signature">
220
-
221
- <a href="#define_type-class_method" title="define_type (class method)">.<strong>define_type</strong>(name, options = {}) {|value| ... } &#x21d2; nil </a>
222
-
223
-
224
-
225
- </span>
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
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>
236
- </div></span>
237
-
238
- </li>
239
-
240
-
241
- <li class="public ">
242
- <span class="summary_signature">
243
-
244
- <a href="#parse-class_method" title="parse (class method)">.<strong>parse</strong>(value, options = {}) {|value| ... } &#x21d2; Object </a>
245
-
246
-
247
-
248
- </span>
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
- <span class="summary_desc"><div class='inline'><p>Interprets the given value as the specified type.</p>
259
- </div></span>
260
-
261
- </li>
262
-
263
-
264
- <li class="public ">
265
- <span class="summary_signature">
266
-
267
- <a href="#register-class_method" title="register (class method)">.<strong>register</strong>(name, options = {}) {|value| ... } &#x21d2; Object </a>
268
-
269
-
270
-
271
- </span>
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
- <span class="summary_desc"><div class='inline'><p>Parses the referenced value and creates a matching constant in the requested context.</p>
282
- </div></span>
283
-
284
- </li>
285
-
286
-
287
- </ul>
288
-
289
-
290
-
291
-
292
- <div id="class_method_details" class="method_details_list">
293
- <h2>Class Method Details</h2>
294
-
295
-
296
- <div class="method_details first">
297
- <h3 class="signature first" id="add_env_bindings-class_method">
298
-
299
- .<strong>add_env_bindings</strong> &#x21d2; <tt>ENV</tt>
300
-
301
-
302
-
303
-
304
-
305
- </h3><div class="docstring">
306
- <div class="discussion">
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>
308
-
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>
312
-
313
-
314
- </div>
315
- </div>
316
- <div class="tags">
317
-
318
- <p class="tag_title">Returns:</p>
319
- <ul class="return">
320
-
321
- <li>
322
-
323
-
324
- <span class='type'>(<tt>ENV</tt>)</span>
325
-
326
-
327
-
328
- &mdash;
329
- <div class='inline'><p>This generates no usable value.</p>
330
- </div>
331
-
332
- </li>
333
-
334
- </ul>
335
-
336
- </div><table class="source_code">
337
- <tr>
338
- <td>
339
- <pre class="lines">
340
-
341
-
342
- 232
343
- 233
344
- 234
345
- 235
346
- 236
347
- 237
348
- 238
349
- 239
350
- 240
351
- 241
352
- 242
353
- 243
354
- 244</pre>
355
- </td>
356
- <td>
357
- <pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 232</span>
358
-
359
- <span class='kw'>def</span> <span class='id identifier rubyid_add_env_bindings'>add_env_bindings</span>
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>
361
- <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</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'>&amp;</span><span class='id identifier rubyid_validation_block'>validation_block</span><span class='rparen'>)</span>
362
- <span class='const'><span class='object_link'><a href="" title="EnvParser (class)">EnvParser</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='kw'>self</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_validation_block'>validation_block</span><span class='rparen'>)</span>
363
- <span class='kw'>end</span>
364
-
365
- <span class='kw'>def</span> <span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
366
- <span class='const'><span class='object_link'><a href="" title="EnvParser (class)">EnvParser</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register'><span class='object_link'><a href="#register-class_method" title="EnvParser.register (method)">register</a></span></span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
367
- <span class='kw'>end</span>
368
- <span class='kw'>end</span>
369
-
370
- <span class='const'>ENV</span>
371
- <span class='kw'>end</span></pre>
372
- </td>
373
- </tr>
374
- </table>
375
- </div>
376
-
377
- <div class="method_details ">
378
- <h3 class="signature " id="autoregister-class_method">
379
-
380
- .<strong>autoregister</strong>(filename = nil) &#x21d2; <tt>Hash</tt>
381
-
382
-
383
-
384
-
385
-
386
- </h3><div class="docstring">
387
- <div class="discussion">
388
- <p>Reads an “autoregister” file and registers the ENV constants defined therein.</p>
389
-
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>
393
-
394
-
395
- </div>
396
- </div>
397
- <div class="tags">
398
- <p class="tag_title">Parameters:</p>
399
- <ul class="param">
400
-
401
- <li>
402
-
403
- <span class='name'>filename</span>
404
-
405
-
406
- <span class='type'>(<tt>String</tt>)</span>
407
-
408
-
409
- <em class="default">(defaults to: <tt>nil</tt>)</em>
410
-
411
-
412
- &mdash;
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>
415
- </div>
416
-
417
- </li>
418
-
419
- </ul>
420
-
421
- <p class="tag_title">Returns:</p>
422
- <ul class="return">
423
-
424
- <li>
425
-
426
-
427
- <span class='type'>(<tt>Hash</tt>)</span>
428
-
429
-
430
-
431
- &mdash;
432
- <div class='inline'><p>The return value from the <span class='object_link'>register_all</span> call that handles the actual registration.</p>
433
- </div>
434
-
435
- </li>
436
-
437
- </ul>
438
- <p class="tag_title">Raises:</p>
439
- <ul class="raise">
440
-
441
- <li>
442
-
443
-
444
- <span class='type'>(<tt><span class='object_link'><a href="EnvParser/AutoregisterFileNotFound.html" title="EnvParser::AutoregisterFileNotFound (class)">EnvParser::AutoregisterFileNotFound</a></span></tt>, <tt><span class='object_link'><a href="EnvParser/UnparseableAutoregisterSpec.html" title="EnvParser::UnparseableAutoregisterSpec (class)">EnvParser::UnparseableAutoregisterSpec</a></span></tt>)</span>
445
-
446
-
447
-
448
- </li>
449
-
450
- </ul>
451
-
452
- </div><table class="source_code">
453
- <tr>
454
- <td>
455
- <pre class="lines">
456
-
457
-
458
- 261
459
- 262
460
- 263
461
- 264
462
- 265
463
- 266
464
- 267
465
- 268
466
- 269
467
- 270
468
- 271
469
- 272
470
- 273
471
- 274
472
- 275
473
- 276
474
- 277
475
- 278
476
- 279
477
- 280
478
- 281
479
- 282
480
- 283
481
- 284
482
- 285</pre>
483
- </td>
484
- <td>
485
- <pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 261</span>
486
-
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>
490
-
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>
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>
493
- <span class='id identifier rubyid_sanitized'>sanitized</span> <span class='op'>=</span> <span class='id identifier rubyid_spec'>spec</span><span class='period'>.</span><span class='id identifier rubyid_slice'>slice</span><span class='lparen'>(</span><span class='symbol'>:as</span><span class='comma'>,</span> <span class='symbol'>:named</span><span class='comma'>,</span> <span class='symbol'>:within</span><span class='comma'>,</span> <span class='symbol'>:if_unset</span><span class='comma'>,</span> <span class='symbol'>:from_set</span><span class='rparen'>)</span>
494
- <span class='id identifier rubyid_sanitized'>sanitized</span><span class='lbracket'>[</span><span class='symbol'>:as</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_sanitized'>sanitized</span><span class='lbracket'>[</span><span class='symbol'>:as</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='kw'>if</span> <span class='id identifier rubyid_sanitized'>sanitized</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span> <span class='symbol'>:as</span>
495
- <span class='id identifier rubyid_sanitized'>sanitized</span><span class='lbracket'>[</span><span class='symbol'>:within</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_sanitized'>sanitized</span><span class='lbracket'>[</span><span class='symbol'>:within</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span> <span class='kw'>if</span> <span class='id identifier rubyid_sanitized'>sanitized</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span> <span class='symbol'>:within</span>
496
-
497
- <span class='id identifier rubyid_sanitized'>sanitized</span>
498
- <span class='kw'>end</span>
499
-
500
- <span class='id identifier rubyid_register_all'>register_all</span> <span class='id identifier rubyid_autoregister_spec'>autoregister_spec</span>
501
-
502
- <span class='comment'># Psych raises an Errno::ENOENT on file-not-found.
503
- </span><span class='comment'>#
504
- </span><span class='kw'>rescue</span> <span class='const'>Errno</span><span class='op'>::</span><span class='const'>ENOENT</span>
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: &quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_filename'>filename</span><span class='embexpr_end'>}</span><span class='tstring_content'>&quot;</span><span class='tstring_end'>)</span></span>
506
-
507
- <span class='comment'># Psych raises a Psych::SyntaxError on unparseable YAML.
508
- </span><span class='comment'>#
509
- </span><span class='kw'>rescue</span> <span class='const'>Psych</span><span class='op'>::</span><span class='const'>SyntaxError</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
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'>&quot;</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'>&quot;</span></span>
511
- <span class='kw'>end</span></pre>
512
- </td>
513
- </tr>
514
- </table>
515
- </div>
516
-
517
- <div class="method_details ">
518
- <h3 class="signature " id="define_type-class_method">
519
-
520
- .<strong>define_type</strong>(name, options = {}) {|value| ... } &#x21d2; <tt>nil</tt>
521
-
522
-
523
-
524
-
525
-
526
- </h3><div class="docstring">
527
- <div class="discussion">
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>
529
-
530
-
531
- </div>
532
- </div>
533
- <div class="tags">
534
- <p class="tag_title">Parameters:</p>
535
- <ul class="param">
536
-
537
- <li>
538
-
539
- <span class='name'>name</span>
540
-
541
-
542
- <span class='type'>(<tt>Symbol</tt>)</span>
543
-
544
-
545
-
546
- &mdash;
547
- <div class='inline'><p>The name to assign to the type.</p>
548
- </div>
549
-
550
- </li>
551
-
552
- <li>
553
-
554
- <span class='name'>options</span>
555
-
556
-
557
- <span class='type'>(<tt>Hash</tt>)</span>
558
-
559
-
560
- <em class="default">(defaults to: <tt>{}</tt>)</em>
561
-
562
-
563
- &mdash;
564
- <div class='inline'><p>a customizable set of options</p>
565
- </div>
566
-
567
- </li>
568
-
569
- </ul>
570
-
571
-
572
-
573
-
574
-
575
-
576
- <p class="tag_title">Options Hash (<tt>options</tt>):</p>
577
- <ul class="option">
578
-
579
- <li>
580
- <span class="name">aliases</span>
581
- <span class="type">(<tt>Array&lt;Symbol&gt;</tt>)</span>
582
- <span class="default">
583
-
584
- </span>
585
-
586
- &mdash; <div class='inline'><p>An array of additional names you’d like to see refer to this same type.</p>
587
- </div>
588
-
589
- </li>
590
-
591
- <li>
592
- <span class="name">if_unset</span>
593
- <span class="type">(<tt>Object</tt>)</span>
594
- <span class="default">
595
-
596
- &mdash; default:
597
- <tt>nil</tt>
598
-
599
- </span>
600
-
601
- &mdash; <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>
604
- </div>
605
-
606
- </li>
607
-
608
- </ul>
609
-
610
-
611
- <p class="tag_title">Yields:</p>
612
- <ul class="yield">
613
-
614
- <li>
615
-
616
-
617
- <span class='type'>(<tt>value</tt>)</span>
618
-
619
-
620
-
621
- &mdash;
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>
632
- </div>
633
-
634
- </li>
635
-
636
- </ul>
637
- <p class="tag_title">Returns:</p>
638
- <ul class="return">
639
-
640
- <li>
641
-
642
-
643
- <span class='type'>(<tt>nil</tt>)</span>
644
-
645
-
646
-
647
- &mdash;
648
- <div class='inline'><p>This generates no usable value.</p>
649
- </div>
650
-
651
- </li>
652
-
653
- </ul>
654
- <p class="tag_title">Raises:</p>
655
- <ul class="raise">
656
-
657
- <li>
658
-
659
-
660
- <span class='type'>(<tt>ArgumentError</tt>, <tt><span class='object_link'><a href="EnvParser/TypeAlreadyDefinedError.html" title="EnvParser::TypeAlreadyDefinedError (class)">EnvParser::TypeAlreadyDefinedError</a></span></tt>)</span>
661
-
662
-
663
-
664
- </li>
665
-
666
- </ul>
667
-
668
- </div><table class="source_code">
669
- <tr>
670
- <td>
671
- <pre class="lines">
672
-
673
-
674
- 44
675
- 45
676
- 46
677
- 47
678
- 48
679
- 49
680
- 50
681
- 51
682
- 52
683
- 53
684
- 54
685
- 55
686
- 56
687
- 57
688
- 58</pre>
689
- </td>
690
- <td>
691
- <pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 44</span>
692
-
693
- <span class='kw'>def</span> <span class='id identifier rubyid_define_type'>define_type</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'>&amp;</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
694
- <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'>&#39;</span><span class='tstring_content'>no parsing block given</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
695
-
696
- <span class='id identifier rubyid_given_types'>given_types</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='const'>Array</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span> <span class='op'>+</span> <span class='const'>Array</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:aliases</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='symbol'>:to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='symbol'>:to_sym</span><span class='rparen'>)</span>
697
- <span class='id identifier rubyid_given_types'>given_types</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_type'>type</span><span class='op'>|</span>
698
- <span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="EnvParser/TypeAlreadyDefinedError.html" title="EnvParser::TypeAlreadyDefinedError (class)">TypeAlreadyDefinedError</a></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>cannot redefine </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_type'>type</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_known_types'>known_types</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='rparen'>)</span>
699
-
700
- <span class='id identifier rubyid_known_types'>known_types</span><span class='lbracket'>[</span><span class='id identifier rubyid_type'>type</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbrace'>{</span>
701
- <span class='label'>parser:</span> <span class='id identifier rubyid_parser'>parser</span><span class='comma'>,</span>
702
- <span class='label'>if_unset:</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:if_unset</span><span class='rbracket'>]</span>
703
- <span class='rbrace'>}</span>
704
- <span class='kw'>end</span>
705
-
706
- <span class='kw'>nil</span>
707
- <span class='kw'>end</span></pre>
708
- </td>
709
- </tr>
710
- </table>
711
- </div>
712
-
713
- <div class="method_details ">
714
- <h3 class="signature " id="parse-class_method">
715
-
716
- .<strong>parse</strong>(value, options = {}) {|value| ... } &#x21d2; <tt>Object</tt>
717
-
718
-
719
-
720
-
721
-
722
- </h3><div class="docstring">
723
- <div class="discussion">
724
- <p>Interprets the given value as the specified type.</p>
725
-
726
-
727
- </div>
728
- </div>
729
- <div class="tags">
730
- <p class="tag_title">Parameters:</p>
731
- <ul class="param">
732
-
733
- <li>
734
-
735
- <span class='name'>value</span>
736
-
737
-
738
- <span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
739
-
740
-
741
-
742
- &mdash;
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>
745
- </div>
746
-
747
- </li>
748
-
749
- <li>
750
-
751
- <span class='name'>options</span>
752
-
753
-
754
- <span class='type'>(<tt>Hash</tt>)</span>
755
-
756
-
757
- <em class="default">(defaults to: <tt>{}</tt>)</em>
758
-
759
-
760
- &mdash;
761
- <div class='inline'><p>a customizable set of options</p>
762
- </div>
763
-
764
- </li>
765
-
766
- </ul>
767
-
768
-
769
-
770
-
771
-
772
-
773
- <p class="tag_title">Options Hash (<tt>options</tt>):</p>
774
- <ul class="option">
775
-
776
- <li>
777
- <span class="name">as</span>
778
- <span class="type">(<tt>Symbol</tt>)</span>
779
- <span class="default">
780
-
781
- </span>
782
-
783
- &mdash; <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>
785
-
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>
789
- </div>
790
-
791
- </li>
792
-
793
- <li>
794
- <span class="name">if_unset</span>
795
- <span class="type">(<tt>Object</tt>)</span>
796
- <span class="default">
797
-
798
- </span>
799
-
800
- &mdash; <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>
804
- </div>
805
-
806
- </li>
807
-
808
- <li>
809
- <span class="name">from_set</span>
810
- <span class="type">(<tt>Array</tt>, <tt>Range</tt>)</span>
811
- <span class="default">
812
-
813
- </span>
814
-
815
- &mdash; <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>
825
- </div>
826
-
827
- </li>
828
-
829
- <li>
830
- <span class="name">validated_by</span>
831
- <span class="type">(<tt>Proc</tt>)</span>
832
- <span class="default">
833
-
834
- </span>
835
-
836
- &mdash; <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>
845
- </div>
846
-
847
- </li>
848
-
849
- </ul>
850
-
851
-
852
- <p class="tag_title">Yields:</p>
853
- <ul class="yield">
854
-
855
- <li>
856
-
857
-
858
- <span class='type'>(<tt>value</tt>)</span>
859
-
860
-
861
-
862
- &mdash;
863
- <div class='inline'><p>A block (if given) is treated exactly as the “validated_by” Proc would.</p>
864
-
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>
868
- </div>
869
-
870
- </li>
871
-
872
- </ul>
873
- <p class="tag_title">Raises:</p>
874
- <ul class="raise">
875
-
876
- <li>
877
-
878
-
879
- <span class='type'>(<tt>ArgumentError</tt>, <tt><span class='object_link'><a href="EnvParser/UnknownTypeError.html" title="EnvParser::UnknownTypeError (class)">EnvParser::UnknownTypeError</a></span></tt>, <tt><span class='object_link'><a href="EnvParser/ValueNotAllowedError.html" title="EnvParser::ValueNotAllowedError (class)">EnvParser::ValueNotAllowedError</a></span></tt>)</span>
880
-
881
-
882
-
883
- </li>
884
-
885
- </ul>
886
-
887
- </div><table class="source_code">
888
- <tr>
889
- <td>
890
- <pre class="lines">
891
-
892
-
893
- 112
894
- 113
895
- 114
896
- 115
897
- 116
898
- 117
899
- 118
900
- 119
901
- 120
902
- 121
903
- 122
904
- 123
905
- 124
906
- 125
907
- 126
908
- 127</pre>
909
- </td>
910
- <td>
911
- <pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 112</span>
912
-
913
- <span class='kw'>def</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='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_validation_block'>validation_block</span><span class='rparen'>)</span>
914
- <span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='const'>ENV</span><span class='lbracket'>[</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Symbol</span>
915
- <span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
916
-
917
- <span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='id identifier rubyid_known_types'>known_types</span><span class='lbracket'>[</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:as</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
918
- <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'>&#39;</span><span class='tstring_content'>missing `as` parameter</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span><span class='lparen'>(</span><span class='symbol'>:as</span><span class='rparen'>)</span>
919
- <span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="EnvParser/UnknownTypeError.html" title="EnvParser::UnknownTypeError (class)">UnknownTypeError</a></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>invalid `as` parameter: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:as</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_type'>type</span>
920
-
921
- <span class='kw'>return</span> <span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span><span class='lparen'>(</span><span class='symbol'>:if_unset</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:if_unset</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='id identifier rubyid_type'>type</span><span class='lbracket'>[</span><span class='symbol'>:if_unset</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
922
-
923
- <span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_type'>type</span><span class='lbracket'>[</span><span class='symbol'>:parser</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
924
- <span class='id identifier rubyid_check_for_set_inclusion'>check_for_set_inclusion</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='label'>set:</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:from_set</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span><span class='lparen'>(</span><span class='symbol'>:from_set</span><span class='rparen'>)</span>
925
- <span class='id identifier rubyid_check_user_defined_validations'>check_user_defined_validations</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='label'>proc:</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:validated_by</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>block:</span> <span class='id identifier rubyid_validation_block'>validation_block</span><span class='rparen'>)</span>
926
-
927
- <span class='id identifier rubyid_value'>value</span>
928
- <span class='kw'>end</span></pre>
929
- </td>
930
- </tr>
931
- </table>
932
- </div>
933
-
934
- <div class="method_details ">
935
- <h3 class="signature " id="register-class_method">
936
-
937
- .<strong>register</strong>(name, options = {}) {|value| ... } &#x21d2; <tt>Object</tt>
938
-
939
-
940
-
941
-
942
-
943
- </h3><div class="docstring">
944
- <div class="discussion">
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>
949
-
950
- <pre class="code ruby"><code class="ruby">
951
- # Example shortcut usage:
952
-
953
- EnvParser.register :A, from: one_hash, as: :integer
954
- EnvParser.register :B, from: another_hash, as: :string, if_unset: &#39;none&#39;
955
-
956
- # ... is equivalent to ...
957
-
958
- EnvParser.register(
959
- A: { from: one_hash, as: :integer }
960
- B: { from: another_hash, as: :string, if_unset: &#39;none&#39; }
961
- )
962
- </code></pre>
963
-
964
-
965
- </div>
966
- </div>
967
- <div class="tags">
968
- <p class="tag_title">Parameters:</p>
969
- <ul class="param">
970
-
971
- <li>
972
-
973
- <span class='name'>name</span>
974
-
975
-
976
- <span class='type'></span>
977
-
978
-
979
-
980
- &mdash;
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>
983
- </div>
984
-
985
- </li>
986
-
987
- <li>
988
-
989
- <span class='name'>options</span>
990
-
991
-
992
- <span class='type'>(<tt>Hash</tt>)</span>
993
-
994
-
995
- <em class="default">(defaults to: <tt>{}</tt>)</em>
996
-
997
-
998
- &mdash;
999
- <div class='inline'><p>a customizable set of options</p>
1000
- </div>
1001
-
1002
- </li>
1003
-
1004
- </ul>
1005
-
1006
-
1007
-
1008
-
1009
-
1010
-
1011
- <p class="tag_title">Options Hash (<tt>options</tt>):</p>
1012
- <ul class="option">
1013
-
1014
- <li>
1015
- <span class="name">from</span>
1016
- <span class="type">(<tt>Hash</tt>)</span>
1017
- <span class="default">
1018
-
1019
- &mdash; default:
1020
- <tt>ENV</tt>
1021
-
1022
- </span>
1023
-
1024
- &mdash; <div class='inline'><p>The source Hash from which to pull the value referenced by the “name” key.</p>
1025
- </div>
1026
-
1027
- </li>
1028
-
1029
- <li>
1030
- <span class="name">named</span>
1031
- <span class="type">(<tt>Symbol</tt>)</span>
1032
- <span class="default">
1033
-
1034
- </span>
1035
-
1036
- &mdash; <div class='inline'><p>The name the constant should be given. Valid only when a “within” value is <em>explicitly</em>
1037
- given. This allows for decoupling ENV variable names from the constant name defined
1038
- within its target class or module, allowing for the ENV variables to be namespaced in
1039
- some way.</p>
1040
-
1041
- <pre class="code ruby"><code class="ruby">
1042
- <span class='const'><span class='object_link'><a href="" title="EnvParser (class)">EnvParser</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span>
1043
- <span class='label'>CUSTOM_CLIENT_DEFAULT_HOSTNAME:</span> <span class='lbrace'>{</span> <span class='label'>as:</span> <span class='symbol'>:string</span><span class='comma'>,</span> <span class='label'>named:</span> <span class='symbol'>:DEFAULT_HOSTNAME</span><span class='comma'>,</span> <span class='label'>within:</span> <span class='const'>CustomClient</span> <span class='rbrace'>}</span><span class='comma'>,</span>
1044
- <span class='label'>CUSTOM_CLIENT_DEFAULT_PORT:</span> <span class='lbrace'>{</span> <span class='label'>as:</span> <span class='symbol'>:integer</span><span class='comma'>,</span> <span class='label'>named:</span> <span class='symbol'>:DEFAULT_PORT</span><span class='comma'>,</span> <span class='label'>within:</span> <span class='const'>CustomClient</span> <span class='rbrace'>}</span>
1045
- <span class='rparen'>)</span>
1046
- </code></pre>
1047
- </div>
1048
-
1049
- </li>
1050
-
1051
- <li>
1052
- <span class="name">within</span>
1053
- <span class="type">(<tt>Module</tt>, <tt>Class</tt>)</span>
1054
- <span class="default">
1055
-
1056
- &mdash; default:
1057
- <tt>Kernel</tt>
1058
-
1059
- </span>
1060
-
1061
- &mdash; <div class='inline'><p>The module or class in which the constant should be created. Creates global constants by
1062
- default.</p>
1063
- </div>
1064
-
1065
- </li>
1066
-
1067
- <li>
1068
- <span class="name">as</span>
1069
- <span class="type">(<tt>Symbol</tt>)</span>
1070
- <span class="default">
1071
-
1072
- </span>
1073
-
1074
- &mdash; <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
1075
- </div>
1076
-
1077
- </li>
1078
-
1079
- <li>
1080
- <span class="name">if_unset</span>
1081
- <span class="type">(<tt>Object</tt>)</span>
1082
- <span class="default">
1083
-
1084
- </span>
1085
-
1086
- &mdash; <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
1087
- </div>
1088
-
1089
- </li>
1090
-
1091
- <li>
1092
- <span class="name">from_set</span>
1093
- <span class="type">(<tt>Array</tt>, <tt>Range</tt>)</span>
1094
- <span class="default">
1095
-
1096
- </span>
1097
-
1098
- &mdash; <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
1099
- </div>
1100
-
1101
- </li>
1102
-
1103
- <li>
1104
- <span class="name">validated_by</span>
1105
- <span class="type">(<tt>Proc</tt>)</span>
1106
- <span class="default">
1107
-
1108
- </span>
1109
-
1110
- &mdash; <div class='inline'><p>See <span class='object_link'><a href="#parse-class_method" title="EnvParser.parse (method)">parse</a></span>.</p>
1111
- </div>
1112
-
1113
- </li>
1114
-
1115
- </ul>
1116
-
1117
-
1118
- <p class="tag_title">Yields:</p>
1119
- <ul class="yield">
1120
-
1121
- <li>
1122
-
1123
-
1124
- <span class='type'>(<tt>value</tt>)</span>
1125
-
1126
-
1127
-
1128
- &mdash;
1129
- <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
1130
- cannot be used to register multiple constants simultaneously – each value needing
1131
- validation must give its own “validated_by” Proc.</p>
1132
- </div>
1133
-
1134
- </li>
1135
-
1136
- </ul>
1137
- <p class="tag_title">Raises:</p>
1138
- <ul class="raise">
1139
-
1140
- <li>
1141
-
1142
-
1143
- <span class='type'>(<tt>ArgumentError</tt>)</span>
1144
-
1145
-
1146
-
1147
- </li>
1148
-
1149
- </ul>
1150
-
1151
- </div><table class="source_code">
1152
- <tr>
1153
- <td>
1154
- <pre class="lines">
1155
-
1156
-
1157
- 191
1158
- 192
1159
- 193
1160
- 194
1161
- 195
1162
- 196
1163
- 197
1164
- 198
1165
- 199
1166
- 200
1167
- 201
1168
- 202
1169
- 203
1170
- 204
1171
- 205
1172
- 206
1173
- 207
1174
- 208
1175
- 209
1176
- 210
1177
- 211
1178
- 212
1179
- 213
1180
- 214
1181
- 215
1182
- 216
1183
- 217
1184
- 218
1185
- 219
1186
- 220
1187
- 221</pre>
1188
- </td>
1189
- <td>
1190
- <pre class="code"><span class="info file"># File 'lib/env_parser.rb', line 191</span>
1191
-
1192
- <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'>&amp;</span><span class='id identifier rubyid_validation_block'>validation_block</span><span class='rparen'>)</span>
1193
- <span class='comment'># Allow for registering multiple variables simultaneously via a single call.
1194
- </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>
1195
- <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'>&#39;</span><span class='tstring_content'>cannot register multiple values with one block</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
1196
- <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>
1197
- <span class='kw'>end</span>
1198
-
1199
- <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>
1200
- <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>
1201
-
1202
- <span class='id identifier rubyid_named'>named</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span>
1203
- <span class='id identifier rubyid_named'>named</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'>:named</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span> <span class='symbol'>:within</span>
1204
-
1205
- <span class='comment'># ENV *seems* like a Hash and it does *some* Hash-y things, but it is NOT a Hash and that can
1206
- </span> <span class='comment'># bite you in some cases. Making sure we&#39;re working with a straight-up Hash saves a lot of
1207
- </span> <span class='comment'># sanity checks later on. This is also a good place to make sure we&#39;re working with a String
1208
- </span> <span class='comment'># key.
1209
- </span> <span class='kw'>if</span> <span class='id identifier rubyid_from'>from</span> <span class='op'>==</span> <span class='const'>ENV</span>
1210
- <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>
1211
- <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>
1212
- <span class='kw'>end</span>
1213
-
1214
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>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'>&quot;</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>
1215
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>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'>&quot;</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>
1216
-
1217
- <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>
1218
- <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'>&amp;</span><span class='id identifier rubyid_validation_block'>validation_block</span><span class='rparen'>)</span>
1219
- <span class='id identifier rubyid_within'>within</span><span class='period'>.</span><span class='id identifier rubyid_const_set'>const_set</span><span class='lparen'>(</span><span class='id identifier rubyid_named'>named</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span><span class='rparen'>)</span>
1220
-
1221
- <span class='id identifier rubyid_value'>value</span>
1222
- <span class='kw'>end</span></pre>
1223
- </td>
1224
- </tr>
1225
- </table>
1226
- </div>
1227
-
1228
- </div>
1229
-
1230
- </div>
1231
-
1232
- <div id="footer">
1233
- Generated on Mon Jun 9 14:00:25 2025 by
1234
- <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1235
- 0.9.37 (ruby-3.4.2).
1236
- </div>
1237
-
1238
- </div>
1239
- </body>
1240
- </html>