[flori/json] Overload kwargs in JSON.dump
https://github.com/flori/json/commit/936f280f9f
This commit is contained in:
parent
a22ed89438
commit
e6b35e8a6d
@ -615,13 +615,17 @@ module JSON
|
||||
if anIO and limit.nil?
|
||||
anIO = anIO.to_io if anIO.respond_to?(:to_io)
|
||||
unless anIO.respond_to?(:write)
|
||||
limit = anIO
|
||||
if kwargs.nil? and anIO.is_a?(Hash)
|
||||
kwargs = anIO
|
||||
else
|
||||
limit = anIO
|
||||
end
|
||||
anIO = nil
|
||||
end
|
||||
end
|
||||
opts = JSON.dump_default_options
|
||||
opts = opts.merge(:max_nesting => limit) if limit
|
||||
merge_dump_options(opts, **kwargs) if kwargs
|
||||
opts = merge_dump_options(opts, **kwargs) if kwargs
|
||||
result = generate(obj, opts)
|
||||
if anIO
|
||||
anIO.write result
|
||||
@ -641,7 +645,8 @@ module JSON
|
||||
private
|
||||
|
||||
def merge_dump_options(opts, strict: NOT_SET)
|
||||
opts[:strict] = strict if NOT_SET != strict
|
||||
opts = opts.merge(strict: strict) if NOT_SET != strict
|
||||
opts
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -66,6 +66,10 @@ EOT
|
||||
assert_equal '{"a":1,"b":2}', dump(a: 1, b: 2)
|
||||
end
|
||||
|
||||
def test_dump_strict
|
||||
assert_equal '{}', dump({}, strict: true)
|
||||
end
|
||||
|
||||
def test_generate_pretty
|
||||
json = pretty_generate({})
|
||||
assert_equal(<<'EOT'.chomp, json)
|
||||
|
Loading…
x
Reference in New Issue
Block a user