babl-json 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/babl/nodes/constant.rb +4 -0
- data/lib/babl/nodes/each.rb +3 -2
- data/lib/babl/nodes/with.rb +20 -7
- data/lib/babl/operators/static.rb +8 -4
- data/lib/babl/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 329322cf3fa5b7e83cad065409efcd8889146f0f
|
4
|
+
data.tar.gz: 4b492ee8bc38517fcd1c2e138631e95301ea655f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a0b504aa4bfdd699fe1c7bb5d2e42096329d503fe439878a13c9bbe6239f30de74a3c68fbb4d1d2309ec6f3b87a254117489f8d6d874c4d83e8b0daba00952a
|
7
|
+
data.tar.gz: ae23a4755c56670770efdcc4dfa1abf1fed22ef6b48ce954cf2d726908c9652d768571ee8a735eee79606ab0c8ad83c6991a90e753b2ff73fc427f3de6ef2539
|
data/lib/babl/nodes/constant.rb
CHANGED
@@ -5,6 +5,10 @@ require 'babl/utils'
|
|
5
5
|
module Babl
|
6
6
|
module Nodes
|
7
7
|
class Constant < Utils::Value.new(:value, :schema)
|
8
|
+
NULL = new(nil, Schema::Primitive::NULL)
|
9
|
+
TRUE = new(true, Schema::Primitive::TRUE)
|
10
|
+
FALSE = new(false, Schema::Primitive::FALSE)
|
11
|
+
|
8
12
|
def render(_frame)
|
9
13
|
value
|
10
14
|
end
|
data/lib/babl/nodes/each.rb
CHANGED
@@ -35,8 +35,9 @@ module Babl
|
|
35
35
|
raise Errors::RenderingError, "Not enumerable : #{collection.inspect}\n#{frame.formatted_stack}"
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
idx = -1
|
39
|
+
collection.map do |value|
|
40
|
+
frame.move_forward(value, idx += 1) do |new_frame|
|
40
41
|
node.render(new_frame)
|
41
42
|
end
|
42
43
|
end
|
data/lib/babl/nodes/with.rb
CHANGED
@@ -43,18 +43,31 @@ module Babl
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def render(frame)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
# When there is only 0 or 1 input node, we can avoid the allocation of an array
|
47
|
+
value =
|
48
|
+
case nodes.size
|
49
|
+
when 0
|
50
|
+
rescue_errors(frame) { block.call }
|
51
|
+
when 1
|
52
|
+
input = nodes.first.render(frame)
|
53
|
+
rescue_errors(frame) { block.call(input) }
|
54
|
+
else
|
55
|
+
inputs = nodes.map { |node| node.render(frame) }
|
56
|
+
rescue_errors(frame) { block.call(*inputs) }
|
57
|
+
end
|
53
58
|
|
54
59
|
frame.move_forward(value, :__block__) do |new_frame|
|
55
60
|
node.render(new_frame)
|
56
61
|
end
|
57
62
|
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def rescue_errors(frame)
|
67
|
+
yield
|
68
|
+
rescue StandardError => e
|
69
|
+
raise Errors::RenderingError, "#{e.message}\n" + frame.formatted_stack(:__block__), e.backtrace
|
70
|
+
end
|
58
71
|
end
|
59
72
|
end
|
60
73
|
end
|
@@ -11,11 +11,15 @@ module Babl
|
|
11
11
|
sanitized_val = Nodes::TerminalValue.instance.render_object(val)
|
12
12
|
|
13
13
|
case sanitized_val
|
14
|
-
when ::String, ::Numeric
|
14
|
+
when ::String, ::Numeric
|
15
15
|
frozen_val = sanitized_val.dup.freeze
|
16
|
-
construct_terminal {
|
17
|
-
|
18
|
-
}
|
16
|
+
construct_terminal { Nodes::Constant.new(frozen_val, Schema::Primitive.new(frozen_val)) }
|
17
|
+
when ::NilClass
|
18
|
+
construct_terminal { Nodes::Constant::NULL }
|
19
|
+
when ::TrueClass
|
20
|
+
construct_terminal { Nodes::Constant::TRUE }
|
21
|
+
when ::FalseClass
|
22
|
+
construct_terminal { Nodes::Constant::FALSE }
|
19
23
|
else call(sanitized_val)
|
20
24
|
end
|
21
25
|
rescue Errors::RenderingError => exception
|
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.5.
|
4
|
+
version: 0.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederic Terrazzoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
103
|
+
version: '0.58'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
110
|
+
version: '0.58'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: multi_json
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|