nero 0.7.0.rc5 → 0.7.0.rc7
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 +4 -0
- data/README.md +10 -3
- data/UPGRADING.md +17 -2
- data/lib/nero/format_tag.rb +12 -1
- data/lib/nero/parser.rb +10 -6
- data/lib/nero/rails/credentials_tag.rb +8 -1
- data/lib/nero/rails/duration_tag.rb +2 -2
- data/lib/nero/rails/string_inquirer_tag.rb +1 -1
- data/lib/nero/root_path_tag.rb +8 -2
- data/lib/nero/version.rb +1 -1
- data/lib/nero/visitor.rb +15 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23aa3b665e8b5406843b40b42eb7311227c0c97a48aca5f3e05db0059ec30db0
|
|
4
|
+
data.tar.gz: 10ad7cbcdafd704fab53d13b89ed623df9e7f85197ce8d8e3f9ef4bdb02a71e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6fbb16f88bd7b2294002583851ed926b9765a0908ccb98fc0b0935b5c9c6aa6971cf6e95d2876cb8dc7e13f2b65582170c92fa8cc5769bf7e02095ea854ed530
|
|
7
|
+
data.tar.gz: 9c710ee338dec046f327862ec456d891f20daca292c14d61cc6e86216d76535f6ed447a2b3522fcd79b38d4fdc454639f87463015e93327e83ea36edc4206e64
|
data/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,7 @@ Total refactor and so quite some breaking changes. See [UPGRADING.md](UPGRADING.
|
|
|
13
13
|
## Breaking Changes
|
|
14
14
|
|
|
15
15
|
- **`Nero.load` / `Nero.load_file` now return string keys**, like `YAML.load` (0.6: symbol keys). `Nero.load(...)[:foo]` silently gives `nil`: use `symbolize_names: true`, or `Nero.config_for` (symbol keys, like Rails). They raise `Nero::ParseError` with all errors at once; `Nero::Parser#parse`/`#parse_file` return a `Result` instead.
|
|
16
|
+
- **Unknown tags are a parse error.** A tag Nero doesn't know used to pass through silently: Psych treats an unknown local tag as no tag at all, so a typo (`!env/intger PORT` → `"PORT"`), a custom tag that isn't registered (`!str/upcsae foo` → `"foo"`) or Psych's shorthands (`!ruby/sym`, `!str:Foo`, `!binary`) gave a plain value and no error. Now every `!tag` must be built in or registered; YAML core tags (`!!str`, `!!binary`, `!!set`, ...) work as before. The error suggests similar names: `unknown tag !env/intger (maybe you meant: !env/integer, !env/int)`.
|
|
16
17
|
- Nero.configure / Nero.configuration removed — custom tags are now registered via a block passed to parse/parse_file/config_for:
|
|
17
18
|
```ruby
|
|
18
19
|
# Before
|
|
@@ -30,6 +31,7 @@ Total refactor and so quite some breaking changes. See [UPGRADING.md](UPGRADING.
|
|
|
30
31
|
- !uri and !path tags removed — !uri is gone entirely; !path is no longer a built-in.
|
|
31
32
|
- `Nero::PathRootTag` renamed to `Nero::RootPathTag` with a new constructor API.
|
|
32
33
|
- `!path/rails_root` is only available with Rails (`nero/rails`, loaded by the Railtie); `!path/git_root` stays built in.
|
|
34
|
+
- `!path/git_root` / `!path/rails_root` stay below the root: a path leading outside it (`!path/rails_root ..`, `[config, ../..]`) is a parse error. `..` within the root is fine, and the result is cleaned (`config/../lib` → `<root>/lib`). For a path outside the project, use `!env/path` or a custom tag.
|
|
33
35
|
- `!secret_key_base` (0.7.0 release candidates only) removed. Read it in Ruby instead (`Rails.application.secret_key_base`, or better `Rails.application.key_generator.generate_key("purpose")`), or register it as a one-line custom tag.
|
|
34
36
|
- !str/format changed — now also available as !format; the map form (fmt: key) is replaced by a sequence with named-parameter hashes: !format ["http://%<host>s", host: !ref host].
|
|
35
37
|
- load_config removed (was already deprecated).
|
|
@@ -62,7 +64,9 @@ Total refactor and so quite some breaking changes. See [UPGRADING.md](UPGRADING.
|
|
|
62
64
|
- Tag arguments: a bare tag (`a: !my/tag`) passes no args (`[]`, was `[nil]`), and a quoted scalar stays a string (`!my/tag "123"` → `["123"]`, `!my/tag ""` → `[""]`; was `[123]` and `[nil]`).
|
|
63
65
|
- `!env/integer` parses decimal only: `08` is `8` instead of an error (`Integer("08")` reads it as octal).
|
|
64
66
|
- `!env` (and the coercing variants) without a variable name is a parse error instead of looking up `nil`.
|
|
67
|
+
- `!format` with a mapping (the 0.6 `fmt:` form), without a template, or with a non-string template is a parse error instead of a `TypeError`; so is a format argument of the wrong type (`%d` with `nil`). `!credentials` with a mapping, no key, or a non-string key is a parse error instead of a `NoMethodError`.
|
|
65
68
|
- `!ref [a, c]` resolved silently to `a` during the refactor; it resolves to `a.c` again.
|
|
69
|
+
- An anchor nested inside another root (`development: {proxies: &proxies [!ip ...]}`, aliased as `*proxies` under `production:`) lost its tags when loading `production`: the alias gave plain strings, silently. Only an anchor directly on a root (`shared: &shared`) was kept. Aliased nodes now keep their tags at any depth.
|
|
66
70
|
- Rails: `Nero.config_for(:app)` reads `Rails.root/config/app.yml` again, whatever the current directory (as 0.6 did via `config_dir`); without Rails it's `./config`. `Nero.config_dir` is the method to override.
|
|
67
71
|
- Rails: credentials are looked up when a `!credentials` tag resolves, so parsing works before (or without) a Rails application; a `false` credential is returned instead of reported missing; a block passed to `parse`/`config_for` runs once.
|
|
68
72
|
|
data/README.md
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
<img src="assets/banner.svg" alt="Nero: declarative YAML-tags" width="100%">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://badge.fury.io/rb/nero"><img src="https://badge.fury.io/rb/nero.svg" alt="Gem Version"></a>
|
|
7
|
+
<a href="https://eval.github.io/nero/"><img src="https://img.shields.io/badge/docs-API-ff9a3c" alt="API docs"></a>
|
|
8
|
+
<a href="https://rubygems.org/gems/nero"><img src="https://img.shields.io/gem/dt/nero" alt="Downloads"></a>
|
|
9
|
+
<a href="LICENSE.txt"><img src="https://img.shields.io/github/license/eval/nero" alt="License: MIT"></a>
|
|
10
|
+
</p>
|
|
6
11
|
|
|
7
12
|
Nero is a RubyGem that offers declarative YAML-tags to simplify config files, e.g. for requiring and coercion of env-vars.
|
|
8
13
|
Additionally, it allows you to create your own.
|
|
@@ -103,7 +108,7 @@ Nero's entry points behave like their namesakes:
|
|
|
103
108
|
| `Nero.load(yaml)`, `Nero.load_file(path)` | `YAML.load`, `YAML.load_file` | strings (`symbolize_names: true` for symbols) | `Symbol` |
|
|
104
109
|
| `Nero.config_for(:app, env:)` | `Rails.application.config_for` | symbols | `Symbol`, `Date`, `Time` |
|
|
105
110
|
|
|
106
|
-
Differences from `YAML.load`: aliases (anchors) are allowed,
|
|
111
|
+
Differences from `YAML.load`: aliases (anchors) are allowed, all problems are reported at once in a `Nero::ParseError` (see `#errors`), and a tag Nero doesn't know is an error instead of being ignored (`unknown tag !env/intger (maybe you meant: !env/integer, !env/int)`). Allow more classes with `permitted_classes:` (this replaces the default list, as in Psych). Arbitrary objects (`!ruby/object:...`) are refused by default, also in `config_for` (Rails' `config_for` uses `YAML.unsafe_load`).
|
|
107
112
|
|
|
108
113
|
```ruby
|
|
109
114
|
# config/app.yml, relative to the current directory (in Rails: Rails.root/config)
|
|
@@ -178,7 +183,7 @@ Deprecated usage (e.g. `!ref [a, b]`) still works and prints a warning on stderr
|
|
|
178
183
|
# segments are joined, so other tags can provide them:
|
|
179
184
|
uploads: !path/git_root [storage, !env [TENANT, default]]
|
|
180
185
|
```
|
|
181
|
-
Segments are relative to the root: a missing (`nil`) or absolute segment is an error.
|
|
186
|
+
Segments are relative to the root: a missing (`nil`) or absolute segment is an error, and so is a path leading outside the root (`..`). The result is cleaned: `config/../lib` → `<root>/lib`.
|
|
182
187
|
With Rails there's also `!path/rails_root` (see [Rails](#rails)).
|
|
183
188
|
- `!format` (or `!str/format`)
|
|
184
189
|
Using Ruby's [format specifications](https://docs.ruby-lang.org/en/master/language/format_specifications_rdoc.html):
|
|
@@ -276,6 +281,8 @@ config.x.app = Nero.config_for(:app)
|
|
|
276
281
|
|
|
277
282
|
Pass a block to `Nero.load`, `Nero.load_file`, `Nero.config_for` or `Nero::Parser.new` and register tags with `add_tag(name, tag)`. Built-in tags with the same name are replaced.
|
|
278
283
|
|
|
284
|
+
Any other `!tag` is a parse error (`unknown tag !str/fromat`): a typo or a tag you forgot to register never silently passes through as a plain value. YAML's own `!!str`, `!!binary` etc. are fine; Psych's `!ruby/...` shorthands are not supported.
|
|
285
|
+
|
|
279
286
|
A tag is anything that responds to `resolve(args, context:)`:
|
|
280
287
|
- `args` is what follows the tag in YAML: an Array for a scalar or sequence, a Hash for a mapping. Nested tags (`!env` etc.) are already resolved.
|
|
281
288
|
- `context` gives access to `environ` (the env-vars), `dir` (the folder of the yaml-config) and `add_error(message)`.
|
data/UPGRADING.md
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
0.7 is a rewrite. Most changes fail loudly (a `NoMethodError` or a `Nero::ParseError` at
|
|
4
4
|
boot), but a few change values **silently**. Those come first.
|
|
5
5
|
|
|
6
|
+
One thing that was silent is now loud: a tag Nero doesn't know is a parse error (see
|
|
7
|
+
[Custom tags](#7-custom-tags)). In 0.6 a typo or an unregistered tag gave a plain value.
|
|
8
|
+
|
|
6
9
|
Deprecated usage keeps working until 0.8 and prints a warning on stderr:
|
|
7
10
|
|
|
8
11
|
```
|
|
@@ -20,7 +23,7 @@ Run your app or test suite once after upgrading and fix every warning.
|
|
|
20
23
|
- [ ] [Configuration](#4-neroconfigure-is-gone): no more `Nero.configure`
|
|
21
24
|
- [ ] [`load_config`](#5-load_config-is-gone) → `config_for`
|
|
22
25
|
- [ ] [Tags](#6-tags): `!ref`, `!str/format`, optional env tags, `!path`, `!uri`
|
|
23
|
-
- [ ] [Custom tags](#7-custom-tags): new API
|
|
26
|
+
- [ ] [Custom tags](#7-custom-tags): new API; every `!tag` must be built in or registered
|
|
24
27
|
- [ ] [Loading Ruby objects](#8-loading-ruby-objects): `extra_permitted_classes:` → `permitted_classes:`
|
|
25
28
|
- [ ] [`NERO_ENV_ALL_OPTIONAL`](#9-nero_env_all_optional) → `NERO_ALL_OPTIONAL`
|
|
26
29
|
|
|
@@ -157,13 +160,21 @@ Nero.config_for(:app, env: Rails.env) # env: defaults to Rails.env in a Rails
|
|
|
157
160
|
| `!str/format {fmt: "%<x>s", x: 1}` | `!format ["%<x>s", x: 1]` | The map form with `fmt:` is gone. Positional args (`!format ["%s/x", !ref url]`) still work. `!str/format` stays as an alias. |
|
|
158
161
|
| `!path [a, b]` | `!path/git_root [a, b]`, `!env/path VAR` | `!path` is gone: it built a path relative to the current directory. Use a root-relative path, or a path from the environment. |
|
|
159
162
|
| `!uri [smtps://, !env CREDS, @host]` | `!format ["smtps://%s@host", !env CREDS]` | `!uri` is gone: it concatenated and parsed without escaping. Build the string, and call `URI()` in Ruby if you need an object. |
|
|
160
|
-
| `!path/rails_root` | `!path/rails_root` | Now only available in a Rails app. `!path/git_root` works everywhere. |
|
|
163
|
+
| `!path/rails_root` | `!path/rails_root` | Now only available in a Rails app. `!path/git_root` works everywhere. A path leading outside the root (`!path/rails_root ../shared`) is now an error: use `!env/path` for such a path. |
|
|
161
164
|
|
|
162
165
|
New: `!env/int`, `!env/boolean` (aliases), `!env/path` and `!env?/path`, `!format`; with
|
|
163
166
|
Rails also `!credentials`, `!duration` and `!str/inquirer`.
|
|
164
167
|
|
|
165
168
|
## 7. Custom tags
|
|
166
169
|
|
|
170
|
+
**Unregistered tags are errors.** 0.6 passed a tag it didn't know on to Psych, which
|
|
171
|
+
treats an unknown local tag as no tag: `!upcsae foo` quietly gave `"foo"`,
|
|
172
|
+
`!secret foo` the string `"foo"`. 0.7 reports `unknown tag !upcsae` instead, with a
|
|
173
|
+
suggestion when a built-in name is close (`unknown tag !env/intger (maybe you meant:
|
|
174
|
+
!env/integer, !env/int)`). So a custom tag you forget to register, or register on one code
|
|
175
|
+
path but not another (an initializer that reloads the config without the block), now fails
|
|
176
|
+
at boot instead of changing values.
|
|
177
|
+
|
|
167
178
|
Tags no longer read `tag.args`/`coder`/`ctx`. A tag is anything that responds to
|
|
168
179
|
`resolve(args, context:)`.
|
|
169
180
|
|
|
@@ -239,6 +250,10 @@ Nero.load(yaml, permitted_classes: %w[Symbol Date])
|
|
|
239
250
|
|
|
240
251
|
Aliases (`&anchor`/`*alias`, `<<:` merge keys) work as before.
|
|
241
252
|
|
|
253
|
+
Psych's shorthand tags (`!ruby/sym`, `!ruby/range`, `!ruby/regexp`, `!str:Foo`, `!seq:Foo`,
|
|
254
|
+
`!binary`, `!float`, `!omap`, `!set`) are unknown tags in 0.7. Write symbols as `:foo`, and
|
|
255
|
+
use the YAML core form for the rest: `!!binary`, `!!float`, `!!omap`, `!!set`.
|
|
256
|
+
|
|
242
257
|
## 9. `NERO_ENV_ALL_OPTIONAL`
|
|
243
258
|
|
|
244
259
|
Renamed to `NERO_ALL_OPTIONAL`, because it now also makes Rails `!credentials` optional. The
|
data/lib/nero/format_tag.rb
CHANGED
|
@@ -3,13 +3,24 @@
|
|
|
3
3
|
module Nero
|
|
4
4
|
class FormatTag < BaseTag
|
|
5
5
|
def resolve(args, context:)
|
|
6
|
+
if args.is_a?(Hash)
|
|
7
|
+
context.add_error("!format takes a sequence [template, args...], got a mapping " \
|
|
8
|
+
"(the 0.6 map form with fmt: is gone)")
|
|
9
|
+
return
|
|
10
|
+
end
|
|
11
|
+
|
|
6
12
|
template, *fmt_args = args
|
|
13
|
+
unless template.is_a?(String)
|
|
14
|
+
context.add_error("!format needs a string template as first item, got #{template.inspect}")
|
|
15
|
+
return
|
|
16
|
+
end
|
|
17
|
+
|
|
7
18
|
if fmt_args.any? && fmt_args.all?(Hash)
|
|
8
19
|
fmt_args = [fmt_args.reduce({}, :merge).transform_keys(&:to_sym)]
|
|
9
20
|
end
|
|
10
21
|
|
|
11
22
|
format(template, *fmt_args)
|
|
12
|
-
rescue KeyError, ArgumentError => e
|
|
23
|
+
rescue KeyError, ArgumentError, TypeError => e
|
|
13
24
|
context.add_error("format error: #{e.message}")
|
|
14
25
|
nil
|
|
15
26
|
end
|
data/lib/nero/parser.rb
CHANGED
|
@@ -140,9 +140,8 @@ module Nero
|
|
|
140
140
|
|
|
141
141
|
mapping.children.each_slice(2) do |key_node, val_node|
|
|
142
142
|
next if key_node.value == @root
|
|
143
|
-
next if used_anchors.include?(val_node.anchor)
|
|
144
143
|
|
|
145
|
-
strip_custom_tags(val_node)
|
|
144
|
+
strip_custom_tags(val_node, keep: used_anchors)
|
|
146
145
|
end
|
|
147
146
|
end
|
|
148
147
|
|
|
@@ -155,13 +154,18 @@ module Nero
|
|
|
155
154
|
result
|
|
156
155
|
end
|
|
157
156
|
|
|
158
|
-
|
|
157
|
+
# Clears Nero tags below an inactive root, so e.g. `!env SECRET` under `production:` doesn't
|
|
158
|
+
# error when loading `development`. A node the active root aliases (`&anchor`, at any
|
|
159
|
+
# depth) keeps its tags: the alias needs them resolved.
|
|
160
|
+
def strip_custom_tags(node, keep:)
|
|
161
|
+
return if node.respond_to?(:anchor) && keep.include?(node.anchor)
|
|
162
|
+
|
|
159
163
|
case node
|
|
160
164
|
when ::Psych::Nodes::Scalar, ::Psych::Nodes::Sequence, ::Psych::Nodes::Mapping
|
|
161
165
|
node.tag = nil if node.tag&.start_with?("!")
|
|
162
166
|
end
|
|
163
167
|
return unless node.respond_to?(:children) && node.children
|
|
164
|
-
node.children.each { |child| strip_custom_tags(child) }
|
|
168
|
+
node.children.each { |child| strip_custom_tags(child, keep:) }
|
|
165
169
|
end
|
|
166
170
|
|
|
167
171
|
def contains_ref?(value)
|
|
@@ -179,12 +183,12 @@ module Nero
|
|
|
179
183
|
key = value.path.join(".")
|
|
180
184
|
if visited.include?(key)
|
|
181
185
|
ctx.add_error("circular reference: #{key}")
|
|
182
|
-
return
|
|
186
|
+
return
|
|
183
187
|
end
|
|
184
188
|
target = value.path.reduce(root) { |h, k| h.is_a?(Hash) ? h[key(k)] : nil }
|
|
185
189
|
if target.nil?
|
|
186
190
|
ctx.add_error("unknown ref #{key}")
|
|
187
|
-
return
|
|
191
|
+
return
|
|
188
192
|
end
|
|
189
193
|
resolve_refs(target, root, ctx, visited | [key])
|
|
190
194
|
when Deferred
|
|
@@ -14,10 +14,17 @@ module Nero
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def resolve(args, context:)
|
|
17
|
+
valid = args.is_a?(Array) && args.any? && args.all? { _1.is_a?(String) || _1.is_a?(Symbol) }
|
|
18
|
+
unless valid
|
|
19
|
+
context.add_error("!credentials expects a key or a sequence of keys " \
|
|
20
|
+
"(!credentials [aws, secret]), got #{args.inspect}")
|
|
21
|
+
return
|
|
22
|
+
end
|
|
23
|
+
|
|
17
24
|
keys = args.map(&:to_sym)
|
|
18
25
|
value = credentials.dig(*keys)
|
|
19
26
|
return value unless value.nil?
|
|
20
|
-
return
|
|
27
|
+
return if context.all_optional?
|
|
21
28
|
|
|
22
29
|
context.add_error("credential #{args.join(".")} not found")
|
|
23
30
|
nil
|
|
@@ -11,12 +11,12 @@ module Nero
|
|
|
11
11
|
|
|
12
12
|
unless amount.is_a?(Numeric)
|
|
13
13
|
context.add_error("duration requires a numeric amount, got #{amount.inspect}")
|
|
14
|
-
return
|
|
14
|
+
return
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
unless UNITS.include?(unit)
|
|
18
18
|
context.add_error("duration unknown unit #{unit.inspect}, expected one of: #{UNITS.join(", ")}")
|
|
19
|
-
return
|
|
19
|
+
return
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
amount.public_send(unit)
|
data/lib/nero/root_path_tag.rb
CHANGED
|
@@ -9,7 +9,9 @@ module Nero
|
|
|
9
9
|
# up: !path/git_root [storage, !env TENANT] # segments, joined
|
|
10
10
|
#
|
|
11
11
|
# Segments are strings or numbers. A nil segment (e.g. a missing `!env?`), an absolute
|
|
12
|
-
# segment or a mapping is an error. The
|
|
12
|
+
# segment, a segment leading outside the root (`..`) or a mapping is an error. The
|
|
13
|
+
# result is cleaned (`config/../lib` → `lib`). The root must exist, the resulting path
|
|
14
|
+
# needn't.
|
|
13
15
|
class RootPathTag < BaseTag
|
|
14
16
|
def initialize(containing:)
|
|
15
17
|
@containing = containing
|
|
@@ -22,7 +24,7 @@ module Nero
|
|
|
22
24
|
segments = Array(args).map(&:to_s).reject(&:empty?)
|
|
23
25
|
root = find_root(context) or return
|
|
24
26
|
|
|
25
|
-
segments.empty? ? root : root.join(*segments)
|
|
27
|
+
segments.empty? ? root : root.join(*segments).cleanpath
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
private
|
|
@@ -30,12 +32,16 @@ module Nero
|
|
|
30
32
|
def invalid_args(args)
|
|
31
33
|
return "expected a path or a sequence of path segments, got a mapping" if args.is_a?(Hash)
|
|
32
34
|
|
|
35
|
+
below_root = Pathname.new(".")
|
|
33
36
|
Array(args).each.with_index(1) do |segment, i|
|
|
34
37
|
case segment
|
|
35
38
|
when nil
|
|
36
39
|
return "segment #{i} is nil (use a fallback, e.g. !env [VAR, default])"
|
|
37
40
|
when String, Numeric
|
|
38
41
|
return "segment #{i} (#{segment.inspect}) is absolute; segments are relative to the root" if File.absolute_path?(segment.to_s)
|
|
42
|
+
|
|
43
|
+
below_root = (below_root + segment.to_s).cleanpath
|
|
44
|
+
return "segment #{i} (#{segment.inspect}) leads outside the root" if below_root.each_filename.first == ".."
|
|
39
45
|
else
|
|
40
46
|
return "segment #{i} must be a string, got #{segment.class}"
|
|
41
47
|
end
|
data/lib/nero/version.rb
CHANGED
data/lib/nero/visitor.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "did_you_mean"
|
|
4
|
+
|
|
3
5
|
module Nero
|
|
4
6
|
class Visitor < ::Psych::Visitors::ToRuby
|
|
5
7
|
# Like YAML.load (safe_load): only `permitted_classes` (class names or classes) can be
|
|
@@ -23,7 +25,7 @@ module Nero
|
|
|
23
25
|
when ::Psych::Nodes::Scalar::SINGLE_QUOTED, ::Psych::Nodes::Scalar::DOUBLE_QUOTED then [o.value]
|
|
24
26
|
else o.value.empty? ? [] : [super]
|
|
25
27
|
end
|
|
26
|
-
handler.resolve(args, context: @nero_ctx)
|
|
28
|
+
register(o, handler.resolve(args, context: @nero_ctx))
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def visit_Psych_Nodes_Sequence(o)
|
|
@@ -32,7 +34,7 @@ module Nero
|
|
|
32
34
|
|
|
33
35
|
o.tag = nil
|
|
34
36
|
args = super
|
|
35
|
-
contains_ref?(args) ? Deferred.new(handler, args) : handler.resolve(args, context: @nero_ctx)
|
|
37
|
+
register(o, contains_ref?(args) ? Deferred.new(handler, args) : handler.resolve(args, context: @nero_ctx))
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def visit_Psych_Nodes_Mapping(o)
|
|
@@ -41,14 +43,22 @@ module Nero
|
|
|
41
43
|
|
|
42
44
|
o.tag = nil
|
|
43
45
|
args = super
|
|
44
|
-
contains_ref?(args) ? Deferred.new(handler, args) : handler.resolve(args, context: @nero_ctx)
|
|
46
|
+
register(o, contains_ref?(args) ? Deferred.new(handler, args) : handler.resolve(args, context: @nero_ctx))
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
private
|
|
48
50
|
|
|
49
51
|
def find_nero_tag(tag)
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
+
return unless tag&.start_with?("!") # filter out untagged and core tags (e.g. !!str that arrive as tag:yaml.org,2002:str
|
|
53
|
+
tag_name = tag[1..]
|
|
54
|
+
|
|
55
|
+
@nero_tags.fetch(tag_name) do
|
|
56
|
+
dictionary = @nero_tags.reject { |_, t| t.respond_to?(:deprecated?) && t.deprecated? }.keys
|
|
57
|
+
suggestions = DidYouMean::SpellChecker.new(dictionary:).correct(tag_name)
|
|
58
|
+
hint = suggestions.empty? ? "" : " (maybe you meant: #{suggestions.map { "!#{_1}" }.join(", ")})"
|
|
59
|
+
@nero_ctx.add_error("unknown tag #{tag}#{hint}")
|
|
60
|
+
nil
|
|
61
|
+
end
|
|
52
62
|
end
|
|
53
63
|
|
|
54
64
|
def contains_ref?(value)
|