nero 0.6.0 → 0.7.0.rc2
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/.envrc +3 -1
- data/CHANGELOG.md +26 -1
- data/README.md +51 -49
- data/lib/nero/base_tag.rb +9 -0
- data/lib/nero/context.rb +17 -0
- data/lib/nero/deferred.rb +9 -0
- data/lib/nero/env_tag.rb +32 -0
- data/lib/nero/error.rb +22 -0
- data/lib/nero/format_tag.rb +16 -0
- data/lib/nero/parser.rb +139 -0
- data/lib/nero/proc_tag.rb +9 -0
- data/lib/nero/rails/credentials_tag.rb +24 -0
- data/lib/nero/rails/duration_tag.rb +26 -0
- data/lib/nero/rails/string_inquirer_tag.rb +16 -0
- data/lib/nero/rails.rb +35 -0
- data/lib/nero/railtie.rb +4 -5
- data/lib/nero/ref.rb +9 -0
- data/lib/nero/ref_tag.rb +9 -0
- data/lib/nero/result.rb +19 -0
- data/lib/nero/root_path_tag.rb +26 -0
- data/lib/nero/version.rb +1 -1
- data/lib/nero/visitor.rb +54 -0
- data/lib/nero.rb +28 -574
- data/rakelib/gem.rake +4 -10
- metadata +20 -18
- data/lib/nero/util.rb +0 -29
data/lib/nero/result.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nero
|
|
4
|
+
class Result
|
|
5
|
+
attr_reader :value, :errors
|
|
6
|
+
|
|
7
|
+
def initialize(value, errors = [])
|
|
8
|
+
@value = value
|
|
9
|
+
@errors = errors
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def ok? = errors.empty?
|
|
13
|
+
|
|
14
|
+
def value!
|
|
15
|
+
raise ParseError, errors unless ok?
|
|
16
|
+
value
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nero
|
|
4
|
+
class RootPathTag < BaseTag
|
|
5
|
+
def initialize(containing:)
|
|
6
|
+
@containing = containing
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def resolve(args, context:)
|
|
10
|
+
relative_path = args[0]&.then { |p| p.empty? ? nil : p }
|
|
11
|
+
dir = context.dir
|
|
12
|
+
|
|
13
|
+
loop do
|
|
14
|
+
if File.exist?(File.join(dir, @containing))
|
|
15
|
+
return relative_path ? Pathname.new(File.join(dir, relative_path)) : Pathname.new(dir)
|
|
16
|
+
end
|
|
17
|
+
parent = File.dirname(dir)
|
|
18
|
+
if parent == dir
|
|
19
|
+
context.add_error("could not find #{@containing} in any ancestor of #{context.dir}")
|
|
20
|
+
return nil
|
|
21
|
+
end
|
|
22
|
+
dir = parent
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/nero/version.rb
CHANGED
data/lib/nero/visitor.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nero
|
|
4
|
+
class Visitor < ::Psych::Visitors::ToRuby
|
|
5
|
+
def self.build(tags, ctx)
|
|
6
|
+
visitor = create
|
|
7
|
+
visitor.instance_variable_set(:@nero_tags, tags)
|
|
8
|
+
visitor.instance_variable_set(:@nero_ctx, ctx)
|
|
9
|
+
visitor
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def visit_Psych_Nodes_Scalar(o)
|
|
13
|
+
handler = find_nero_tag(o.tag)
|
|
14
|
+
return super unless handler
|
|
15
|
+
|
|
16
|
+
o.tag = nil
|
|
17
|
+
handler.resolve([super], context: @nero_ctx)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def visit_Psych_Nodes_Sequence(o)
|
|
21
|
+
handler = find_nero_tag(o.tag)
|
|
22
|
+
return super unless handler
|
|
23
|
+
|
|
24
|
+
o.tag = nil
|
|
25
|
+
args = super
|
|
26
|
+
contains_ref?(args) ? Deferred.new(handler, args) : handler.resolve(args, context: @nero_ctx)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def visit_Psych_Nodes_Mapping(o)
|
|
30
|
+
handler = find_nero_tag(o.tag)
|
|
31
|
+
return super unless handler
|
|
32
|
+
|
|
33
|
+
o.tag = nil
|
|
34
|
+
args = super
|
|
35
|
+
contains_ref?(args) ? Deferred.new(handler, args) : handler.resolve(args, context: @nero_ctx)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def find_nero_tag(tag)
|
|
41
|
+
return nil unless tag&.start_with?("!")
|
|
42
|
+
@nero_tags[tag[1..]]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def contains_ref?(value)
|
|
46
|
+
case value
|
|
47
|
+
when Ref, Deferred then true
|
|
48
|
+
when Hash then value.values.any? { |v| contains_ref?(v) }
|
|
49
|
+
when Array then value.any? { |v| contains_ref?(v) }
|
|
50
|
+
else false
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|