diff options
author | Ryan Davis <ryand-ruby@zenspider.com> | 2019-11-22 14:53:04 -0800 |
---|---|---|
committer | Ryan Davis <ryand-ruby@zenspider.com> | 2019-11-27 14:54:39 -0800 |
commit | 19da336333e63dc9dde7baea47b179e162b7568e (patch) | |
tree | ce10de9e526ed1397bd8cd8b71f32b42eec27e19 | |
parent | 8d8e1aa70297d55034e3f6a4ce2f32300294b2a4 (diff) | |
download | json-19da336333e63dc9dde7baea47b179e162b7568e.tar.gz |
Minor cleanup for ruby 2.7 warnings and failures.
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | lib/json/common.rb | 5 | ||||
-rw-r--r-- | lib/json/pure/parser.rb | 10 | ||||
-rw-r--r-- | tests/json_parser_test.rb | 2 |
4 files changed, 14 insertions, 4 deletions
diff --git a/.travis.yml b/.travis.yml index 1ac58d8..2962e9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ rvm: - 2.4 - 2.5 - 2.6 + - 2.7.0-preview2 - ruby-head - jruby matrix: diff --git a/lib/json/common.rb b/lib/json/common.rb index 7cc8529..05da9d0 100644 --- a/lib/json/common.rb +++ b/lib/json/common.rb @@ -153,7 +153,8 @@ module JSON # * *object_class*: Defaults to Hash # * *array_class*: Defaults to Array def parse(source, opts = {}) - Parser.new(source, opts).parse + opts ||= {} + Parser.new(source, **opts).parse end # Parse the JSON document _source_ into a Ruby data structure and return it. @@ -176,7 +177,7 @@ module JSON :max_nesting => false, :allow_nan => true }.merge(opts) - Parser.new(source, opts).parse + Parser.new(source, **opts).parse end # Generate a JSON document from the Ruby data structure _obj_ and return diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb index 3a6343b..5340296 100644 --- a/lib/json/pure/parser.rb +++ b/lib/json/pure/parser.rb @@ -197,7 +197,15 @@ module JSON def parse_value case when scan(FLOAT) - @decimal_class && @decimal_class.new(self[1]) || Float(self[1]) + if @decimal_class then + if @decimal_class == BigDecimal then + BigDecimal(self[1]) + else + @decimal_class.new(self[1]) || Float(self[1]) + end + else + Float(self[1]) + end when scan(INTEGER) Integer(self[1]) when scan(TRUE) diff --git a/tests/json_parser_test.rb b/tests/json_parser_test.rb index 5f454eb..452e177 100644 --- a/tests/json_parser_test.rb +++ b/tests/json_parser_test.rb @@ -111,7 +111,7 @@ class JSONParserTest < Test::Unit::TestCase def test_parse_bigdecimals assert_equal(BigDecimal, JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"].class) - assert_equal(BigDecimal.new("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] ) + assert_equal(BigDecimal("0.901234567890123456789E1"), JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] ) end if Array.method_defined?(:permutation) |