philiprehberger-env_validator 0.4.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 +10 -0
- data/README.md +23 -1
- data/lib/philiprehberger/env_validator/result.rb +22 -3
- 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,16 @@ 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
|
+
|
|
15
|
+
## [0.5.0] - 2026-04-26
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- `Result#to_h(exclude:)` accepts a list of symbol or string keys to omit from the returned hash, useful for redacting sensitive values during serialization
|
|
19
|
+
|
|
10
20
|
## [0.4.0] - 2026-04-16
|
|
11
21
|
|
|
12
22
|
### 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
|
|
@@ -80,8 +82,15 @@ end
|
|
|
80
82
|
config.keys # => ["PORT", "HOST"]
|
|
81
83
|
config.key?(:PORT) # => true
|
|
82
84
|
config.slice(:PORT) # => { "PORT" => 3000 }
|
|
85
|
+
config.to_h # => { "PORT" => 3000, "HOST" => "localhost" }
|
|
86
|
+
|
|
87
|
+
# Redact sensitive keys when serializing (e.g. for logs)
|
|
88
|
+
config.to_h(exclude: %i[api_key])
|
|
89
|
+
# => { "PORT" => 3000, "HOST" => "localhost" }
|
|
83
90
|
```
|
|
84
91
|
|
|
92
|
+
The `exclude:` list accepts symbols or strings and is matched against keys regardless of how they are stored internally.
|
|
93
|
+
|
|
85
94
|
### Prefix
|
|
86
95
|
|
|
87
96
|
Group related variables with a shared prefix:
|
|
@@ -147,6 +156,18 @@ Each element is stripped of surrounding whitespace and cast to `item_type`. An e
|
|
|
147
156
|
| Boolean | `boolean` | `true/false/1/0/yes/no/on/off` (case-insensitive) |
|
|
148
157
|
| Array | `array` | Delimited string cast to a list of typed elements |
|
|
149
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
|
+
|
|
150
171
|
## API
|
|
151
172
|
|
|
152
173
|
| Method / Class | Description |
|
|
@@ -157,7 +178,8 @@ Each element is stripped of surrounding whitespace and cast to `item_type`. An e
|
|
|
157
178
|
| `Result#keys` | List all defined variable names |
|
|
158
179
|
| `Result#key?(name)` | Check if a variable was defined |
|
|
159
180
|
| `Result#slice(*names)` | Get a subset hash of specific keys |
|
|
160
|
-
| `Result#to_h` | Get all values as a hash |
|
|
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 |
|
|
161
183
|
|
|
162
184
|
## Development
|
|
163
185
|
|
|
@@ -45,9 +45,28 @@ module Philiprehberger
|
|
|
45
45
|
@values.slice(*string_keys)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
#
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
# Return all validated values as a hash, optionally redacting keys.
|
|
49
|
+
#
|
|
50
|
+
# @param exclude [Array<Symbol, String>] keys to omit from the returned hash
|
|
51
|
+
# @return [Hash<String, Object>] all validated values, minus excluded keys
|
|
52
|
+
def to_h(exclude: [])
|
|
53
|
+
return @values.dup if exclude.nil? || exclude.empty?
|
|
54
|
+
|
|
55
|
+
excluded_keys = exclude.map(&:to_s)
|
|
56
|
+
@values.reject { |key, _| excluded_keys.include?(key.to_s) }
|
|
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
|
|
51
70
|
end
|
|
52
71
|
end
|
|
53
72
|
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.
|