env_parser 1.6.1 → 1.6.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.
data/docs/css/style.css CHANGED
@@ -82,6 +82,11 @@ body {
82
82
  #search { display: none; }
83
83
  }
84
84
 
85
+ @media (max-width: 320px) {
86
+ body { height: 100%; overflow: hidden; overflow-wrap: break-word; }
87
+ #main { height: 100%; overflow: auto; }
88
+ }
89
+
85
90
  #main img { max-width: 100%; }
86
91
  h1 { font-size: 25px; margin: 1em 0 0.5em; padding-top: 4px; border-top: 1px dotted #d5d5d5; }
87
92
  h1.noborder { border-top: 0px; margin-top: 0; padding-top: 4px; }
@@ -106,6 +111,7 @@ h2 small a {
106
111
  position: relative;
107
112
  padding: 2px 7px;
108
113
  }
114
+ a { font-weight: 550; }
109
115
  .clear { clear: both; }
110
116
  .inline { display: inline; }
111
117
  .inline p:first-child { display: inline; }
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  File: README
8
8
 
9
- &mdash; Documentation by YARD 0.9.28
9
+ &mdash; Documentation by YARD 0.9.37
10
10
 
11
11
  </title>
12
12
 
@@ -58,7 +58,7 @@
58
58
  </div>
59
59
 
60
60
  <div id="content"><div id='filecontents'><p><a href="https://rubygems.org/gems/env_parser"><img src="https://img.shields.io/github/v/release/nestor-custodio/env_parser?color=green&amp;label=gem%20version" alt="Gem Version" /></a>
61
- <a href="https://github.com/nestor-custodio/env_parser/blob/main/LICENSE.txt"><img src="https://img.shields.io/github/license/nestor-custodio/env_parser" alt="MIT License" /></a></p>
61
+ <a href="https://tldrlegal.com/license/mit-license"><img src="https://img.shields.io/github/license/nestor-custodio/env_parser" alt="MIT License" /></a></p>
62
62
 
63
63
  <h1 id="envparser">EnvParser</h1>
64
64
 
@@ -105,19 +105,20 @@ $ gem install env_parser
105
105
  <p>```ruby
106
106
  # Returns an ENV value parsed “as” a specific type:
107
107
  #
108
- EnvParser.parse env_key_as_a_symbol
109
- as: # ➜ required
110
- if_unset: # ➜ optional; default value
111
- from_set: # ➜ optional; an Array or Range
108
+ EnvParser.parse env_key_as_a_symbol,
109
+ as: …, # ➜ required; Symbol
110
+ if_unset: …, # ➜ optional; default value (of any type)
111
+ from_set: …, # ➜ optional; Array or Range
112
112
  validated_by: -&gt;(value) { … } # ➜ optional; may also be given as a block</p>
113
113
 
114
114
  <h1 id="parse-an-env-value-and-register-it-as-a-constant">Parse an ENV value and register it as a constant:</h1>
115
115
  <p>#
116
- EnvParser.register env_key_as_a_symbol
117
- as: # ➜ required
118
- within: # ➜ optional; Class or Module
119
- if_unset: # ➜ optional; default value
120
- from_set: # ➜ optional; an Array or Range
116
+ EnvParser.register env_key_as_a_symbol,
117
+ as: …, # ➜ required; Symbol
118
+ named: …, # ➜ optional; String or Symbol; available only if <code>within</code> is also given
119
+ within: …, # ➜ optional; Class or Module
120
+ if_unset: …, # ➜ optional; default value (of any type)
121
+ from_set: …, # ➜ optional; Array or Range
121
122
  validated_by: -&gt;(value) { … } # ➜ optional; may also be given as a block</p>
122
123
 
123
124
  <h1 id="registers-all-env-variables-as-speced-in-envparseryml">Registers all ENV variables as spec’ed in “.env_parser.yml”:</h1>
@@ -184,6 +185,18 @@ ENV[‘BEST_VIDEO’] # =&gt; ‘https://youtu.be/L_jWHffIx5E’</p>
184
185
  <p>EnvParser.register :BEST_VIDEO, as: :string, within: URI
185
186
  URI::BEST_VIDEO # =&gt; ‘https://youtu.be/L_jWHffIx5E’
186
187
  BEST_VIDEO # =&gt; raises NameError
188
+ ```</p>
189
+
190
+ <p><code>EnvParser.register</code>’s <strong><em>within</em></strong> option also allows for specifying what you would like the registered constant to be <strong><em>named</em></strong>, since related ENV variables will tend to have redundant names once namespaced within a single class or module. Note that <code>named</code> is only available when used alongside <code>within</code>, as it exists solely as a namespacing aid; registering ENV variables as <em>global</em> constants with different names would be a debugging nightmare.</p>
191
+
192
+ <p>```ruby
193
+ ENV[‘CUSTOM_CLIENT_DEFAULT_HOSTNAME’] # =&gt; ‘localhost’
194
+ ENV[‘CUSTOM_CLIENT_DEFAULT_PORT’ ] # =&gt; ‘3000’</p>
195
+
196
+ <p>EnvParser.register :CUSTOM_CLIENT_DEFAULT_HOSTNAME, as: :string , named: :DEFAULT_HOSTNAME, within: CustomClient
197
+ EnvParser.register :CUSTOM_CLIENT_DEFAULT_PORT , as: :integer, named: :DEFAULT_PORT , within: CustomClient
198
+ CustomClient::DEFAULT_HOSTNAME # =&gt; ‘localhost’
199
+ CustomClient::DEFAULT_PORT # =&gt; 3000
187
200
  ```</p>
188
201
 
189
202
  <p>You can also register multiple constants with a single call, which is a bit cleaner.</p>
@@ -252,7 +265,7 @@ ENV.parse :MISSING_VAR, as: :integer # =&gt; 0
252
265
  ENV.parse :MISSING_VAR, as: :integer, if_unset: 250 # =&gt; 250
253
266
  </code></p>
254
267
 
255
- <p>Note these default values are used as-is with no type conversion, so exercise caution.</p>
268
+ <p>Note these default values are used as-is, with no type conversion (because sometimes you just want <code>nil</code> 🤷), so exercise caution.</p>
256
269
 
257
270
  <p><code>ruby
258
271
  ENV.parse :MISSING_VAR, as: :integer, if_unset: 'Careful!' # =&gt; 'Careful!' (NOT AN INTEGER)
@@ -275,7 +288,7 @@ ENV.parse :TWELVE, as: :integer, from_set: (1..5) # =&gt; raises EnvParser::Val
275
288
  <li>
276
289
  <p><strong>Custom Validation Of Parsed Values</strong></p>
277
290
 
278
- <p>You can write your own, more complex validations by passing in a <strong><em>validated_by</em></strong> lambda or an equivalent block. The lambda/block should take one value and return true if the given value passes the custom validation.</p>
291
+ <p>You can write your own, more complex validations by passing in a <strong><em>validated_by</em></strong> lambda or an equivalent block. The lambda/block should expect one value (of the requested <strong><em>as</em></strong> type) and return true if the given value passes the custom validation.</p>
279
292
 
280
293
  <p>```ruby
281
294
  # Via a “validated_by” lambda …
@@ -327,7 +340,7 @@ b = ENV.parse :B, as: :my_special_type_of_number
327
340
  <li>
328
341
  <p><strong>The <code>autoregister</code> Call</strong></p>
329
342
 
330
- <p>Consolidating all of your <code>EnvParser.register</code> calls into a single place only makes sense. A single <code>EnvParser.autoregister</code> call take a filename to read and process as a series of constant registration requests. If no filename is given, the default <code>".env_parser.yml"</code> is assumed.</p>
343
+ <p>Consolidating all of your <code>EnvParser.register</code> calls into a single place only makes sense. A single <code>EnvParser.autoregister</code> call takes a filename to read and process as a series of constant registration requests. If no filename is given, the default <code>".env_parser.yml"</code> is assumed.</p>
331
344
 
332
345
  <p>You’ll normally want to call <code>EnvParser.autoregister</code> as early in your application as possible. For Rails applications (and other frameworks that call <code>require 'bundler/setup'</code>), requiring the EnvParser gem via …</p>
333
346
 
@@ -370,7 +383,7 @@ USERNAME:
370
383
  within: MyClassOrModule
371
384
  ```</p>
372
385
 
373
- <p>Because no Ruby <em>statements</em> can be safely represented via YAML, the set of <code>EnvParser.register</code> options available via autoregistration is limited to <strong><em>as</em></strong>, <strong><em>within</em></strong>, <strong><em>if_unset</em></strong>, and <strong><em>from_set</em></strong>. As an additional restriction, <strong><em>from_set</em></strong> (if given) must be an array, as ranges cannot be represented in YAML.</p>
386
+ <p>Because no Ruby <em>statements</em> can be safely represented via YAML, the set of <code>EnvParser.register</code> options available via autoregistration is limited to <strong><em>as</em></strong>, <strong><em>named</em></strong>, <strong><em>within</em></strong>, <strong><em>if_unset</em></strong>, and <strong><em>from_set</em></strong>. As an additional restriction, <strong><em>from_set</em></strong> (if given) must be an array, as ranges cannot be represented in YAML.</p>
374
387
  </li>
375
388
  </ul>
376
389
 
@@ -396,9 +409,9 @@ USERNAME:
396
409
  </div></div>
397
410
 
398
411
  <div id="footer">
399
- Generated on Fri Dec 30 17:49:58 2022 by
412
+ Generated on Mon Jun 9 14:00:25 2025 by
400
413
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
401
- 0.9.28 (ruby-3.0.4).
414
+ 0.9.37 (ruby-3.4.2).
402
415
  </div>
403
416
 
404
417
  </div>
data/docs/file_list.html CHANGED
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html>
2
- <html>
2
+ <html >
3
3
  <head>
4
4
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
5
  <meta charset="utf-8" />
@@ -38,7 +38,10 @@
38
38
 
39
39
  </div>
40
40
 
41
- <div id="search">Search: <input type="text" /></div>
41
+ <div id="search">
42
+ <label for="search-class">Search:</label>
43
+ <input id="search-class" type="text" />
44
+ </div>
42
45
  </div>
43
46
 
44
47
  <ul id="full_list" class="file">
data/docs/frames.html CHANGED
@@ -2,13 +2,18 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8">
5
- <title>Documentation by YARD 0.9.28</title>
5
+ <title>Documentation by YARD 0.9.37</title>
6
6
  </head>
7
7
  <script type="text/javascript">
8
- var match = unescape(window.location.hash).match(/^#!(.+)/);
9
- var name = match ? match[1] : 'index.html';
10
- name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
11
- window.top.location = name;
8
+ var mainUrl = 'index.html';
9
+ try {
10
+ var match = decodeURIComponent(window.location.hash).match(/^#!(.+)/);
11
+ var name = match ? match[1] : mainUrl;
12
+ var url = new URL(name, location.href);
13
+ window.top.location.replace(url.origin === location.origin ? name : mainUrl);
14
+ } catch (e) {
15
+ window.top.location.replace(mainUrl);
16
+ }
12
17
  </script>
13
18
  <noscript>
14
19
  <h1>Oops!</h1>
data/docs/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  File: README
8
8
 
9
- &mdash; Documentation by YARD 0.9.28
9
+ &mdash; Documentation by YARD 0.9.37
10
10
 
11
11
  </title>
12
12
 
@@ -58,7 +58,7 @@
58
58
  </div>
59
59
 
60
60
  <div id="content"><div id='filecontents'><p><a href="https://rubygems.org/gems/env_parser"><img src="https://img.shields.io/github/v/release/nestor-custodio/env_parser?color=green&amp;label=gem%20version" alt="Gem Version" /></a>
61
- <a href="https://github.com/nestor-custodio/env_parser/blob/main/LICENSE.txt"><img src="https://img.shields.io/github/license/nestor-custodio/env_parser" alt="MIT License" /></a></p>
61
+ <a href="https://tldrlegal.com/license/mit-license"><img src="https://img.shields.io/github/license/nestor-custodio/env_parser" alt="MIT License" /></a></p>
62
62
 
63
63
  <h1 id="envparser">EnvParser</h1>
64
64
 
@@ -105,19 +105,20 @@ $ gem install env_parser
105
105
  <p>```ruby
106
106
  # Returns an ENV value parsed “as” a specific type:
107
107
  #
108
- EnvParser.parse env_key_as_a_symbol
109
- as: # ➜ required
110
- if_unset: # ➜ optional; default value
111
- from_set: # ➜ optional; an Array or Range
108
+ EnvParser.parse env_key_as_a_symbol,
109
+ as: …, # ➜ required; Symbol
110
+ if_unset: …, # ➜ optional; default value (of any type)
111
+ from_set: …, # ➜ optional; Array or Range
112
112
  validated_by: -&gt;(value) { … } # ➜ optional; may also be given as a block</p>
113
113
 
114
114
  <h1 id="parse-an-env-value-and-register-it-as-a-constant">Parse an ENV value and register it as a constant:</h1>
115
115
  <p>#
116
- EnvParser.register env_key_as_a_symbol
117
- as: # ➜ required
118
- within: # ➜ optional; Class or Module
119
- if_unset: # ➜ optional; default value
120
- from_set: # ➜ optional; an Array or Range
116
+ EnvParser.register env_key_as_a_symbol,
117
+ as: …, # ➜ required; Symbol
118
+ named: …, # ➜ optional; String or Symbol; available only if <code>within</code> is also given
119
+ within: …, # ➜ optional; Class or Module
120
+ if_unset: …, # ➜ optional; default value (of any type)
121
+ from_set: …, # ➜ optional; Array or Range
121
122
  validated_by: -&gt;(value) { … } # ➜ optional; may also be given as a block</p>
122
123
 
123
124
  <h1 id="registers-all-env-variables-as-speced-in-envparseryml">Registers all ENV variables as spec’ed in “.env_parser.yml”:</h1>
@@ -184,6 +185,18 @@ ENV[‘BEST_VIDEO’] # =&gt; ‘https://youtu.be/L_jWHffIx5E’</p>
184
185
  <p>EnvParser.register :BEST_VIDEO, as: :string, within: URI
185
186
  URI::BEST_VIDEO # =&gt; ‘https://youtu.be/L_jWHffIx5E’
186
187
  BEST_VIDEO # =&gt; raises NameError
188
+ ```</p>
189
+
190
+ <p><code>EnvParser.register</code>’s <strong><em>within</em></strong> option also allows for specifying what you would like the registered constant to be <strong><em>named</em></strong>, since related ENV variables will tend to have redundant names once namespaced within a single class or module. Note that <code>named</code> is only available when used alongside <code>within</code>, as it exists solely as a namespacing aid; registering ENV variables as <em>global</em> constants with different names would be a debugging nightmare.</p>
191
+
192
+ <p>```ruby
193
+ ENV[‘CUSTOM_CLIENT_DEFAULT_HOSTNAME’] # =&gt; ‘localhost’
194
+ ENV[‘CUSTOM_CLIENT_DEFAULT_PORT’ ] # =&gt; ‘3000’</p>
195
+
196
+ <p>EnvParser.register :CUSTOM_CLIENT_DEFAULT_HOSTNAME, as: :string , named: :DEFAULT_HOSTNAME, within: CustomClient
197
+ EnvParser.register :CUSTOM_CLIENT_DEFAULT_PORT , as: :integer, named: :DEFAULT_PORT , within: CustomClient
198
+ CustomClient::DEFAULT_HOSTNAME # =&gt; ‘localhost’
199
+ CustomClient::DEFAULT_PORT # =&gt; 3000
187
200
  ```</p>
188
201
 
189
202
  <p>You can also register multiple constants with a single call, which is a bit cleaner.</p>
@@ -252,7 +265,7 @@ ENV.parse :MISSING_VAR, as: :integer # =&gt; 0
252
265
  ENV.parse :MISSING_VAR, as: :integer, if_unset: 250 # =&gt; 250
253
266
  </code></p>
254
267
 
255
- <p>Note these default values are used as-is with no type conversion, so exercise caution.</p>
268
+ <p>Note these default values are used as-is, with no type conversion (because sometimes you just want <code>nil</code> 🤷), so exercise caution.</p>
256
269
 
257
270
  <p><code>ruby
258
271
  ENV.parse :MISSING_VAR, as: :integer, if_unset: 'Careful!' # =&gt; 'Careful!' (NOT AN INTEGER)
@@ -275,7 +288,7 @@ ENV.parse :TWELVE, as: :integer, from_set: (1..5) # =&gt; raises EnvParser::Val
275
288
  <li>
276
289
  <p><strong>Custom Validation Of Parsed Values</strong></p>
277
290
 
278
- <p>You can write your own, more complex validations by passing in a <strong><em>validated_by</em></strong> lambda or an equivalent block. The lambda/block should take one value and return true if the given value passes the custom validation.</p>
291
+ <p>You can write your own, more complex validations by passing in a <strong><em>validated_by</em></strong> lambda or an equivalent block. The lambda/block should expect one value (of the requested <strong><em>as</em></strong> type) and return true if the given value passes the custom validation.</p>
279
292
 
280
293
  <p>```ruby
281
294
  # Via a “validated_by” lambda …
@@ -327,7 +340,7 @@ b = ENV.parse :B, as: :my_special_type_of_number
327
340
  <li>
328
341
  <p><strong>The <code>autoregister</code> Call</strong></p>
329
342
 
330
- <p>Consolidating all of your <code>EnvParser.register</code> calls into a single place only makes sense. A single <code>EnvParser.autoregister</code> call take a filename to read and process as a series of constant registration requests. If no filename is given, the default <code>".env_parser.yml"</code> is assumed.</p>
343
+ <p>Consolidating all of your <code>EnvParser.register</code> calls into a single place only makes sense. A single <code>EnvParser.autoregister</code> call takes a filename to read and process as a series of constant registration requests. If no filename is given, the default <code>".env_parser.yml"</code> is assumed.</p>
331
344
 
332
345
  <p>You’ll normally want to call <code>EnvParser.autoregister</code> as early in your application as possible. For Rails applications (and other frameworks that call <code>require 'bundler/setup'</code>), requiring the EnvParser gem via …</p>
333
346
 
@@ -370,7 +383,7 @@ USERNAME:
370
383
  within: MyClassOrModule
371
384
  ```</p>
372
385
 
373
- <p>Because no Ruby <em>statements</em> can be safely represented via YAML, the set of <code>EnvParser.register</code> options available via autoregistration is limited to <strong><em>as</em></strong>, <strong><em>within</em></strong>, <strong><em>if_unset</em></strong>, and <strong><em>from_set</em></strong>. As an additional restriction, <strong><em>from_set</em></strong> (if given) must be an array, as ranges cannot be represented in YAML.</p>
386
+ <p>Because no Ruby <em>statements</em> can be safely represented via YAML, the set of <code>EnvParser.register</code> options available via autoregistration is limited to <strong><em>as</em></strong>, <strong><em>named</em></strong>, <strong><em>within</em></strong>, <strong><em>if_unset</em></strong>, and <strong><em>from_set</em></strong>. As an additional restriction, <strong><em>from_set</em></strong> (if given) must be an array, as ranges cannot be represented in YAML.</p>
374
387
  </li>
375
388
  </ul>
376
389
 
@@ -396,9 +409,9 @@ USERNAME:
396
409
  </div></div>
397
410
 
398
411
  <div id="footer">
399
- Generated on Fri Dec 30 17:49:58 2022 by
412
+ Generated on Mon Jun 9 14:00:25 2025 by
400
413
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
401
- 0.9.28 (ruby-3.0.4).
414
+ 0.9.37 (ruby-3.4.2).
402
415
  </div>
403
416
 
404
417
  </div>