nero 0.7.0.rc6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62ecb94e14c94b7c1b29ee0bb129d97be5ecb39cad34c7493e778405ea8b9f04
4
- data.tar.gz: 5f838bc003bbde162f560931afefbd3283fc9c61cdf2bd086396f1434eb92178
3
+ metadata.gz: 23aa3b665e8b5406843b40b42eb7311227c0c97a48aca5f3e05db0059ec30db0
4
+ data.tar.gz: 10ad7cbcdafd704fab53d13b89ed623df9e7f85197ce8d8e3f9ef4bdb02a71e6
5
5
  SHA512:
6
- metadata.gz: 37f2c53be5adadb1c14d6634c98d1b249f6df104b02813332761057c2ef90ce2f1016730bafef0558d15539f728dba586676a84508aeee5763d9230c19a47557
7
- data.tar.gz: 8b9d702e980eaa58dabd81b943fc0ea31f69ff5ceafd90d08228109f7ed49212305b565dd46ab525debe072506c2dd609bc2e2b946c157df46b167051ab49470
6
+ metadata.gz: 6fbb16f88bd7b2294002583851ed926b9765a0908ccb98fc0b0935b5c9c6aa6971cf6e95d2876cb8dc7e13f2b65582170c92fa8cc5769bf7e02095ea854ed530
7
+ data.tar.gz: 9c710ee338dec046f327862ec456d891f20daca292c14d61cc6e86216d76535f6ed447a2b3522fcd79b38d4fdc454639f87463015e93327e83ea36edc4206e64
data/CHANGELOG.md CHANGED
@@ -64,7 +64,9 @@ Total refactor and so quite some breaking changes. See [UPGRADING.md](UPGRADING.
64
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]`).
65
65
  - `!env/integer` parses decimal only: `08` is `8` instead of an error (`Integer("08")` reads it as octal).
66
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`.
67
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.
68
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.
69
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.
70
72
 
@@ -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
- def strip_custom_tags(node)
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)
@@ -14,6 +14,13 @@ 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?
data/lib/nero/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  module Nero
4
4
  # NOTE this is written upon release via:
5
5
  # $ rake gem:build[version=0.3.0]
6
- VERSION = "0.7.0.rc6"
6
+ VERSION = "0.7.0.rc7"
7
7
  end
data/lib/nero/visitor.rb CHANGED
@@ -25,7 +25,7 @@ module Nero
25
25
  when ::Psych::Nodes::Scalar::SINGLE_QUOTED, ::Psych::Nodes::Scalar::DOUBLE_QUOTED then [o.value]
26
26
  else o.value.empty? ? [] : [super]
27
27
  end
28
- handler.resolve(args, context: @nero_ctx)
28
+ register(o, handler.resolve(args, context: @nero_ctx))
29
29
  end
30
30
 
31
31
  def visit_Psych_Nodes_Sequence(o)
@@ -34,7 +34,7 @@ module Nero
34
34
 
35
35
  o.tag = nil
36
36
  args = super
37
- 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))
38
38
  end
39
39
 
40
40
  def visit_Psych_Nodes_Mapping(o)
@@ -43,7 +43,7 @@ module Nero
43
43
 
44
44
  o.tag = nil
45
45
  args = super
46
- 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))
47
47
  end
48
48
 
49
49
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.rc6
4
+ version: 0.7.0.rc7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Goet