@@ -101,6 +101,29 @@ def create_pretty_state
101
101
102
102
# Sets or Returns the JSON generator state class that is used by JSON.
103
103
attr_accessor :state
104
+
105
+ private
106
+
107
+ def deprecated_singleton_attr_accessor ( *attrs )
108
+ args = RUBY_VERSION >= "3.0" ? ", category: :deprecated" : ""
109
+ attrs . each do |attr |
110
+ singleton_class . class_eval <<~RUBY
111
+ def #{ attr }
112
+ warn "JSON.#{ attr } is deprecated and will be removed in json 3.0.0", uplevel: 1 #{ args }
113
+ @#{ attr }
114
+ end
115
+
116
+ def #{ attr } =(val)
117
+ warn "JSON.#{ attr } = is deprecated and will be removed in json 3.0.0", uplevel: 1 #{ args }
118
+ @#{ attr } = val
119
+ end
120
+
121
+ def _#{ attr }
122
+ @#{ attr }
123
+ end
124
+ RUBY
125
+ end
126
+ end
104
127
end
105
128
106
129
# Sets create identifier, which is used to decide if the _json_create_
@@ -424,28 +447,26 @@ def pretty_generate(obj, opts = nil)
424
447
module_function :pretty_unparse
425
448
# :startdoc:
426
449
427
- class << self
428
- # Sets or returns default options for the JSON.unsafe_load method.
429
- # Initially:
430
- # opts = JSON.load_default_options
431
- # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
432
- attr_accessor :unsafe_load_default_options
433
- end
434
- self . unsafe_load_default_options = {
450
+ # Sets or returns default options for the JSON.unsafe_load method.
451
+ # Initially:
452
+ # opts = JSON.load_default_options
453
+ # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
454
+ deprecated_singleton_attr_accessor :unsafe_load_default_options
455
+
456
+ @unsafe_load_default_options = {
435
457
:max_nesting => false ,
436
458
:allow_nan => true ,
437
459
:allow_blank => true ,
438
460
:create_additions => true ,
439
461
}
440
462
441
- class << self
442
- # Sets or returns default options for the JSON.load method.
443
- # Initially:
444
- # opts = JSON.load_default_options
445
- # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
446
- attr_accessor :load_default_options
447
- end
448
- self . load_default_options = {
463
+ # Sets or returns default options for the JSON.load method.
464
+ # Initially:
465
+ # opts = JSON.load_default_options
466
+ # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
467
+ deprecated_singleton_attr_accessor :load_default_options
468
+
469
+ @load_default_options = {
449
470
:allow_nan => true ,
450
471
:allow_blank => true ,
451
472
:create_additions => nil ,
@@ -581,9 +602,9 @@ class << self
581
602
#
582
603
def unsafe_load ( source , proc = nil , options = nil )
583
604
opts = if options . nil?
584
- unsafe_load_default_options
605
+ _unsafe_load_default_options
585
606
else
586
- unsafe_load_default_options . merge ( options )
607
+ _unsafe_load_default_options . merge ( options )
587
608
end
588
609
589
610
unless source . is_a? ( String )
@@ -741,9 +762,9 @@ def unsafe_load(source, proc = nil, options = nil)
741
762
#
742
763
def load ( source , proc = nil , options = nil )
743
764
opts = if options . nil?
744
- load_default_options
765
+ _load_default_options
745
766
else
746
- load_default_options . merge ( options )
767
+ _load_default_options . merge ( options )
747
768
end
748
769
749
770
unless source . is_a? ( String )
@@ -781,14 +802,12 @@ def recurse_proc(result, &proc) # :nodoc:
781
802
alias restore load
782
803
module_function :restore
783
804
784
- class << self
785
- # Sets or returns the default options for the JSON.dump method.
786
- # Initially:
787
- # opts = JSON.dump_default_options
788
- # opts # => {:max_nesting=>false, :allow_nan=>true}
789
- attr_accessor :dump_default_options
790
- end
791
- self . dump_default_options = {
805
+ # Sets or returns the default options for the JSON.dump method.
806
+ # Initially:
807
+ # opts = JSON.dump_default_options
808
+ # opts # => {:max_nesting=>false, :allow_nan=>true}
809
+ deprecated_singleton_attr_accessor :dump_default_options
810
+ @dump_default_options = {
792
811
:max_nesting => false ,
793
812
:allow_nan => true ,
794
813
}
@@ -841,7 +860,7 @@ def dump(obj, anIO = nil, limit = nil, kwargs = nil)
841
860
end
842
861
end
843
862
844
- opts = JSON . dump_default_options
863
+ opts = JSON . _dump_default_options
845
864
opts = opts . merge ( :max_nesting => limit ) if limit
846
865
opts = opts . merge ( kwargs ) if kwargs
847
866
0 commit comments