json 2.21.2 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +55 -1
- data/README.md +4 -84
- data/ext/json/ext/generator/generator.c +32 -38
- data/ext/json/ext/json.h +13 -0
- data/ext/json/ext/parser/parser.c +80 -84
- data/lib/json/common.rb +142 -401
- data/lib/json/ext/generator/state.rb +0 -27
- data/lib/json/ext.rb +0 -2
- data/lib/json/truffle_ruby/generator.rb +38 -80
- data/lib/json/version.rb +1 -1
- data/lib/json.rb +43 -295
- metadata +1 -17
- data/lib/json/add/bigdecimal.rb +0 -58
- data/lib/json/add/complex.rb +0 -51
- data/lib/json/add/core.rb +0 -13
- data/lib/json/add/date.rb +0 -54
- data/lib/json/add/date_time.rb +0 -67
- data/lib/json/add/exception.rb +0 -49
- data/lib/json/add/ostruct.rb +0 -54
- data/lib/json/add/range.rb +0 -54
- data/lib/json/add/rational.rb +0 -49
- data/lib/json/add/regexp.rb +0 -48
- data/lib/json/add/set.rb +0 -48
- data/lib/json/add/string.rb +0 -35
- data/lib/json/add/struct.rb +0 -52
- data/lib/json/add/symbol.rb +0 -52
- data/lib/json/add/time.rb +0 -52
- data/lib/json/generic_object.rb +0 -67
|
@@ -71,33 +71,6 @@ module JSON
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
alias_method :to_hash, :to_h
|
|
74
|
-
|
|
75
|
-
# call-seq: [](name)
|
|
76
|
-
#
|
|
77
|
-
# Returns the value returned by method +name+.
|
|
78
|
-
def [](name)
|
|
79
|
-
::JSON.deprecation_warning("JSON::State#[] is deprecated and will be removed in json 3.0.0")
|
|
80
|
-
|
|
81
|
-
if respond_to?(name)
|
|
82
|
-
__send__(name)
|
|
83
|
-
else
|
|
84
|
-
instance_variable_get("@#{name}") if
|
|
85
|
-
instance_variables.include?("@#{name}".to_sym) # avoid warning
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# call-seq: []=(name, value)
|
|
90
|
-
#
|
|
91
|
-
# Sets the attribute name to value.
|
|
92
|
-
def []=(name, value)
|
|
93
|
-
::JSON.deprecation_warning("JSON::State#[]= is deprecated and will be removed in json 3.0.0")
|
|
94
|
-
|
|
95
|
-
if respond_to?(name_writer = "#{name}=")
|
|
96
|
-
__send__ name_writer, value
|
|
97
|
-
else
|
|
98
|
-
instance_variable_set "@#{name}", value
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
74
|
end
|
|
102
75
|
end
|
|
103
76
|
end
|
data/lib/json/ext.rb
CHANGED
|
@@ -167,7 +167,8 @@ module JSON
|
|
|
167
167
|
@strict = false
|
|
168
168
|
@max_nesting = 100
|
|
169
169
|
@sort_keys = false
|
|
170
|
-
|
|
170
|
+
@allow_duplicate_key = false
|
|
171
|
+
_configure(**opts) if opts
|
|
171
172
|
end
|
|
172
173
|
|
|
173
174
|
# This string is used to indent levels in the JSON text.
|
|
@@ -289,65 +290,48 @@ module JSON
|
|
|
289
290
|
|
|
290
291
|
# Configure this State instance with the Hash _opts_, and return
|
|
291
292
|
# itself.
|
|
292
|
-
def configure(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
if opts[:depth]&.negative?
|
|
302
|
-
raise ArgumentError, "depth must be >= 0 (got #{opts[:depth]})"
|
|
303
|
-
end
|
|
304
|
-
|
|
305
|
-
opts.each do |key, value|
|
|
306
|
-
instance_variable_set "@#{key}", value
|
|
293
|
+
def configure(options)
|
|
294
|
+
unless Hash == options
|
|
295
|
+
if options.respond_to?(:to_hash)
|
|
296
|
+
options = options.to_hash
|
|
297
|
+
elsif options.respond_to?(:to_h)
|
|
298
|
+
options = options.to_h
|
|
299
|
+
end
|
|
307
300
|
end
|
|
301
|
+
_configure(**options)
|
|
302
|
+
end
|
|
303
|
+
alias merge configure
|
|
308
304
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
@as_json = opts[:as_json].to_proc if opts[:as_json]
|
|
317
|
-
@ascii_only = opts[:ascii_only] if opts.key?(:ascii_only)
|
|
318
|
-
self.sort_keys = opts[:sort_keys] if opts.key?(:sort_keys)
|
|
319
|
-
@depth = opts[:depth] || 0
|
|
320
|
-
@buffer_initial_length ||= opts[:buffer_initial_length]
|
|
321
|
-
|
|
322
|
-
@script_safe = if opts.key?(:script_safe)
|
|
323
|
-
!!opts[:script_safe]
|
|
324
|
-
elsif opts.key?(:escape_slash)
|
|
325
|
-
!!opts[:escape_slash]
|
|
326
|
-
else
|
|
327
|
-
false
|
|
305
|
+
private def _configure(
|
|
306
|
+
indent: '', space: '', space_before: '', object_nl: '', array_nl: '', allow_nan: false,
|
|
307
|
+
as_json: false, ascii_only: false, sort_keys: false, depth: 0, buffer_initial_length: 1024,
|
|
308
|
+
allow_duplicate_key: false, script_safe: false, strict: false, max_nesting: 100
|
|
309
|
+
)
|
|
310
|
+
if depth.negative?
|
|
311
|
+
raise ArgumentError, "depth must be >= 0 (got #{depth})"
|
|
328
312
|
end
|
|
329
313
|
|
|
330
|
-
if
|
|
331
|
-
|
|
332
|
-
else
|
|
333
|
-
@allow_duplicate_key = nil # nil is deprecation
|
|
314
|
+
if max_nesting && !(Integer === max_nesting)
|
|
315
|
+
raise TypeError, ":max_nesting must be `false` or an Integer, got: #{max_nesting.class}"
|
|
334
316
|
end
|
|
335
317
|
|
|
336
|
-
@
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
318
|
+
@indent = indent || ''
|
|
319
|
+
@space = space || ''
|
|
320
|
+
@space_before = space_before || ''
|
|
321
|
+
@object_nl = object_nl || ''
|
|
322
|
+
@array_nl = array_nl || ''
|
|
323
|
+
@allow_nan = allow_nan || false
|
|
324
|
+
@as_json = as_json || false
|
|
325
|
+
@ascii_only = ascii_only || false
|
|
326
|
+
self.sort_keys = sort_keys
|
|
327
|
+
@depth = depth
|
|
328
|
+
@buffer_initial_length = buffer_initial_length
|
|
329
|
+
@allow_duplicate_key = allow_duplicate_key
|
|
330
|
+
@script_safe = script_safe
|
|
331
|
+
@strict = strict
|
|
332
|
+
@max_nesting = max_nesting || 0
|
|
348
333
|
self
|
|
349
334
|
end
|
|
350
|
-
alias merge configure
|
|
351
335
|
|
|
352
336
|
def allow_duplicate_key? # :nodoc:
|
|
353
337
|
@allow_duplicate_key
|
|
@@ -362,10 +346,6 @@ module JSON
|
|
|
362
346
|
result[key.to_sym] = instance_variable_get(iv)
|
|
363
347
|
end
|
|
364
348
|
|
|
365
|
-
if result[:allow_duplicate_key].nil?
|
|
366
|
-
result.delete(:allow_duplicate_key)
|
|
367
|
-
end
|
|
368
|
-
|
|
369
349
|
result
|
|
370
350
|
end
|
|
371
351
|
|
|
@@ -416,7 +396,7 @@ module JSON
|
|
|
416
396
|
else
|
|
417
397
|
if key_type && !@allow_duplicate_key && key_type != k.class
|
|
418
398
|
key_type = nil # stop checking
|
|
419
|
-
JSON.send(:on_mixed_keys_hash, obj
|
|
399
|
+
JSON.send(:on_mixed_keys_hash, obj)
|
|
420
400
|
end
|
|
421
401
|
buf << ','
|
|
422
402
|
end
|
|
@@ -483,28 +463,6 @@ module JSON
|
|
|
483
463
|
end
|
|
484
464
|
buf << '"'
|
|
485
465
|
end
|
|
486
|
-
|
|
487
|
-
# Return the value returned by method +name+.
|
|
488
|
-
def [](name)
|
|
489
|
-
::JSON.deprecation_warning("JSON::State#[] is deprecated and will be removed in json 3.0.0")
|
|
490
|
-
|
|
491
|
-
if respond_to?(name)
|
|
492
|
-
__send__(name)
|
|
493
|
-
else
|
|
494
|
-
instance_variable_get("@#{name}") if
|
|
495
|
-
instance_variables.include?("@#{name}".to_sym) # avoid warning
|
|
496
|
-
end
|
|
497
|
-
end
|
|
498
|
-
|
|
499
|
-
def []=(name, value)
|
|
500
|
-
::JSON.deprecation_warning("JSON::State#[]= is deprecated and will be removed in json 3.0.0")
|
|
501
|
-
|
|
502
|
-
if respond_to?(name_writer = "#{name}=")
|
|
503
|
-
__send__ name_writer, value
|
|
504
|
-
else
|
|
505
|
-
instance_variable_set "@#{name}", value
|
|
506
|
-
end
|
|
507
|
-
end
|
|
508
466
|
end
|
|
509
467
|
|
|
510
468
|
module GeneratorMethods
|
|
@@ -569,7 +527,7 @@ module JSON
|
|
|
569
527
|
else
|
|
570
528
|
if key_type && !state.allow_duplicate_key? && key_type != key.class
|
|
571
529
|
key_type = nil # stop checking
|
|
572
|
-
JSON.send(:on_mixed_keys_hash, self
|
|
530
|
+
JSON.send(:on_mixed_keys_hash, self)
|
|
573
531
|
end
|
|
574
532
|
result << delim
|
|
575
533
|
end
|
data/lib/json/version.rb
CHANGED