babl-json 0.3.0 → 0.3.1

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: 871e1b12d52df06d65775112f9ff0f13aa42dfab
4
- data.tar.gz: 72c86a1b58a6469be3dddbdf01e49b087abee471
3
+ metadata.gz: 4f2f029a652582cac66cd36e290f5cda18388ed5
4
+ data.tar.gz: 44aabe9259b3b4c91147578e2a0c4528a45f3248
5
5
  SHA512:
6
- metadata.gz: b32c9e4b2eec50edd2f427b4e05c7e6bc45220d22bfbef3c7d1f87387b6487f63068001f9385b82becaad66f0a9725e65d81e9eff321430544b251f4d4ecda41
7
- data.tar.gz: 2d80756fd150ed750c5639a0a65187dba8ae4c58f64c0dfde2d2e80d859db1897322f1b126573522a799ce6b1b74a46aa63db7318632a0f27d43b18a6f7f79fb
6
+ metadata.gz: 0d6199f5bd49ba5e467902e79ca254cf97dba01b21d92141ab451786c0fdba79a5701743f2c4f2766a9928924dd91bd8073c17f0d1542c83f3fbb047d852db31
7
+ data.tar.gz: 25c6e56a337e7eb69bd085a3454ef1183dbe489e372f9970be1ec1d8591b0b2df959d6790d69f3ac269c4735444ab5022233d635fe58d9ad6ea5aa922c035173
@@ -32,10 +32,11 @@ module Babl
32
32
 
33
33
  def render_object(obj, stack = nil)
34
34
  case obj
35
- when ::String, ::Numeric, ::NilClass, ::TrueClass, ::FalseClass then obj
35
+ when ::String, ::Integer, ::NilClass, ::TrueClass, ::FalseClass then obj
36
+ when ::Numeric then obj.to_f
37
+ when ::Symbol then obj.to_s
36
38
  when ::Hash then render_hash(obj, stack || [])
37
39
  when ::Array then render_array(obj, stack || [])
38
- when ::Symbol then obj.to_s
39
40
  else raise TerminalValueError.new("Only primitives can be serialized: #{obj}", stack || [])
40
41
  end
41
42
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'babl/utils'
3
3
  require 'babl/schema'
4
+ require 'babl/nodes/terminal_value'
4
5
 
5
6
  module Babl
6
7
  module Nodes
@@ -20,7 +21,9 @@ module Babl
20
21
 
21
22
  def render(ctx)
22
23
  value = ctx.object
23
- return value if schema.classes.any? { |clazz| clazz === value }
24
+ if schema.classes.any? { |clazz| clazz === value }
25
+ return ::Numeric === value ? TerminalValue.instance.render_object(value) : value
26
+ end
24
27
  raise Errors::RenderingError, "Expected type '#{schema.type}': #{value}\n#{ctx.formatted_stack}"
25
28
  end
26
29
 
@@ -8,10 +8,12 @@ module Babl
8
8
  module DSL
9
9
  # Create a static JSON value
10
10
  def static(val)
11
- case val
11
+ sanitized_val = Nodes::TerminalValue.instance.render_object(val)
12
+
13
+ case sanitized_val
12
14
  when ::String, ::Numeric, ::NilClass, ::TrueClass, ::FalseClass
13
- construct_terminal { Nodes::Constant.new(val, Schema::Primitive.new(val)) }
14
- else call(Nodes::TerminalValue.instance.render_object(val))
15
+ construct_terminal { Nodes::Constant.new(sanitized_val, Schema::Primitive.new(sanitized_val)) }
16
+ else call(sanitized_val)
15
17
  end
16
18
  rescue Errors::RenderingError => exception
17
19
  raise Errors::InvalidTemplate, exception.message
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Babl
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babl-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederic Terrazzoni