nero 0.3.0 → 0.4.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/Appraisals +7 -0
- data/CHANGELOG.md +14 -0
- data/README.md +47 -17
- data/gemfiles/psych_3.gemfile +10 -0
- data/gemfiles/psych_4.gemfile +10 -0
- data/lib/nero/version.rb +1 -1
- data/lib/nero.rb +41 -6
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9822fcc078e4b2c0e9f049da7cf6f37a98a5b9cf607434057f266a393154296e
|
4
|
+
data.tar.gz: b71a5be94f469b564e3a80c80a0545246afbc053f619201f8a0c6c0923a776a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 863f2c0fbeb21286a0d0f51219e07351a93489688eb7c49be5c1c720a3e414d8e43129e2c0e4d23c6e44213e8547a03c28df128210026414e9e3e209bb7ef472
|
7
|
+
data.tar.gz: c431e49a4d5d422b554a891973c0e24b7c1810dd922492d56b39ca6157dc70e3110114d7474d0d2ed3b5076f2bea63d8493b2cd9db64c3354ea051022f8887cb
|
data/Appraisals
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
## [Unreleased]
|
2
|
+
...
|
3
|
+
|
4
|
+
## [0.4.0] - 2025-02-15
|
5
|
+
|
6
|
+
- Add `!ref`-tag:
|
7
|
+
```ruby
|
8
|
+
Nero.load(<<~YAML)
|
9
|
+
min_threads: !env [MIN_THREADS, !ref [max_threads]]
|
10
|
+
max_threads: 5
|
11
|
+
end
|
12
|
+
# => {min_threads: 5, max_threads: 5}
|
13
|
+
```
|
14
|
+
- Support Psych v3
|
15
|
+
...so it can used with Rails v6
|
2
16
|
|
3
17
|
## [0.3.0] - 2025-02-02
|
4
18
|
|
data/README.md
CHANGED
@@ -2,33 +2,33 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/nero)
|
4
4
|
|
5
|
-
Nero is a RubyGem that offers
|
5
|
+
Nero is a RubyGem that offers declarative YAML-tags to simplify config files, e.g. for requiring and coercion of env-vars.
|
6
|
+
Additionally, it allows you to create your own.
|
6
7
|
|
7
|
-
|
8
|
+
**Sample:**
|
8
9
|
|
9
10
|
```yaml
|
10
11
|
development:
|
11
|
-
|
12
|
-
# custom logic how to get a boolean...
|
13
|
-
debug?: <%= ENV["DEBUG"] == "true" %>
|
14
|
-
production:
|
15
|
-
# any ENV.fetch in this section would hamper local development...
|
16
|
-
secret: <%= ENV["SECRET"] %>
|
17
|
-
# custom coercion logic
|
18
|
-
max_threads: <%= ENV.fetch("MAX_THREADS", 5).to_i %>
|
19
|
-
```
|
20
|
-
|
21
|
-
...turn it into this:
|
22
|
-
```yaml
|
23
|
-
development:
|
12
|
+
# env-var with default value
|
24
13
|
secret: !env [SECRET, "dummy"]
|
14
|
+
# optional env-var with coercion
|
25
15
|
debug?: !env/bool? DEBUG
|
26
16
|
production:
|
27
|
-
# required
|
17
|
+
# required env-var (only when getting the production-root)
|
28
18
|
secret: !env SECRET
|
19
|
+
# int coercion
|
29
20
|
max_threads: !env/integer [MAX_THREADS, 5]
|
21
|
+
# something custom
|
22
|
+
cache_ttl: !duration [2, hours]
|
30
23
|
```
|
31
24
|
|
25
|
+
## Highlights
|
26
|
+
|
27
|
+
* 💎 declarative YAML-tags for e.g. requiring and coercing env-vars
|
28
|
+
* 🛠️ add custom tags
|
29
|
+
* 🛤️ `Rails.application.config_for` stand-in
|
30
|
+
* ♻️ Zeitwerk-only dependency
|
31
|
+
|
32
32
|
## Installation
|
33
33
|
|
34
34
|
Install the gem and add to the application's Gemfile by executing:
|
@@ -128,12 +128,37 @@ The following tags are provided:
|
|
128
128
|
- smtps://%s:%s@smtp.gmail.com
|
129
129
|
- !env SMTP_USER
|
130
130
|
- !env SMTP_PASS
|
131
|
-
|
131
|
+
|
132
|
+
# pass it a map (including a key 'fmt') to use references
|
132
133
|
smtp_url: !str/format
|
133
134
|
fmt: smtps://%<user>s:%<pass>s@smtp.gmail.com
|
134
135
|
user: !env SMTP_USER
|
135
136
|
pass: !env SMTP_PASS
|
136
137
|
```
|
138
|
+
- `!ref`
|
139
|
+
Include values from elsewhere:
|
140
|
+
```yaml
|
141
|
+
# simple
|
142
|
+
min_threads: !env [MIN_THREADS, !ref [max_threads]]
|
143
|
+
max_threads: 5
|
144
|
+
|
145
|
+
# oauth_callback -refs-> base.url -refs-> base.host
|
146
|
+
base:
|
147
|
+
host: !env [HOST]
|
148
|
+
url: !str/format ['https://%s', !ref[base, host]]
|
149
|
+
oauth_callback: !str/format
|
150
|
+
- '%s/oauth/callback'
|
151
|
+
- !ref[base, url]
|
152
|
+
|
153
|
+
# refs are resolved within the tree of the selected root.
|
154
|
+
# The following config won't work when doing `Nero.load_config(:app, root: :prod)`
|
155
|
+
dev:
|
156
|
+
max_threads: 5
|
157
|
+
prod:
|
158
|
+
max_threads: !env[MAX_THREADS, !ref[dev, max_threads]]
|
159
|
+
```
|
160
|
+
NOTE future version should raise properly over ref-ing a non-existing path.
|
161
|
+
|
137
162
|
|
138
163
|
Add one yourself:
|
139
164
|
```ruby
|
@@ -152,6 +177,11 @@ Nero.configure do |nero|
|
|
152
177
|
#
|
153
178
|
# Find the value in the respective attribute, e.g. `coder.scalar`:
|
154
179
|
coder.scalar.upcase
|
180
|
+
|
181
|
+
# NOTE when needing just one argument, supporting both scalar and seq allows for chaining:
|
182
|
+
# a: !my/inc 4 # scalar suffices
|
183
|
+
# ...but when chaining, a seq is required:
|
184
|
+
# a: !my/inc [!my/square 2]
|
155
185
|
end
|
156
186
|
|
157
187
|
# Other configuration options:
|
data/lib/nero/version.rb
CHANGED
data/lib/nero.rb
CHANGED
@@ -45,7 +45,7 @@ module Nero
|
|
45
45
|
|
46
46
|
def resolve(ctx)
|
47
47
|
resolve_nested!(ctx)
|
48
|
-
ctx[:tags][@coder.tag].call(@coder)
|
48
|
+
ctx[:tags][@coder.tag].call(@coder, ctx)
|
49
49
|
end
|
50
50
|
|
51
51
|
def resolve_nested!(ctx)
|
@@ -75,8 +75,23 @@ module Nero
|
|
75
75
|
yield configuration if block_given?
|
76
76
|
end
|
77
77
|
|
78
|
+
# helpers for configuration
|
79
|
+
# module TagHelpers
|
80
|
+
# def to_boolean(s)
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
|
78
84
|
def self.add_default_tags!
|
85
|
+
# extend TagHelpers
|
86
|
+
|
79
87
|
configure do |config|
|
88
|
+
config.add_tag("ref") do |coder, ctx|
|
89
|
+
# validate: non-empty coder.seq, only strs, path must exists in ctx[:config]
|
90
|
+
|
91
|
+
path = coder.seq.map(&:to_sym)
|
92
|
+
deep_resolve(ctx[:config].dig(*path), **ctx)
|
93
|
+
end
|
94
|
+
|
80
95
|
config.add_tag("env/integer") do |coder|
|
81
96
|
Integer(env_fetch(*(coder.scalar || coder.seq), all_optional: "999"))
|
82
97
|
end
|
@@ -175,13 +190,14 @@ module Nero
|
|
175
190
|
aliases: true
|
176
191
|
}
|
177
192
|
|
178
|
-
def self.load_config(file, root: nil)
|
193
|
+
def self.load_config(file, root: nil, env: nil)
|
194
|
+
root ||= env
|
179
195
|
add_tags!
|
180
196
|
|
181
197
|
file = resolve_file(file)
|
182
198
|
|
183
199
|
if file.exist?
|
184
|
-
process_yaml(
|
200
|
+
process_yaml(yaml_load_file(file, @yaml_options), root:)
|
185
201
|
else
|
186
202
|
raise "Can't find file #{file}"
|
187
203
|
end
|
@@ -197,10 +213,11 @@ module Nero
|
|
197
213
|
end
|
198
214
|
private_class_method :resolve_file
|
199
215
|
|
200
|
-
def self.load(raw, root: nil)
|
216
|
+
def self.load(raw, root: nil, env: nil)
|
217
|
+
root ||= env
|
201
218
|
add_tags!
|
202
219
|
|
203
|
-
process_yaml(
|
220
|
+
process_yaml(yaml_load(raw, @yaml_options), root:)
|
204
221
|
end
|
205
222
|
|
206
223
|
def self.process_yaml(yaml, root: nil)
|
@@ -208,10 +225,28 @@ module Nero
|
|
208
225
|
root ? _1[root.to_sym] : _1
|
209
226
|
end
|
210
227
|
|
211
|
-
deep_resolve(unresolved, tags: configuration.tags)
|
228
|
+
deep_resolve(unresolved, tags: configuration.tags, config: unresolved)
|
212
229
|
end
|
213
230
|
private_class_method :process_yaml
|
214
231
|
|
232
|
+
def self.yaml_load_file(file, opts = {})
|
233
|
+
if Psych::VERSION < "4"
|
234
|
+
YAML.load_file(file)
|
235
|
+
else
|
236
|
+
YAML.load_file(file, **opts)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
private_class_method :yaml_load_file
|
240
|
+
|
241
|
+
def self.yaml_load(file, opts = {})
|
242
|
+
if Psych::VERSION < "4"
|
243
|
+
YAML.load(file)
|
244
|
+
else
|
245
|
+
YAML.load(file, **opts)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
private_class_method :yaml_load
|
249
|
+
|
215
250
|
def self.add_tags!
|
216
251
|
configuration.tags.keys.each do
|
217
252
|
YAML.add_tag(_1, TagResolver)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gert Goet
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-02-
|
10
|
+
date: 2025-02-15 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: zeitwerk
|
@@ -23,6 +23,20 @@ dependencies:
|
|
23
23
|
- - ">="
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: appraisal
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
26
40
|
description: |
|
27
41
|
Some convenient YAML-tags...
|
28
42
|
- to get environment values: env, env?, env/integer, env/integer?, env/bool, env/bool?.
|
@@ -39,10 +53,13 @@ files:
|
|
39
53
|
- ".envrc"
|
40
54
|
- ".rspec"
|
41
55
|
- ".standard.yml"
|
56
|
+
- Appraisals
|
42
57
|
- CHANGELOG.md
|
43
58
|
- LICENSE.txt
|
44
59
|
- README.md
|
45
60
|
- Rakefile
|
61
|
+
- gemfiles/psych_3.gemfile
|
62
|
+
- gemfiles/psych_4.gemfile
|
46
63
|
- lib/nero.rb
|
47
64
|
- lib/nero/util.rb
|
48
65
|
- lib/nero/version.rb
|