nero 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/.yardopts +6 -0
- data/CHANGELOG.md +23 -0
- data/README.md +34 -13
- data/lib/nero/railtie.rb +10 -0
- data/lib/nero/version.rb +1 -1
- data/lib/nero.rb +219 -47
- data/rakelib/yard.rake +12 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 136899b1a5b7fd355608891703ad0e8b0c628dfcb3ae74d9a5344fb0a78b41b8
|
4
|
+
data.tar.gz: 47fce2793b077af0a637d7cac6a5e31b471c16bbbff71561f97bdf4aa904a3d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 979f099766b6c33577346e608fa8e82f890d4d3ef5b49913a142cdbcb7385ecff78776882e5ee78420f0b285388972aef8e6c4c980d4aff120b8c142efec2212
|
7
|
+
data.tar.gz: e43d9f3916bfc43b3abe49939b3953a72679fec64e8de4de5b682600d6d5ef2f66f97557e262a5558046c9e332532bc908a4317d4a114bc46754d9ff60d3242c
|
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,29 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
...
|
3
3
|
|
4
|
+
## [0.6.0] - 2025-04-10
|
5
|
+
|
6
|
+
### deprecations
|
7
|
+
|
8
|
+
- `Nero.load_config` - use `Nero.load_file` or `Nero.config_for`.
|
9
|
+
|
10
|
+
### other
|
11
|
+
|
12
|
+
- API docs live at https://eval.github.io/nero/
|
13
|
+
- Config for Rails
|
14
|
+
The `config.config_dir` is automatically setup, so `Nero.config_for` (formerly `Nero.load_config`) just works.
|
15
|
+
- `Nero::Config.dig!` ⛏️💥
|
16
|
+
Any (Hash-)result from `Nero.load/load_file/config_for` is now an instance of `Nero::Config`.
|
17
|
+
This class contains `dig!`, a fail-hard variant of `dig`:
|
18
|
+
```ruby
|
19
|
+
Nero.load(<<~Y).dig!(:smtp_settings, :hose) # 💥 typo
|
20
|
+
smtp_settings:
|
21
|
+
host: 127.0.0.1
|
22
|
+
port: 1025
|
23
|
+
Y
|
24
|
+
#=> 'Nero::DigExt#dig!': path not found [:smtp_settings, :hose] (ArgumentError)
|
25
|
+
```
|
26
|
+
|
4
27
|
## [0.5.0] - 2025-03-20
|
5
28
|
|
6
29
|
- tag-classes
|
data/README.md
CHANGED
@@ -47,6 +47,21 @@ Install the gem and add to the application's Gemfile by executing:
|
|
47
47
|
bundle add nero
|
48
48
|
```
|
49
49
|
|
50
|
+
## Configuration
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
Nero.configure do |nero|
|
54
|
+
# Path that `Nero.config_for` uses to resolve Symbol or String files, e.g. `Nero.config_for(:app)`
|
55
|
+
nero.config_dir = "config"
|
56
|
+
|
57
|
+
# Add custom tags (also see section about custom tags)
|
58
|
+
nero.add_tag("upcase") do |tag|
|
59
|
+
# tag is an instance of [Nero::BaseTag](https://eval.github.io/nero/Nero/BaseTag.html).
|
60
|
+
tag.args.join.upcase
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
50
65
|
## Usage
|
51
66
|
|
52
67
|
> [!WARNING]
|
@@ -73,7 +88,7 @@ Loading this config:
|
|
73
88
|
|
74
89
|
```ruby
|
75
90
|
# Loading development
|
76
|
-
Nero.
|
91
|
+
Nero.load_file("config/settings", root: :development)
|
77
92
|
# ...and no ENV-vars were provided
|
78
93
|
#=> {secret: "dummy", debug?: false}
|
79
94
|
|
@@ -81,7 +96,7 @@ Nero.load_config("config/settings", root: :development)
|
|
81
96
|
#=> {secret: "dummy", debug?: true}
|
82
97
|
|
83
98
|
# Loading production
|
84
|
-
Nero.
|
99
|
+
Nero.load_file("config/settings", root: :production)
|
85
100
|
# ...and no ENV-vars were provided
|
86
101
|
# raises error: key not found: "SECRET" (KeyError)
|
87
102
|
|
@@ -89,15 +104,18 @@ Nero.load_config("config/settings", root: :production)
|
|
89
104
|
#=> {secret: "s3cr3t", max_threads: 3}
|
90
105
|
```
|
91
106
|
> [!TIP]
|
92
|
-
>
|
107
|
+
> You can also use `Nero.config_for` (similar to [Rails.application.config_for](https://api.rubyonrails.org/classes/Rails/Application.html#method-i-config_for)).
|
108
|
+
> In Rails applications this gets configured for you. For other application you might need to adjust the `config_dir`:
|
93
109
|
```ruby
|
94
110
|
Nero.configure do |config|
|
95
|
-
config.config_dir =
|
111
|
+
config.config_dir = "config"
|
96
112
|
end
|
97
113
|
|
98
|
-
Nero.
|
114
|
+
Nero.config_for(:settings, env: Rails.env)
|
99
115
|
```
|
100
116
|
|
117
|
+
[API Documentation](https://eval.github.io/nero/).
|
118
|
+
|
101
119
|
### built-in tags
|
102
120
|
|
103
121
|
The following tags are provided:
|
@@ -199,9 +217,11 @@ $ env NERO_ENV_ALL_OPTIONAL=1 SECRET_KEY_BASE_DUMMY=1 rails asset:precompile
|
|
199
217
|
|
200
218
|
### custom tags
|
201
219
|
|
202
|
-
|
220
|
+
There's three ways to create your own tags.
|
221
|
+
|
222
|
+
For all these methods it's helpful to see the API-docs for [Nero::BaseTag](https://eval.github.io/nero/Nero/BaseTag.html).
|
203
223
|
|
204
|
-
1. a
|
224
|
+
1. **a proc**
|
205
225
|
```ruby
|
206
226
|
Nero.configure do |nero|
|
207
227
|
nero.add_tag("upcase") do |tag|
|
@@ -225,15 +245,16 @@ Three ways to do this:
|
|
225
245
|
tag.args.map(&:upcase)
|
226
246
|
end
|
227
247
|
|
228
|
-
# NOTE though
|
229
|
-
# as it allows for chaining:
|
248
|
+
# NOTE though a tag might just need one argument (ie scalar),
|
249
|
+
# it's helpful to accept a seq as it allows for chaining:
|
230
250
|
# a: !my/inc 4 # scalar suffices
|
231
|
-
# ...but when chaining, it
|
232
|
-
# a: !my/inc [!my/square 2]
|
251
|
+
# ...but when chaining, it needs to be a seq:
|
252
|
+
# a: !my/inc [ !my/square 2 ]
|
233
253
|
end
|
234
254
|
end
|
235
255
|
```
|
236
|
-
|
256
|
+
Blocks are passed instances of [Nero::BaseTag](https://eval.github.io/nero/Nero/BaseTag.html).
|
257
|
+
1. **re-use existing tag-class**
|
237
258
|
You can add an existing tag under a better fitting name this way.
|
238
259
|
Also: some tag-classes have options that allow for simple customizations (like `coerce` below):
|
239
260
|
```ruby
|
@@ -244,7 +265,7 @@ Three ways to do this:
|
|
244
265
|
nero.add_tag("path/project_root", klass: Nero::PathRootTag[containing: '.git'])
|
245
266
|
end
|
246
267
|
```
|
247
|
-
1. custom class
|
268
|
+
1. **custom class**
|
248
269
|
```ruby
|
249
270
|
class RotTag < Nero::BaseTag
|
250
271
|
# Configure:
|
data/lib/nero/railtie.rb
ADDED
data/lib/nero/version.rb
CHANGED
data/lib/nero.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "zeitwerk"
|
4
4
|
loader = Zeitwerk::Loader.for_gem
|
5
|
+
loader.do_not_eager_load("#{__dir__}/nero/railtie.rb")
|
5
6
|
loader.setup
|
6
7
|
|
7
8
|
require "uri"
|
@@ -14,40 +15,93 @@ require "pathname"
|
|
14
15
|
module Nero
|
15
16
|
class Error < StandardError; end
|
16
17
|
|
18
|
+
module DigExt
|
19
|
+
# ⛏️💥 Like `dig`, but raises `ArgumentError` when `path` does not exist.
|
20
|
+
# @example like dig
|
21
|
+
# {a: {b: 2}}.dig!(:a, :b) #=> 2
|
22
|
+
# {a: {b: 2}}.dig!(:a, :c) #=> ArgumentError, path not found [:a, :c] (ArgumentError)
|
23
|
+
# @raise [ArgumentError] when `path` does not exist.
|
24
|
+
# @overload dig!(*path)
|
25
|
+
# @param path nested keys into config
|
26
|
+
def dig!(k0, *k)
|
27
|
+
k.unshift(k0)
|
28
|
+
|
29
|
+
unless paths.include?(k)
|
30
|
+
raise ArgumentError, "path not found #{k}"
|
31
|
+
end
|
32
|
+
dig(*k)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def paths
|
38
|
+
@paths ||= gather_paths(self).to_set
|
39
|
+
end
|
40
|
+
|
41
|
+
def gather_paths(item, acc: [], path: [])
|
42
|
+
acc += [path]
|
43
|
+
|
44
|
+
case item
|
45
|
+
when NilClass
|
46
|
+
[]
|
47
|
+
when Hash
|
48
|
+
item.flat_map { |(k, v)| gather_paths(v, acc: acc, path: path + [k]) }
|
49
|
+
when Array
|
50
|
+
item.each_with_index.flat_map do |item, ix|
|
51
|
+
gather_paths(item, acc: acc, path: path + [ix])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
acc
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Config < Hash
|
60
|
+
include DigExt
|
61
|
+
|
62
|
+
def self.for(v)
|
63
|
+
case v
|
64
|
+
when self then v
|
65
|
+
when Hash then self.[](v)
|
66
|
+
else
|
67
|
+
v
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
17
72
|
module Resolvable
|
18
|
-
def try_resolve(
|
73
|
+
def try_resolve(object)
|
19
74
|
if object.respond_to?(:resolve)
|
20
|
-
object.resolve
|
75
|
+
object.resolve
|
21
76
|
else
|
22
77
|
object
|
23
78
|
end
|
24
79
|
end
|
25
80
|
|
26
|
-
def
|
27
|
-
method(:try_resolve)
|
81
|
+
def deep_resolve(object)
|
82
|
+
Util.deep_transform_values(object, &method(:try_resolve))
|
28
83
|
end
|
29
84
|
|
30
|
-
def
|
31
|
-
Util.deep_transform_values(object, &gen_resolve_tryer(ctx))
|
32
|
-
end
|
33
|
-
|
34
|
-
def resolve_nested!(coder, ctx = {})
|
85
|
+
def resolve_nested!(coder)
|
35
86
|
case coder.type
|
36
87
|
when :seq
|
37
|
-
coder.seq.map!(&
|
88
|
+
coder.seq.map!(&method(:try_resolve))
|
38
89
|
when :map
|
39
|
-
coder.map = deep_resolve(coder.map
|
90
|
+
coder.map = deep_resolve(coder.map)
|
40
91
|
end
|
41
92
|
end
|
42
93
|
end
|
43
94
|
extend Resolvable
|
44
95
|
private_class_method \
|
45
96
|
:deep_resolve,
|
46
|
-
:gen_resolve_tryer,
|
47
97
|
:try_resolve
|
48
98
|
|
49
99
|
class Configuration
|
50
|
-
attr_reader :
|
100
|
+
attr_reader :config_dir
|
101
|
+
|
102
|
+
def tags
|
103
|
+
@tags ||= {}
|
104
|
+
end
|
51
105
|
|
52
106
|
def config_dir=(dir)
|
53
107
|
@config_dir = Pathname(dir).expand_path
|
@@ -56,7 +110,7 @@ module Nero
|
|
56
110
|
def add_tag(name, klass: BaseTag, &block)
|
57
111
|
klass, klass_options = klass
|
58
112
|
|
59
|
-
|
113
|
+
tags[name] = {klass:}.tap do |h|
|
60
114
|
h[:block] = block if block
|
61
115
|
h[:options] = klass_options if klass_options
|
62
116
|
end
|
@@ -67,20 +121,85 @@ module Nero
|
|
67
121
|
@configuration ||= Configuration.new
|
68
122
|
end
|
69
123
|
|
124
|
+
def self.add_tags!
|
125
|
+
configuration.tags.each do |tag_name, tag|
|
126
|
+
YAML.add_tag("!#{tag_name}", tag[:klass])
|
127
|
+
end
|
128
|
+
end
|
129
|
+
private_class_method :add_tags!
|
130
|
+
|
70
131
|
def self.configure
|
71
132
|
yield configuration if block_given?
|
133
|
+
ensure
|
134
|
+
add_tags!
|
72
135
|
end
|
73
136
|
|
137
|
+
# Superclass for all tags.
|
138
|
+
#
|
139
|
+
# Writing your own tag-class would look something like this:
|
140
|
+
#
|
141
|
+
# Wanted usage in YAML:
|
142
|
+
# ```ruby
|
143
|
+
# Nero.load(<<~YAML)
|
144
|
+
# secret: !rot/12 "some message"
|
145
|
+
# other_secret: !rot/13 [ !env [SECRET, some message] ]
|
146
|
+
# YAML
|
147
|
+
# ```
|
148
|
+
#
|
149
|
+
# Required config:
|
150
|
+
# ```ruby
|
151
|
+
# config.add_tag("rot/12", klass: RotTag[n: 12])
|
152
|
+
# config.add_tag("rot/13", klass: RotTag[n: 13]) do |secret|
|
153
|
+
# "#{secret} (try breaking this!)"
|
154
|
+
# end
|
155
|
+
# ```
|
156
|
+
# The class then would look like this:
|
157
|
+
# ```ruby
|
158
|
+
# class RotTag < Nero::BaseTag
|
159
|
+
# attr_reader :n
|
160
|
+
#
|
161
|
+
# # Overriding this method...:
|
162
|
+
# # - restricts options
|
163
|
+
# # ie `RotTag[x: 1]` would raise.
|
164
|
+
# # - sets default values
|
165
|
+
# # - makes options available via getters
|
166
|
+
# # (otherwise available via `options[:n]`).
|
167
|
+
# def init_options(n: 10)
|
168
|
+
# super
|
169
|
+
# @n = n
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# # This is where the magic happens.
|
173
|
+
# # (Accepting any keyword arguments keeps the method fw-compatible).
|
174
|
+
# def resolve(**)
|
175
|
+
# # `args` are the resolved arguments (Array or Hash).
|
176
|
+
# # `config` the config of the tag (containing e.g. the proc).
|
177
|
+
# block = config.fetch(:block, :itself.to_proc)
|
178
|
+
# args.join.tr(chars.join, chars.rotate(n).join).then(&block)
|
179
|
+
# end
|
180
|
+
#
|
181
|
+
# # Just some helper method with all characters that can be rotated.
|
182
|
+
# def chars
|
183
|
+
# %w(a b c) # etc
|
184
|
+
# end
|
185
|
+
# end
|
186
|
+
# ```
|
187
|
+
#
|
74
188
|
class BaseTag
|
75
189
|
include Resolvable
|
76
190
|
|
77
191
|
attr_reader :coder, :options, :ctx
|
78
192
|
|
193
|
+
# Convenience method simplifying {Nero::Configuration#add_tag}:
|
194
|
+
#
|
195
|
+
# ```ruby
|
196
|
+
# config.add_tag("foo", klass: SomeTag[some_option: 1])
|
197
|
+
# ```
|
79
198
|
def self.[](**options)
|
80
199
|
[self, options]
|
81
200
|
end
|
82
201
|
|
83
|
-
# used by YAML
|
202
|
+
# @private used by YAML
|
84
203
|
def init_with(coder)
|
85
204
|
@coder = coder
|
86
205
|
end
|
@@ -104,7 +223,7 @@ module Nero
|
|
104
223
|
|
105
224
|
def args
|
106
225
|
@args ||= begin
|
107
|
-
resolve_nested!(coder
|
226
|
+
resolve_nested!(coder)
|
108
227
|
case coder.type
|
109
228
|
when :map then Util.deep_symbolize_keys(coder.map)
|
110
229
|
else
|
@@ -135,23 +254,28 @@ module Nero
|
|
135
254
|
# When tag-name ends with "?", the env-var is optional.
|
136
255
|
#
|
137
256
|
# Given config:
|
257
|
+
# ```ruby
|
138
258
|
# config.add_tag("env/upcase", klass: Nero::EnvTag[coerce: :upcase])
|
139
259
|
# config.add_tag("env/upcase?", klass: Nero::EnvTag[coerce: :upcase])
|
140
|
-
|
260
|
+
# ```
|
261
|
+
#
|
141
262
|
# Then YAML => result:
|
142
|
-
#
|
143
|
-
# "--- env/upcase MSG
|
144
|
-
# "--- env/upcase
|
263
|
+
# ```ruby
|
264
|
+
# "--- env/upcase [MSG, Hello World]" #=> "HELLO WORLD"
|
265
|
+
# "--- env/upcase MSG" #=> raises when not ENV.has_key? "MSG"
|
266
|
+
# "--- env/upcase? MSG" #=> nil
|
267
|
+
# ```
|
145
268
|
#
|
146
|
-
#
|
147
|
-
# - scalar
|
269
|
+
# YAML-args supported:
|
270
|
+
# - scalar —
|
148
271
|
# name of env-var, e.g. `!env HOME`
|
149
|
-
# - seq
|
272
|
+
# - seq —
|
150
273
|
# name of env-var and fallback, e.g. `!env [HOME, /root]`
|
151
|
-
|
274
|
+
#
|
152
275
|
# Options:
|
153
|
-
# - coerce
|
154
|
-
#
|
276
|
+
# - `coerce` —
|
277
|
+
# symbol or proc to be applied to value of env-var.
|
278
|
+
# when using coerce, the block is ignored.
|
155
279
|
#
|
156
280
|
class EnvTag < BaseTag
|
157
281
|
def resolve(**)
|
@@ -251,7 +375,7 @@ module Nero
|
|
251
375
|
# validate: non-empty coder.seq, only strs, path must exists in ctx[:config]
|
252
376
|
|
253
377
|
path = tag.args.map(&:to_sym)
|
254
|
-
deep_resolve(tag.ctx[:yaml].dig(*path)
|
378
|
+
deep_resolve(tag.ctx[:yaml].dig(*path))
|
255
379
|
end
|
256
380
|
|
257
381
|
config.add_tag("env", klass: EnvTag)
|
@@ -296,22 +420,84 @@ module Nero
|
|
296
420
|
@configuration = nil
|
297
421
|
|
298
422
|
configure do |config|
|
299
|
-
config.config_dir = Pathname.
|
423
|
+
config.config_dir = Pathname.new("config").expand_path
|
300
424
|
end
|
301
425
|
|
302
426
|
add_default_tags!
|
427
|
+
add_tags!
|
303
428
|
end
|
304
429
|
reset_configuration!
|
305
430
|
|
306
|
-
def self.
|
431
|
+
def self.default_yaml_options
|
307
432
|
{
|
308
433
|
permitted_classes: [Symbol] + configuration.tags.values.map { _1[:klass] },
|
309
434
|
aliases: true
|
310
435
|
}
|
311
436
|
end
|
437
|
+
private_class_method :default_yaml_options
|
438
|
+
|
439
|
+
def self.yaml_options(yaml_options)
|
440
|
+
epc = yaml_options.delete(:extra_permitted_classes)
|
441
|
+
default_yaml_options.merge(yaml_options).tap do
|
442
|
+
_1[:permitted_classes].push(*epc)
|
443
|
+
end
|
444
|
+
end
|
312
445
|
private_class_method :yaml_options
|
313
446
|
|
447
|
+
# Like `YAML.load` with extra options.
|
448
|
+
#
|
449
|
+
# @param [Symbol, String] root return the value of this root key.
|
450
|
+
# @param [Boolean] resolve (for debug purposes) not resolving would leave the Nero-tags as-is.
|
451
|
+
# @param [Array<ClassName>] extra_permitted_classes classes that are added
|
452
|
+
# to the default permitted_classes and passed to `YAML.load`.
|
453
|
+
# @param [Hash] yaml_options options passed to `YAML.load`.
|
454
|
+
# @return [Nero::Config (when the data is a Hash)]
|
455
|
+
# @example
|
456
|
+
# Nero.load(<<~YAML, extra_permitted_classes: [Time])
|
457
|
+
# home: !env HOME,
|
458
|
+
# created_at: 2010-02-11 11:02:57
|
459
|
+
# project_root: !path/git_root
|
460
|
+
# YAML
|
461
|
+
# #=> {
|
462
|
+
# # home: "/Users/gert",
|
463
|
+
# # created_at: 2010-02-11 12:02:57 +0100,
|
464
|
+
# # project_root: #<Pathname:/Users/gert/projects/nero>
|
465
|
+
# # }
|
466
|
+
def self.load(yaml, root: nil, resolve: true, **yaml_options)
|
467
|
+
process_yaml(yaml_load(yaml, yaml_options(yaml_options)), root:, resolve:)
|
468
|
+
end
|
469
|
+
|
470
|
+
# Like `YAML.load_file`. See {load} for options.
|
471
|
+
# @return [Nero::Config (when the YAML-data is a Hash)]
|
472
|
+
def self.load_file(file, root: nil, resolve: true, **yaml_options)
|
473
|
+
config_file = (file.is_a?(Pathname) ? file : Pathname.new(file)).expand_path
|
474
|
+
process_yaml(yaml_load_file(config_file, yaml_options(yaml_options)), root:, config_file:, resolve:)
|
475
|
+
end
|
476
|
+
|
477
|
+
# Convenience wrapper for {load_file} that works like `Rails.application.config_for`.
|
478
|
+
# @see https://api.rubyonrails.org/classes/Rails/Application.html#method-i-config_for Rails' config_for documentation
|
479
|
+
#
|
480
|
+
# The file-argument is expanded like so `(configuration.config_dir / "#{file}.yml").expand_path`.
|
481
|
+
#
|
482
|
+
# @param [Symbol, String, Pathname] file `Symbol` or `String` are expanded as shown above. A `Pathname` is used as-is.
|
483
|
+
# @param [Symbol, String] env return the value of this root key.
|
484
|
+
# @param [Symbol, String] root return the value of this root key.
|
485
|
+
# @param [Boolean] resolve (for debug purposes) not resolving would leave the Nero-tags as-is.
|
486
|
+
# @param [Array<ClassName>] extra_permitted_classes classes that are added
|
487
|
+
# to the default permitted_classes and passed to `YAML.load`.
|
488
|
+
# @param [Hash] yaml_options options passed to `YAML.load_file`.
|
489
|
+
# @return [Nero::Config (when the data is a Hash)]
|
490
|
+
# @example
|
491
|
+
# Nero.config_for(:app, env: Rails.env) #=> {...}
|
492
|
+
def self.config_for(file, root: nil, env: nil, **yaml_options)
|
493
|
+
root ||= env
|
494
|
+
|
495
|
+
load_file(resolve_file(file), root:, **yaml_options)
|
496
|
+
end
|
497
|
+
|
498
|
+
# @deprecated Use `load_file` or `config_for` instead.
|
314
499
|
def self.load_config(file, root: nil, env: nil, resolve: true)
|
500
|
+
warn "[DEPRECATION] `load_config` is deprecated. Use `load_file` or `config_for` instead."
|
315
501
|
root ||= env
|
316
502
|
add_tags!
|
317
503
|
|
@@ -327,20 +513,12 @@ module Nero
|
|
327
513
|
def self.resolve_file(file)
|
328
514
|
case file
|
329
515
|
when Pathname then file
|
330
|
-
# TODO expand full path
|
331
516
|
else
|
332
|
-
configuration.config_dir / "#{file}.yml"
|
517
|
+
(configuration.config_dir / "#{file}.yml").expand_path
|
333
518
|
end
|
334
519
|
end
|
335
520
|
private_class_method :resolve_file
|
336
521
|
|
337
|
-
def self.load(raw, root: nil, env: nil, resolve: true)
|
338
|
-
root ||= env
|
339
|
-
add_tags!
|
340
|
-
|
341
|
-
process_yaml(yaml_load(raw, yaml_options), root:, resolve:)
|
342
|
-
end
|
343
|
-
|
344
522
|
def self.process_yaml(yaml, root: nil, resolve: true, config_file: nil)
|
345
523
|
config_file ||= (Pathname.pwd / __FILE__)
|
346
524
|
|
@@ -352,8 +530,7 @@ module Nero
|
|
352
530
|
|
353
531
|
return unresolved unless resolve
|
354
532
|
|
355
|
-
|
356
|
-
deep_resolve(unresolved, **{})
|
533
|
+
Config.for(deep_resolve(unresolved))
|
357
534
|
end
|
358
535
|
private_class_method :process_yaml
|
359
536
|
|
@@ -383,13 +560,6 @@ module Nero
|
|
383
560
|
end
|
384
561
|
private_class_method :yaml_load
|
385
562
|
|
386
|
-
def self.add_tags!
|
387
|
-
configuration.tags.each do |tag_name, tag|
|
388
|
-
YAML.add_tag("!#{tag_name}", tag[:klass])
|
389
|
-
end
|
390
|
-
end
|
391
|
-
private_class_method :add_tags!
|
392
|
-
|
393
563
|
def self.collect_tags(obj)
|
394
564
|
case obj
|
395
565
|
when Hash
|
@@ -413,4 +583,6 @@ module Nero
|
|
413
583
|
private_class_method :collect_tags
|
414
584
|
end
|
415
585
|
|
586
|
+
require "nero/railtie" if defined?(Rails::Railtie)
|
587
|
+
|
416
588
|
loader.eager_load if ENV.key?("CI")
|
data/rakelib/yard.rake
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "yard"
|
2
|
+
|
3
|
+
YARD::Rake::YardocTask.new(:docs) do |t|
|
4
|
+
# Options defined in `.yardopts` are read first, then merged with
|
5
|
+
# options defined here.
|
6
|
+
#
|
7
|
+
# It's recommended to define options in `.yardopts` instead of here,
|
8
|
+
# as `.yardopts` can be read by external YARD tools, like the
|
9
|
+
# hot-reload YARD server `yard server --reload`.
|
10
|
+
|
11
|
+
# t.options += ['--title', "Something custom"]
|
12
|
+
end
|
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gert Goet
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-10 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: zeitwerk
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- ".envrc"
|
54
54
|
- ".rspec"
|
55
55
|
- ".standard.yml"
|
56
|
+
- ".yardopts"
|
56
57
|
- Appraisals
|
57
58
|
- CHANGELOG.md
|
58
59
|
- LICENSE.txt
|
@@ -61,9 +62,11 @@ files:
|
|
61
62
|
- gemfiles/psych_3.gemfile
|
62
63
|
- gemfiles/psych_4.gemfile
|
63
64
|
- lib/nero.rb
|
65
|
+
- lib/nero/railtie.rb
|
64
66
|
- lib/nero/util.rb
|
65
67
|
- lib/nero/version.rb
|
66
68
|
- rakelib/gem.rake
|
69
|
+
- rakelib/yard.rake
|
67
70
|
- sig/nero.rbs
|
68
71
|
homepage: https://github.com/eval/nero
|
69
72
|
licenses:
|