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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dec8dc9599589b5511a86e459172421352ab0b44
4
- data.tar.gz: 966a0cc10f570cdb0078b97092da6aa2778644f5
3
+ metadata.gz: 329322cf3fa5b7e83cad065409efcd8889146f0f
4
+ data.tar.gz: 4b492ee8bc38517fcd1c2e138631e95301ea655f
5
5
  SHA512:
6
- metadata.gz: 43e8e8ea87c8edea34b825faa3f0bc35104e3485fda08a9a6096f57e14d2dfa1a387e533ebfbf75f4597e29ac0eb0c92755e0fbcefb96fa7c62fb7a916b25bc5
7
- data.tar.gz: 9341db37ffed4346b12c2d9487aa6c094ae3b4125ea635b7854c0427a8cd1e133e7ace096cadcfa384f5838ebb52704285d3e9d2053be9fb70a8e10aabf8be2d
6
+ metadata.gz: 3a0b504aa4bfdd699fe1c7bb5d2e42096329d503fe439878a13c9bbe6239f30de74a3c68fbb4d1d2309ec6f3b87a254117489f8d6d874c4d83e8b0daba00952a
7
+ data.tar.gz: ae23a4755c56670770efdcc4dfa1abf1fed22ef6b48ce954cf2d726908c9652d768571ee8a735eee79606ab0c8ad83c6991a90e753b2ff73fc427f3de6ef2539
@@ -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
@@ -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
- collection.map.with_index do |value, idx|
39
- frame.move_forward(value, idx) do |new_frame|
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
@@ -43,18 +43,31 @@ module Babl
43
43
  end
44
44
 
45
45
  def render(frame)
46
- values = nodes.map { |n| n.render(frame) }
47
-
48
- value = begin
49
- block.call(*values)
50
- rescue StandardError => e
51
- raise Errors::RenderingError, "#{e.message}\n" + frame.formatted_stack(:__block__), e.backtrace
52
- end
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, ::NilClass, ::TrueClass, ::FalseClass
14
+ when ::String, ::Numeric
15
15
  frozen_val = sanitized_val.dup.freeze
16
- construct_terminal {
17
- Nodes::Constant.new(frozen_val, Schema::Primitive.new(frozen_val))
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Babl
3
- VERSION = '0.5.8'
3
+ VERSION = '0.5.9'
4
4
  end
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.8
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-07-17 00:00:00.000000000 Z
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.57'
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.57'
110
+ version: '0.58'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: multi_json
113
113
  requirement: !ruby/object:Gem::Requirement