nero 0.7.0.rc2 → 0.7.0.rc3
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/.irbrc +4 -0
- data/CHANGELOG.md +52 -5
- data/README.md +199 -137
- data/UPGRADING.md +255 -0
- data/_irbrc.example +4 -0
- data/lib/nero/context.rb +17 -3
- data/lib/nero/env_tag.rb +19 -5
- data/lib/nero/format_tag.rb +6 -5
- data/lib/nero/ip_tag.rb +31 -0
- data/lib/nero/parser.rb +84 -21
- data/lib/nero/rails/credentials_tag.rb +9 -6
- data/lib/nero/rails.rb +11 -5
- data/lib/nero/ref.rb +2 -1
- data/lib/nero/ref_tag.rb +6 -1
- data/lib/nero/result.rb +4 -2
- data/lib/nero/root_path_tag.rb +42 -6
- data/lib/nero/version.rb +1 -1
- data/lib/nero/visitor.rb +12 -3
- data/lib/nero.rb +45 -8
- data/mise.toml +9 -0
- data/tmp/.keep +0 -0
- metadata +25 -26
- data/Appraisals +0 -7
- data/gemfiles/psych_3.gemfile +0 -10
- data/gemfiles/psych_4.gemfile +0 -10
data/lib/nero/root_path_tag.rb
CHANGED
|
@@ -1,26 +1,62 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Nero
|
|
4
|
+
# A Pathname below the nearest ancestor directory (of the YAML file) that contains
|
|
5
|
+
# `containing`, e.g. `.git` for `!path/git_root`.
|
|
6
|
+
#
|
|
7
|
+
# root: !path/git_root # the root itself
|
|
8
|
+
# app: !path/git_root config/app.yml # one relative path
|
|
9
|
+
# up: !path/git_root [storage, !env TENANT] # segments, joined
|
|
10
|
+
#
|
|
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 root must exist, the resulting path needn't.
|
|
4
13
|
class RootPathTag < BaseTag
|
|
5
14
|
def initialize(containing:)
|
|
6
15
|
@containing = containing
|
|
7
16
|
end
|
|
8
17
|
|
|
9
18
|
def resolve(args, context:)
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
error = invalid_args(args)
|
|
20
|
+
return context.add_error("#{label}: #{error}") && nil if error
|
|
12
21
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
segments = Array(args).map(&:to_s).reject(&:empty?)
|
|
23
|
+
root = find_root(context) or return
|
|
24
|
+
|
|
25
|
+
segments.empty? ? root : root.join(*segments)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def invalid_args(args)
|
|
31
|
+
return "expected a path or a sequence of path segments, got a mapping" if args.is_a?(Hash)
|
|
32
|
+
|
|
33
|
+
Array(args).each.with_index(1) do |segment, i|
|
|
34
|
+
case segment
|
|
35
|
+
when nil
|
|
36
|
+
return "segment #{i} is nil (use a fallback, e.g. !env [VAR, default])"
|
|
37
|
+
when String, Numeric
|
|
38
|
+
return "segment #{i} (#{segment.inspect}) is absolute; segments are relative to the root" if File.absolute_path?(segment.to_s)
|
|
39
|
+
else
|
|
40
|
+
return "segment #{i} must be a string, got #{segment.class}"
|
|
16
41
|
end
|
|
42
|
+
end
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def find_root(context)
|
|
47
|
+
dir = context.dir
|
|
48
|
+
loop do
|
|
49
|
+
return Pathname.new(dir) if File.exist?(File.join(dir, @containing))
|
|
50
|
+
|
|
17
51
|
parent = File.dirname(dir)
|
|
18
52
|
if parent == dir
|
|
19
53
|
context.add_error("could not find #{@containing} in any ancestor of #{context.dir}")
|
|
20
|
-
return
|
|
54
|
+
return
|
|
21
55
|
end
|
|
22
56
|
dir = parent
|
|
23
57
|
end
|
|
24
58
|
end
|
|
59
|
+
|
|
60
|
+
def label = "path relative to the directory containing #{@containing}"
|
|
25
61
|
end
|
|
26
62
|
end
|
data/lib/nero/version.rb
CHANGED
data/lib/nero/visitor.rb
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Nero
|
|
4
4
|
class Visitor < ::Psych::Visitors::ToRuby
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
# Like YAML.load (safe_load): only `permitted_classes` (class names or classes) can be
|
|
6
|
+
# instantiated, so `!ruby/object:...` raises Psych::DisallowedClass. Aliases are allowed.
|
|
7
|
+
def self.build(tags, ctx, permitted_classes: Parser::PERMITTED_CLASSES, symbolize_names: false)
|
|
8
|
+
loader = ::Psych::ClassLoader::Restricted.new(permitted_classes.map(&:to_s), [])
|
|
9
|
+
visitor = new(::Psych::ScalarScanner.new(loader), loader, symbolize_names:)
|
|
7
10
|
visitor.instance_variable_set(:@nero_tags, tags)
|
|
8
11
|
visitor.instance_variable_set(:@nero_ctx, ctx)
|
|
9
12
|
visitor
|
|
@@ -14,7 +17,13 @@ module Nero
|
|
|
14
17
|
return super unless handler
|
|
15
18
|
|
|
16
19
|
o.tag = nil
|
|
17
|
-
|
|
20
|
+
# A bare tag (`a: !tag`) has no args. A quoted scalar stays a string: with an explicit
|
|
21
|
+
# tag Psych doesn't mark it quoted, so `!tag "123"` would become 123 and `!tag ""` nil.
|
|
22
|
+
args = case o.style
|
|
23
|
+
when ::Psych::Nodes::Scalar::SINGLE_QUOTED, ::Psych::Nodes::Scalar::DOUBLE_QUOTED then [o.value]
|
|
24
|
+
else o.value.empty? ? [] : [super]
|
|
25
|
+
end
|
|
26
|
+
handler.resolve(args, context: @nero_ctx)
|
|
18
27
|
end
|
|
19
28
|
|
|
20
29
|
def visit_Psych_Nodes_Sequence(o)
|
data/lib/nero.rb
CHANGED
|
@@ -16,26 +16,63 @@ require_relative "nero/ref_tag"
|
|
|
16
16
|
require_relative "nero/env_tag"
|
|
17
17
|
require_relative "nero/root_path_tag"
|
|
18
18
|
require_relative "nero/format_tag"
|
|
19
|
+
require_relative "nero/ip_tag"
|
|
19
20
|
require_relative "nero/visitor"
|
|
20
21
|
require_relative "nero/parser"
|
|
21
22
|
|
|
22
23
|
module Nero
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
# Like YAML.load, plus Nero's tags: string keys (symbolize_names: true for symbols), only
|
|
25
|
+
# permitted_classes (default Symbol) instantiated, aliases allowed. Raises Nero::ParseError
|
|
26
|
+
# with all errors at once. Nero::Parser#parse returns a Result instead of raising.
|
|
27
|
+
def self.load(yaml, **opts, &block)
|
|
28
|
+
result = Parser.new(**opts, &block).parse(yaml)
|
|
29
|
+
emit_warnings result.warnings if result.warnings?
|
|
30
|
+
result.value!
|
|
25
31
|
end
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
# Like YAML.load_file; see load. root: (or env:) picks a top-level key, e.g. :development.
|
|
34
|
+
def self.load_file(path, env: nil, root: nil, **opts, &block)
|
|
28
35
|
root ||= env&.to_s
|
|
29
|
-
Parser.new(root
|
|
36
|
+
result = Parser.new(root:, **opts, &block).parse_file(path)
|
|
37
|
+
emit_warnings result.warnings if result.warnings?
|
|
38
|
+
result.value!
|
|
30
39
|
end
|
|
31
40
|
|
|
32
|
-
|
|
41
|
+
# @deprecated Use load. Removed in 0.8.
|
|
42
|
+
def self.parse(...)
|
|
43
|
+
emit_warnings ["DEPRECATION WARNING: Nero.parse is deprecated and will be removed in nero 0.8 (use Nero.load)"]
|
|
44
|
+
load(...)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @deprecated Use load_file. Removed in 0.8.
|
|
48
|
+
def self.parse_file(...)
|
|
49
|
+
emit_warnings ["DEPRECATION WARNING: Nero.parse_file is deprecated and will be removed in nero 0.8 (use Nero.load_file)"]
|
|
50
|
+
load_file(...)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Classes config files may instantiate: dates and times are plausible config values.
|
|
54
|
+
# Unlike Rails' config_for (YAML.unsafe_load), arbitrary objects (!ruby/object) are refused.
|
|
55
|
+
CONFIG_PERMITTED_CLASSES = %w[Symbol Date Time].freeze
|
|
56
|
+
|
|
57
|
+
# Where config_for looks for `<name>.yml`: `config/` in the current directory.
|
|
58
|
+
# With Rails (nero/rails), `Rails.root/config` instead.
|
|
59
|
+
def self.config_dir = Pathname.pwd / "config"
|
|
60
|
+
|
|
61
|
+
# Like Rails.application.config_for: symbol keys. See CONFIG_PERMITTED_CLASSES.
|
|
62
|
+
# file: a name (`:app` → `config_dir/app.yml`) or a Pathname (used as is, relative to the cwd).
|
|
63
|
+
def self.config_for(file, env: nil, root: nil, permitted_classes: CONFIG_PERMITTED_CLASSES, &block)
|
|
33
64
|
root ||= env&.to_s
|
|
34
65
|
path = case file
|
|
35
|
-
when Pathname then file
|
|
36
|
-
else
|
|
66
|
+
when Pathname then file.expand_path
|
|
67
|
+
else config_dir / "#{file}.yml"
|
|
68
|
+
end
|
|
69
|
+
load_file(path, root:, permitted_classes:, symbolize_names: true, &block)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private_class_method def self.emit_warnings(warnings)
|
|
73
|
+
warnings.each do |warn|
|
|
74
|
+
Kernel.warn("[nero] #{warn}")
|
|
37
75
|
end
|
|
38
|
-
parse_file(path.expand_path, root: root, &block)
|
|
39
76
|
end
|
|
40
77
|
end
|
|
41
78
|
|
data/mise.toml
ADDED
data/tmp/.keep
ADDED
|
File without changes
|
metadata
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nero
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.0.
|
|
4
|
+
version: 0.7.0.rc3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gert Goet
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
-
dependencies:
|
|
12
|
-
- !ruby/object:Gem::Dependency
|
|
13
|
-
name: appraisal
|
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
|
15
|
-
requirements:
|
|
16
|
-
- - ">="
|
|
17
|
-
- !ruby/object:Gem::Version
|
|
18
|
-
version: '0'
|
|
19
|
-
type: :development
|
|
20
|
-
prerelease: false
|
|
21
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
-
requirements:
|
|
23
|
-
- - ">="
|
|
24
|
-
- !ruby/object:Gem::Version
|
|
25
|
-
version: '0'
|
|
11
|
+
dependencies: []
|
|
26
12
|
description: |
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
13
|
+
Declarative YAML-tags for config files, all errors reported at once:
|
|
14
|
+
- environment values: !env, !env?, coerced via !env/integer, !env/float, !env/bool, !env/path, !env/ip, !env/list (optional: !env?/integer etc.)
|
|
15
|
+
- references within the file: !ref
|
|
16
|
+
- formatted strings: !format
|
|
17
|
+
- IP addresses and ranges: !ip
|
|
18
|
+
- paths below the project root: !path/git_root (and !path/rails_root)
|
|
19
|
+
- Rails: !credentials, !duration, !str/inquirer, Nero.config_for
|
|
20
|
+
- custom tags via a block
|
|
31
21
|
|
|
32
22
|
See README for examples.
|
|
33
23
|
email:
|
|
@@ -37,16 +27,16 @@ extensions: []
|
|
|
37
27
|
extra_rdoc_files: []
|
|
38
28
|
files:
|
|
39
29
|
- ".envrc"
|
|
30
|
+
- ".irbrc"
|
|
40
31
|
- ".rspec"
|
|
41
32
|
- ".standard.yml"
|
|
42
33
|
- ".yardopts"
|
|
43
|
-
- Appraisals
|
|
44
34
|
- CHANGELOG.md
|
|
45
35
|
- LICENSE.txt
|
|
46
36
|
- README.md
|
|
47
37
|
- Rakefile
|
|
48
|
-
-
|
|
49
|
-
-
|
|
38
|
+
- UPGRADING.md
|
|
39
|
+
- _irbrc.example
|
|
50
40
|
- lib/nero.rb
|
|
51
41
|
- lib/nero/base_tag.rb
|
|
52
42
|
- lib/nero/context.rb
|
|
@@ -54,6 +44,7 @@ files:
|
|
|
54
44
|
- lib/nero/env_tag.rb
|
|
55
45
|
- lib/nero/error.rb
|
|
56
46
|
- lib/nero/format_tag.rb
|
|
47
|
+
- lib/nero/ip_tag.rb
|
|
57
48
|
- lib/nero/parser.rb
|
|
58
49
|
- lib/nero/proc_tag.rb
|
|
59
50
|
- lib/nero/rails.rb
|
|
@@ -67,9 +58,11 @@ files:
|
|
|
67
58
|
- lib/nero/root_path_tag.rb
|
|
68
59
|
- lib/nero/version.rb
|
|
69
60
|
- lib/nero/visitor.rb
|
|
61
|
+
- mise.toml
|
|
70
62
|
- rakelib/gem.rake
|
|
71
63
|
- rakelib/yard.rake
|
|
72
64
|
- sig/nero.rbs
|
|
65
|
+
- tmp/.keep
|
|
73
66
|
homepage: https://github.com/eval/nero
|
|
74
67
|
licenses:
|
|
75
68
|
- MIT
|
|
@@ -77,6 +70,12 @@ metadata:
|
|
|
77
70
|
homepage_uri: https://github.com/eval/nero
|
|
78
71
|
source_code_uri: https://github.com/eval/nero
|
|
79
72
|
changelog_uri: https://github.com/eval/nero/blob/main/CHANGELOG.md
|
|
73
|
+
rubygems_mfa_required: 'true'
|
|
74
|
+
post_install_message: |
|
|
75
|
+
Nero 0.7 has breaking changes. Most notably:
|
|
76
|
+
Nero.load / Nero.load_file now return STRING keys, like YAML.load.
|
|
77
|
+
Use symbolize_names: true, or Nero.config_for (symbol keys, like Rails).
|
|
78
|
+
Upgrade guide: https://github.com/eval/nero/blob/main/UPGRADING.md
|
|
80
79
|
rdoc_options: []
|
|
81
80
|
require_paths:
|
|
82
81
|
- lib
|
|
@@ -84,14 +83,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
84
83
|
requirements:
|
|
85
84
|
- - ">="
|
|
86
85
|
- !ruby/object:Gem::Version
|
|
87
|
-
version: 3.
|
|
86
|
+
version: 3.3.0
|
|
88
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
88
|
requirements:
|
|
90
89
|
- - ">="
|
|
91
90
|
- !ruby/object:Gem::Version
|
|
92
91
|
version: '0'
|
|
93
92
|
requirements: []
|
|
94
|
-
rubygems_version:
|
|
93
|
+
rubygems_version: 4.0.20
|
|
95
94
|
specification_version: 4
|
|
96
|
-
summary:
|
|
95
|
+
summary: Declarative YAML-tags
|
|
97
96
|
test_files: []
|
data/Appraisals
DELETED
data/gemfiles/psych_3.gemfile
DELETED