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