philiprehberger-env_validator 0.5.0 → 0.6.0
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/CHANGELOG.md +5 -0
- data/README.md +15 -0
- data/lib/philiprehberger/env_validator/result.rb +13 -0
- data/lib/philiprehberger/env_validator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0780e54abe494b5db8736bc9d785d1cc9383b34e41c8f3029e0a33b15f213d9
|
|
4
|
+
data.tar.gz: 06e4e7b33320265595ca48fb0ca1d4d71ab5ba978b8b75abd52d622c97e074eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e2d37adc96b99600d61bc346fb08439cb02a5288930f7241e8f5106fd1093d4c87dc620271fd1aa79991a938e8b78eac1b703bf0987c7b929fde313bbef8dfd1
|
|
7
|
+
data.tar.gz: e3df0449a752f36558aef1e80e5fdac3399129c697bee96e4d52c4214cf52147ffe5c7b54030bde138c0e6ff83b5a1189454dbf5fae63331215e8ec768eddb1f
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-06-14
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Result#freeze!` — deeply freezes the underlying values hash and string values, then returns `self`. Lets callers safely treat a validated `Result` as an immutable global/shared config after boot.
|
|
14
|
+
|
|
10
15
|
## [0.5.0] - 2026-04-26
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
[](https://rubygems.org/gems/philiprehberger-env_validator)
|
|
5
5
|
[](https://github.com/philiprehberger/rb-env-validator/commits/main)
|
|
6
6
|
|
|
7
|
+

|
|
8
|
+
|
|
7
9
|
Schema-based environment variable validation with typed accessors
|
|
8
10
|
|
|
9
11
|
## Requirements
|
|
@@ -154,6 +156,18 @@ Each element is stripped of surrounding whitespace and cast to `item_type`. An e
|
|
|
154
156
|
| Boolean | `boolean` | `true/false/1/0/yes/no/on/off` (case-insensitive) |
|
|
155
157
|
| Array | `array` | Delimited string cast to a list of typed elements |
|
|
156
158
|
|
|
159
|
+
### Immutable Configs
|
|
160
|
+
|
|
161
|
+
Once validated at boot time, prevent accidental mutation of the result:
|
|
162
|
+
|
|
163
|
+
```ruby
|
|
164
|
+
ENV_CONFIG = Philiprehberger::EnvValidator.define do
|
|
165
|
+
string :api_key
|
|
166
|
+
end.freeze!
|
|
167
|
+
|
|
168
|
+
ENV_CONFIG.fetch(:api_key) << 'tamper' # => FrozenError
|
|
169
|
+
```
|
|
170
|
+
|
|
157
171
|
## API
|
|
158
172
|
|
|
159
173
|
| Method / Class | Description |
|
|
@@ -165,6 +179,7 @@ Each element is stripped of surrounding whitespace and cast to `item_type`. An e
|
|
|
165
179
|
| `Result#key?(name)` | Check if a variable was defined |
|
|
166
180
|
| `Result#slice(*names)` | Get a subset hash of specific keys |
|
|
167
181
|
| `Result#to_h(exclude:)` | Get all values as a hash; pass `exclude:` to omit keys (symbols or strings) |
|
|
182
|
+
| `Result#freeze!` | Deeply freeze the result; returns self for chaining |
|
|
168
183
|
|
|
169
184
|
## Development
|
|
170
185
|
|
|
@@ -55,6 +55,19 @@ module Philiprehberger
|
|
|
55
55
|
excluded_keys = exclude.map(&:to_s)
|
|
56
56
|
@values.reject { |key, _| excluded_keys.include?(key.to_s) }
|
|
57
57
|
end
|
|
58
|
+
|
|
59
|
+
# Deeply freeze the result so it cannot be mutated after validation.
|
|
60
|
+
#
|
|
61
|
+
# Freezes the underlying values hash, all string keys, and any String
|
|
62
|
+
# values it holds. Useful for global/shared ENV configs that should be
|
|
63
|
+
# immutable after boot.
|
|
64
|
+
#
|
|
65
|
+
# @return [Result] self
|
|
66
|
+
def freeze!
|
|
67
|
+
@values.each_value { |v| v.freeze if v.is_a?(String) && !v.frozen? }
|
|
68
|
+
@values.freeze
|
|
69
|
+
self
|
|
70
|
+
end
|
|
58
71
|
end
|
|
59
72
|
end
|
|
60
73
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-env_validator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Define environment variable schemas with type casting, required/optional
|
|
14
14
|
flags, and defaults. Validates at boot time and provides typed accessors.
|