babl-json 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/babl/builder/template_base.rb +4 -3
- data/lib/babl/nodes/dep.rb +0 -14
- data/lib/babl/nodes/each.rb +7 -1
- data/lib/babl/nodes/fixed_array.rb +1 -1
- data/lib/babl/nodes/merge.rb +1 -1
- data/lib/babl/nodes/nav.rb +12 -6
- data/lib/babl/nodes/object.rb +2 -2
- data/lib/babl/nodes/parent.rb +5 -22
- data/lib/babl/nodes/switch.rb +7 -0
- data/lib/babl/nodes/typed.rb +67 -17
- data/lib/babl/nodes/with.rb +7 -2
- data/lib/babl/operators/array.rb +3 -1
- data/lib/babl/operators/call.rb +1 -1
- data/lib/babl/operators/dep.rb +9 -0
- data/lib/babl/operators/merge.rb +2 -1
- data/lib/babl/operators/nav.rb +2 -2
- data/lib/babl/operators/object.rb +18 -13
- data/lib/babl/operators/parent.rb +1 -1
- data/lib/babl/operators/source.rb +3 -1
- data/lib/babl/operators/static.rb +4 -1
- data/lib/babl/operators/switch.rb +10 -4
- data/lib/babl/operators/typed.rb +4 -4
- data/lib/babl/operators/with.rb +5 -3
- data/lib/babl/utils/dsl_proxy.rb +3 -2
- data/lib/babl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36cb4d94d13851bb8c5a28ab9d8c4ab5a19fa6de
|
4
|
+
data.tar.gz: '0298c5489089f88c5ce9a171568e418fb8cb0dc6'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0b1e9ce1e461766292ad33f43aa528d61c8fde897a94a7791a8c4b9ffcfb0f53806fbaea2dad7b981c8d2131552b20f22550aaa1eb01888449a2af08cedec50
|
7
|
+
data.tar.gz: 8ad1d7732551481f3309dd06797fe11faaa3aec11c8bc222972c4789c721b427c37f22fbedd987e139fc37174f87c3933dea272c7bd9054be7ced88dadaf725c
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'babl/nodes'
|
3
|
+
require 'babl/utils'
|
3
4
|
require 'babl/builder'
|
4
5
|
require 'babl/rendering'
|
5
6
|
|
@@ -9,9 +10,9 @@ module Babl
|
|
9
10
|
#
|
10
11
|
# Since the BABL code is run via #instance_eval within an instance of this class, we want to
|
11
12
|
# define as few methods as possible here.
|
12
|
-
class TemplateBase
|
13
|
+
class TemplateBase < Utils::Value.new(:builder)
|
13
14
|
def initialize(builder = ChainBuilder.new(&:itself))
|
14
|
-
|
15
|
+
super(builder)
|
15
16
|
end
|
16
17
|
|
17
18
|
def compile(preloader: Rendering::NoopPreloader, pretty: true, optimize: true)
|
@@ -56,7 +57,7 @@ module Babl
|
|
56
57
|
self.class.new builder.construct_terminal(&block)
|
57
58
|
end
|
58
59
|
|
59
|
-
|
60
|
+
protected :builder
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
data/lib/babl/nodes/dep.rb
CHANGED
@@ -4,10 +4,6 @@ require 'babl/utils'
|
|
4
4
|
module Babl
|
5
5
|
module Nodes
|
6
6
|
class Dep < Utils::Value.new(:node, :path)
|
7
|
-
def initialize(node, path)
|
8
|
-
super(node, canonicalize(path))
|
9
|
-
end
|
10
|
-
|
11
7
|
def render(ctx)
|
12
8
|
node.render(ctx)
|
13
9
|
end
|
@@ -27,16 +23,6 @@ module Babl
|
|
27
23
|
def optimize
|
28
24
|
Dep.new(node.optimize, path)
|
29
25
|
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def canonicalize(path)
|
34
|
-
case path
|
35
|
-
when ::Array then path.reduce(Utils::Hash::EMPTY) { |a, p| a.merge(canonicalize(p)) }
|
36
|
-
when ::Hash then path.map { |k, v| [k.to_sym, canonicalize(v)] }.to_h
|
37
|
-
else { path.to_sym => Utils::Hash::EMPTY }
|
38
|
-
end
|
39
|
-
end
|
40
26
|
end
|
41
27
|
end
|
42
28
|
end
|
data/lib/babl/nodes/each.rb
CHANGED
@@ -7,7 +7,13 @@ module Babl
|
|
7
7
|
module Nodes
|
8
8
|
class Each < Utils::Value.new(:node)
|
9
9
|
def dependencies
|
10
|
-
|
10
|
+
node_deps = node.dependencies
|
11
|
+
child_deps = node.dependencies.reject { |key, _| key == Parent::PARENT_MARKER }
|
12
|
+
|
13
|
+
Babl::Utils::Hash.deep_merge(
|
14
|
+
node_deps[Parent::PARENT_MARKER] || Utils::Hash::EMPTY,
|
15
|
+
__each__: child_deps
|
16
|
+
)
|
11
17
|
end
|
12
18
|
|
13
19
|
def schema
|
@@ -26,7 +26,7 @@ module Babl
|
|
26
26
|
optimized_nodes = nodes.map(&:optimize)
|
27
27
|
fixed_array = FixedArray.new(optimized_nodes)
|
28
28
|
return fixed_array unless optimized_nodes.all? { |node| Constant === node }
|
29
|
-
Constant.new(fixed_array.
|
29
|
+
Constant.new(fixed_array.nodes.map(&:value).freeze, fixed_array.schema)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/babl/nodes/merge.rb
CHANGED
data/lib/babl/nodes/nav.rb
CHANGED
@@ -5,9 +5,15 @@ require 'babl/nodes/parent'
|
|
5
5
|
|
6
6
|
module Babl
|
7
7
|
module Nodes
|
8
|
-
class Nav < Utils::Value.new(:
|
8
|
+
class Nav < Utils::Value.new(:property, :node)
|
9
9
|
def dependencies
|
10
|
-
|
10
|
+
node_deps = node.dependencies
|
11
|
+
child_deps = node.dependencies.reject { |key, _| key == Parent::PARENT_MARKER }
|
12
|
+
|
13
|
+
Babl::Utils::Hash.deep_merge(
|
14
|
+
node_deps[Parent::PARENT_MARKER] || Utils::Hash::EMPTY,
|
15
|
+
property => child_deps
|
16
|
+
)
|
11
17
|
end
|
12
18
|
|
13
19
|
def schema
|
@@ -20,18 +26,18 @@ module Babl
|
|
20
26
|
|
21
27
|
def render(ctx)
|
22
28
|
value = begin
|
23
|
-
::Hash === ctx.object ? ctx.object.fetch(
|
29
|
+
::Hash === ctx.object ? ctx.object.fetch(property) : ctx.object.send(property)
|
24
30
|
rescue StandardError => e
|
25
|
-
raise Errors::RenderingError, "#{e.message}\n" + ctx.formatted_stack(
|
31
|
+
raise Errors::RenderingError, "#{e.message}\n" + ctx.formatted_stack(property), e.backtrace
|
26
32
|
end
|
27
|
-
node.render(ctx.move_forward(value,
|
33
|
+
node.render(ctx.move_forward(value, property))
|
28
34
|
end
|
29
35
|
|
30
36
|
def optimize
|
31
37
|
optimized = node.optimize
|
32
38
|
return optimized if Constant === optimized
|
33
39
|
return optimized.node if Parent === optimized
|
34
|
-
Nav.new(
|
40
|
+
Nav.new(property, optimized)
|
35
41
|
end
|
36
42
|
end
|
37
43
|
end
|
data/lib/babl/nodes/object.rb
CHANGED
@@ -6,7 +6,7 @@ require 'babl/nodes/constant'
|
|
6
6
|
module Babl
|
7
7
|
module Nodes
|
8
8
|
class Object < Utils::Value.new(:nodes)
|
9
|
-
EMPTY = new(
|
9
|
+
EMPTY = new(Utils::Hash::EMPTY)
|
10
10
|
|
11
11
|
def dependencies
|
12
12
|
nodes.values.map(&:dependencies).reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
|
@@ -32,7 +32,7 @@ module Babl
|
|
32
32
|
optimized_nodes = nodes.map { |k, v| [k, v.optimize] }.to_h
|
33
33
|
optimized_object = Object.new(optimized_nodes)
|
34
34
|
return optimized_object unless optimized_nodes.values.all? { |node| Constant === node }
|
35
|
-
Constant.new(optimized_object.
|
35
|
+
Constant.new(optimized_object.nodes.map { |k, v| [k, v.value] }.to_h.freeze, optimized_object.schema)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/lib/babl/nodes/parent.rb
CHANGED
@@ -7,9 +7,11 @@ module Babl
|
|
7
7
|
class Parent < Utils::Value.new(:node)
|
8
8
|
PARENT_MARKER = Utils::Ref.new
|
9
9
|
|
10
|
-
class
|
10
|
+
class Verifier < Utils::Value.new(:node)
|
11
11
|
def dependencies
|
12
|
-
|
12
|
+
deps = node.dependencies
|
13
|
+
raise Errors::InvalidTemplate, 'Out of context parent dependency' if deps.key? PARENT_MARKER
|
14
|
+
deps
|
13
15
|
end
|
14
16
|
|
15
17
|
def schema
|
@@ -25,26 +27,7 @@ module Babl
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def optimize
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def backpropagate_dependencies(deps)
|
34
|
-
raise Errors::InvalidTemplate, 'Out of context parent dependency' if deps.key? PARENT_MARKER
|
35
|
-
new_deps = backpropagate_dependencies_one_level(deps)
|
36
|
-
deps == new_deps ? new_deps : backpropagate_dependencies(new_deps)
|
37
|
-
end
|
38
|
-
|
39
|
-
def backpropagate_dependencies_one_level(deps)
|
40
|
-
deps.reduce(Utils::Hash::EMPTY) do |out, (k, v)|
|
41
|
-
next out if k == PARENT_MARKER
|
42
|
-
|
43
|
-
Babl::Utils::Hash.deep_merge(
|
44
|
-
Babl::Utils::Hash.deep_merge(out, k => backpropagate_dependencies_one_level(v)),
|
45
|
-
v[PARENT_MARKER] || Utils::Hash::EMPTY
|
46
|
-
)
|
47
|
-
end
|
30
|
+
Verifier.new(node.optimize)
|
48
31
|
end
|
49
32
|
end
|
50
33
|
|
data/lib/babl/nodes/switch.rb
CHANGED
@@ -38,11 +38,18 @@ module Babl
|
|
38
38
|
optimize_truthy_conditions ||
|
39
39
|
optimize_always_same_outputs ||
|
40
40
|
optimize_same_conditions ||
|
41
|
+
optimize_continue_to_switch ||
|
41
42
|
self
|
42
43
|
end
|
43
44
|
|
44
45
|
private
|
45
46
|
|
47
|
+
def optimize_continue_to_switch
|
48
|
+
cond, val = nodes.last
|
49
|
+
return unless Switch === val && Constant === cond && cond.value
|
50
|
+
Switch.new(nodes[0...-1] + val.nodes).optimize
|
51
|
+
end
|
52
|
+
|
46
53
|
def optimize_same_conditions
|
47
54
|
conds = Set.new
|
48
55
|
new_nodes = nodes.map { |cond, val|
|
data/lib/babl/nodes/typed.rb
CHANGED
@@ -2,33 +2,83 @@
|
|
2
2
|
require 'babl/utils'
|
3
3
|
require 'babl/schema'
|
4
4
|
require 'babl/nodes/terminal_value'
|
5
|
+
require 'singleton'
|
5
6
|
|
6
7
|
module Babl
|
7
8
|
module Nodes
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
module Typed
|
10
|
+
class Base
|
11
|
+
include Singleton
|
12
|
+
|
13
|
+
def dependencies
|
14
|
+
Utils::Hash::EMPTY
|
15
|
+
end
|
16
|
+
|
17
|
+
def pinned_dependencies
|
18
|
+
Utils::Hash::EMPTY
|
19
|
+
end
|
20
|
+
|
21
|
+
def optimize
|
22
|
+
self
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
|
-
|
19
|
-
|
26
|
+
class String < Base
|
27
|
+
def schema
|
28
|
+
Schema::Typed::STRING
|
29
|
+
end
|
30
|
+
|
31
|
+
def render(ctx)
|
32
|
+
value = ctx.object
|
33
|
+
return value if ::String === value
|
34
|
+
return value.to_s if ::Symbol === value
|
35
|
+
|
36
|
+
raise Errors::RenderingError,
|
37
|
+
"Expected a string, got #{value}\n#{ctx.formatted_stack}"
|
38
|
+
end
|
20
39
|
end
|
21
40
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
41
|
+
class Integer < Base
|
42
|
+
def schema
|
43
|
+
Schema::Typed::INTEGER
|
44
|
+
end
|
45
|
+
|
46
|
+
def render(ctx)
|
47
|
+
value = ctx.object
|
48
|
+
return value if ::Integer === value
|
49
|
+
|
50
|
+
raise Errors::RenderingError,
|
51
|
+
"Expected an integer, got #{value}\n#{ctx.formatted_stack}"
|
26
52
|
end
|
27
|
-
raise Errors::RenderingError, "Expected type '#{schema.type}': #{value}\n#{ctx.formatted_stack}"
|
28
53
|
end
|
29
54
|
|
30
|
-
|
31
|
-
|
55
|
+
class Number < Base
|
56
|
+
def schema
|
57
|
+
Schema::Typed::NUMBER
|
58
|
+
end
|
59
|
+
|
60
|
+
def render(ctx)
|
61
|
+
value = ctx.object
|
62
|
+
return value if ::Integer === value
|
63
|
+
return value.to_f if ::Numeric === value
|
64
|
+
|
65
|
+
raise Errors::RenderingError,
|
66
|
+
"Expected a number, got #{value}\n#{ctx.formatted_stack}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Boolean < Base
|
71
|
+
def schema
|
72
|
+
Schema::Typed::BOOLEAN
|
73
|
+
end
|
74
|
+
|
75
|
+
def render(ctx)
|
76
|
+
value = ctx.object
|
77
|
+
return value if true == value || false == value
|
78
|
+
|
79
|
+
raise Errors::RenderingError,
|
80
|
+
"Expected a boolean, got #{value}\n#{ctx.formatted_stack}"
|
81
|
+
end
|
32
82
|
end
|
33
83
|
end
|
34
84
|
end
|
data/lib/babl/nodes/with.rb
CHANGED
@@ -10,8 +10,12 @@ module Babl
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def dependencies
|
13
|
-
|
14
|
-
|
13
|
+
Babl::Utils::Hash.deep_merge(
|
14
|
+
node.dependencies[Parent::PARENT_MARKER] || Utils::Hash::EMPTY,
|
15
|
+
nodes.map(&:dependencies).reduce(Utils::Hash::EMPTY) { |a, b|
|
16
|
+
Babl::Utils::Hash.deep_merge(a, b)
|
17
|
+
}
|
18
|
+
)
|
15
19
|
end
|
16
20
|
|
17
21
|
def pinned_dependencies
|
@@ -32,6 +36,7 @@ module Babl
|
|
32
36
|
def optimize
|
33
37
|
optimized = node.optimize
|
34
38
|
return optimized if Constant === optimized
|
39
|
+
return optimized.node if Parent === optimized
|
35
40
|
With.new(optimized, nodes.map(&:optimize), block)
|
36
41
|
end
|
37
42
|
end
|
data/lib/babl/operators/array.rb
CHANGED
@@ -7,9 +7,11 @@ module Babl
|
|
7
7
|
module DSL
|
8
8
|
# Produce an fixed-size array, using the provided templates to populate its elements.
|
9
9
|
def array(*templates)
|
10
|
+
templates = templates.map { |t| unscoped.call(t) }
|
11
|
+
|
10
12
|
construct_terminal { |ctx|
|
11
13
|
Nodes::FixedArray.new(templates.map { |t|
|
12
|
-
|
14
|
+
t.builder.precompile(Nodes::TerminalValue.instance, ctx.merge(continue: nil))
|
13
15
|
})
|
14
16
|
}
|
15
17
|
end
|
data/lib/babl/operators/call.rb
CHANGED
@@ -18,7 +18,7 @@ module Babl
|
|
18
18
|
when Utils::DslProxy then call(arg.itself)
|
19
19
|
when ::Symbol then nav(arg)
|
20
20
|
when ::Proc then call(&arg)
|
21
|
-
when ::Hash then object(
|
21
|
+
when ::Hash then object(arg)
|
22
22
|
when ::Array then array(*arg)
|
23
23
|
when ::String, ::Numeric, ::NilClass, ::TrueClass, ::FalseClass then static(arg)
|
24
24
|
else raise Errors::InvalidTemplate, "call() received invalid argument: #{arg}"
|
data/lib/babl/operators/dep.rb
CHANGED
@@ -4,10 +4,19 @@ require 'babl/nodes'
|
|
4
4
|
module Babl
|
5
5
|
module Operators
|
6
6
|
module Dep
|
7
|
+
def self.canonicalize(path)
|
8
|
+
case path
|
9
|
+
when ::Array then path.reduce(Utils::Hash::EMPTY) { |a, p| a.merge(canonicalize(p)) }
|
10
|
+
when ::Hash then path.map { |k, v| [k.dup.freeze, canonicalize(v)] }.to_h
|
11
|
+
else { path.dup.freeze => Utils::Hash::EMPTY }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
module DSL
|
8
16
|
# Declare dependencies as if they were generated by nav()
|
9
17
|
# but without navigating.
|
10
18
|
def dep(*path)
|
19
|
+
path = Dep.canonicalize(path)
|
11
20
|
construct_node(continue: nil) { |node| Nodes::Dep.new(node, path) }
|
12
21
|
end
|
13
22
|
end
|
data/lib/babl/operators/merge.rb
CHANGED
@@ -9,11 +9,12 @@ module Babl
|
|
9
9
|
# Merge multiple JSON objects (non-deep)
|
10
10
|
def merge(*templates)
|
11
11
|
return call(Utils::Hash::EMPTY) if templates.empty?
|
12
|
+
templates = templates.map { |t| unscoped.call(t) }
|
12
13
|
|
13
14
|
construct_terminal { |context|
|
14
15
|
Nodes::Merge.new(
|
15
16
|
templates.map { |t|
|
16
|
-
|
17
|
+
t.builder.precompile(
|
17
18
|
Nodes::TerminalValue.instance,
|
18
19
|
context.merge(continue: nil)
|
19
20
|
)
|
data/lib/babl/operators/nav.rb
CHANGED
@@ -14,8 +14,8 @@ module Babl
|
|
14
14
|
if path.empty?
|
15
15
|
return (block ? with(unscoped, &block) : construct_node(key: nil, continue: nil) { |node| node })
|
16
16
|
end
|
17
|
-
|
18
|
-
construct_node(key: nil, continue: nil) { |node| Nodes::Nav.new(
|
17
|
+
property = path.first.dup.freeze
|
18
|
+
construct_node(key: nil, continue: nil) { |node| Nodes::Nav.new(property, node) }
|
19
19
|
.nav(*path[1..-1], &block)
|
20
20
|
end
|
21
21
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'babl/nodes'
|
3
|
+
require 'babl/utils'
|
3
4
|
require 'babl/errors'
|
4
5
|
|
5
6
|
module Babl
|
@@ -7,24 +8,28 @@ module Babl
|
|
7
8
|
module Object
|
8
9
|
module DSL
|
9
10
|
# Create a JSON object node with static structure
|
10
|
-
def object(*
|
11
|
-
|
11
|
+
def object(*args)
|
12
|
+
kwargs = ::Hash === args.last ? args.pop : Utils::Hash::EMPTY
|
13
|
+
|
14
|
+
(args.map(&:to_sym) + kwargs.keys.map(&:to_sym)).group_by(&:itself).each_value do |keys|
|
12
15
|
raise Errors::InvalidTemplate, "Duplicate key in object(): #{keys.first}" if keys.size > 1
|
13
16
|
end
|
14
17
|
|
18
|
+
templates = args
|
19
|
+
.map { |name| [name.to_sym, unscoped.nav(name)] }.to_h
|
20
|
+
.merge(kwargs)
|
21
|
+
.map { |k, v| [k, unscoped.call(v)] }
|
22
|
+
|
15
23
|
construct_terminal { |ctx|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
[k, unscoped.call(v).builder.precompile(
|
24
|
+
Nodes::Object.new(templates.map { |key, template|
|
25
|
+
[
|
26
|
+
key.to_sym,
|
27
|
+
template.builder.precompile(
|
21
28
|
Nodes::TerminalValue.instance,
|
22
|
-
ctx.merge(key:
|
23
|
-
)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Nodes::Object.new(nodes)
|
29
|
+
ctx.merge(key: key, continue: nil)
|
30
|
+
)
|
31
|
+
]
|
32
|
+
}.to_h)
|
28
33
|
}
|
29
34
|
end
|
30
35
|
end
|
@@ -6,7 +6,9 @@ module Babl
|
|
6
6
|
module DSL
|
7
7
|
# Parse BABL source into a Template
|
8
8
|
def source(*args, &block)
|
9
|
-
|
9
|
+
raise Errors::InvalidTemplate, 'source() expects a block xor a string' unless args.empty? ^ block.nil?
|
10
|
+
block ||= proc { instance_eval(*args) }
|
11
|
+
call Utils::DslProxy.eval(unscoped, &block)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -12,7 +12,10 @@ module Babl
|
|
12
12
|
|
13
13
|
case sanitized_val
|
14
14
|
when ::String, ::Numeric, ::NilClass, ::TrueClass, ::FalseClass
|
15
|
-
|
15
|
+
frozen_val = sanitized_val.dup.freeze
|
16
|
+
construct_terminal {
|
17
|
+
Nodes::Constant.new(frozen_val, Schema::Primitive.new(frozen_val))
|
18
|
+
}
|
16
19
|
else call(sanitized_val)
|
17
20
|
end
|
18
21
|
rescue Errors::RenderingError => exception
|
@@ -8,13 +8,19 @@ module Babl
|
|
8
8
|
module DSL
|
9
9
|
# Conditional switching between different templates
|
10
10
|
def switch(conds = Utils::Hash::EMPTY)
|
11
|
+
conds = conds.map { |cond, value| [unscoped.call(cond), unscoped.call(value)] }
|
12
|
+
|
11
13
|
construct_node(continue: nil) { |node, context|
|
12
14
|
nodes = conds.map { |cond, value|
|
13
|
-
cond_node =
|
14
|
-
|
15
|
+
cond_node = cond.builder.precompile(
|
16
|
+
Nodes::InternalValue.instance,
|
17
|
+
context.merge(continue: nil)
|
18
|
+
)
|
15
19
|
|
16
|
-
value_node =
|
17
|
-
|
20
|
+
value_node = value.builder.precompile(
|
21
|
+
Nodes::TerminalValue.instance,
|
22
|
+
context.merge(continue: node)
|
23
|
+
)
|
18
24
|
|
19
25
|
[cond_node, value_node]
|
20
26
|
}
|
data/lib/babl/operators/typed.rb
CHANGED
@@ -6,19 +6,19 @@ module Babl
|
|
6
6
|
module Typed
|
7
7
|
module DSL
|
8
8
|
def integer
|
9
|
-
construct_terminal { Nodes::Typed::
|
9
|
+
construct_terminal { Nodes::Typed::Integer.instance }
|
10
10
|
end
|
11
11
|
|
12
12
|
def number
|
13
|
-
construct_terminal { Nodes::Typed::
|
13
|
+
construct_terminal { Nodes::Typed::Number.instance }
|
14
14
|
end
|
15
15
|
|
16
16
|
def string
|
17
|
-
construct_terminal { Nodes::Typed::
|
17
|
+
construct_terminal { Nodes::Typed::String.instance }
|
18
18
|
end
|
19
19
|
|
20
20
|
def boolean
|
21
|
-
construct_terminal { Nodes::Typed::
|
21
|
+
construct_terminal { Nodes::Typed::Boolean.instance }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/lib/babl/operators/with.rb
CHANGED
@@ -7,13 +7,15 @@ module Babl
|
|
7
7
|
module DSL
|
8
8
|
# Produce a value by calling the block, passing it the output value of the templates passed as argument.
|
9
9
|
def with(*templates, &block)
|
10
|
+
templates = templates.map { |t| unscoped.call(t) }
|
11
|
+
|
10
12
|
construct_node(key: nil, continue: nil) do |node, context|
|
11
|
-
Nodes::With.new(node, templates.map
|
12
|
-
|
13
|
+
Nodes::With.new(node, templates.map { |t|
|
14
|
+
t.builder.precompile(
|
13
15
|
Nodes::InternalValue.instance,
|
14
16
|
context.merge(continue: nil)
|
15
17
|
)
|
16
|
-
|
18
|
+
}, block)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
data/lib/babl/utils/dsl_proxy.rb
CHANGED
@@ -9,7 +9,8 @@ module Babl
|
|
9
9
|
# correctly.
|
10
10
|
class DslProxy
|
11
11
|
NON_PROXIED_METHODS = Set[
|
12
|
-
:__send__, :send, :object_id, :__id__, :equal?, :instance_eval
|
12
|
+
:__send__, :send, :object_id, :__id__, :equal?, :instance_eval, :instance_exec,
|
13
|
+
:respond_to?, :method, :freeze
|
13
14
|
]
|
14
15
|
|
15
16
|
instance_methods.each do |method|
|
@@ -31,7 +32,7 @@ module Babl
|
|
31
32
|
@__fallback__.respond_to?(method, include_private)
|
32
33
|
end
|
33
34
|
|
34
|
-
def self.eval(dsl,
|
35
|
+
def self.eval(dsl, &block)
|
35
36
|
new(dsl, block.binding.receiver).instance_eval(&block)
|
36
37
|
end
|
37
38
|
|
data/lib/babl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babl-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederic Terrazzoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|