sorbet-result 1.1.0 → 1.3.0
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/.ruby-version +1 -1
- data/.standard.yml +1 -1
- data/CHANGELOG.md +17 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +85 -68
- data/README.md +4 -4
- data/lib/typed/no_payload_on_failure_error.rb +8 -3
- data/lib/typed/result.rb +33 -3
- data/sorbet/rbi/gems/{ast@2.4.2.rbi → ast@2.4.3.rbi} +4 -3
- data/sorbet/rbi/gems/benchmark@0.4.1.rbi +619 -0
- data/sorbet/rbi/gems/cgi@0.5.0.rbi +2961 -0
- data/sorbet/rbi/gems/date@3.4.1.rbi +75 -0
- data/sorbet/rbi/gems/erb@4.0.4.rbi +910 -0
- data/sorbet/rbi/gems/{erubi@1.12.0.rbi → erubi@1.13.1.rbi} +25 -15
- data/sorbet/rbi/gems/{io-console@0.7.2.rbi → io-console@0.8.0.rbi} +1 -0
- data/sorbet/rbi/gems/{json@2.7.1.rbi → json@2.12.2.rbi} +736 -238
- data/sorbet/rbi/gems/{language_server-protocol@3.17.0.3.rbi → language_server-protocol@3.17.0.5.rbi} +12 -5
- data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +1 -0
- data/sorbet/rbi/gems/logger@1.7.0.rbi +963 -0
- data/sorbet/rbi/gems/{minitest@5.22.2.rbi → minitest@5.25.5.rbi} +326 -308
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +1 -0
- data/sorbet/rbi/gems/{parallel@1.24.0.rbi → parallel@1.27.0.rbi} +32 -21
- data/sorbet/rbi/gems/{parser@3.3.0.5.rbi → parser@3.3.8.0.rbi} +448 -385
- data/sorbet/rbi/gems/pp@0.6.2.rbi +368 -0
- data/sorbet/rbi/gems/prettyprint@0.2.0.rbi +477 -0
- data/sorbet/rbi/gems/prism@1.4.0.rbi +41732 -0
- data/sorbet/rbi/gems/{psych@5.1.2.rbi → psych@5.2.6.rbi} +974 -236
- data/sorbet/rbi/gems/{racc@1.7.3.rbi → racc@1.8.1.rbi} +38 -33
- data/sorbet/rbi/gems/rainbow@3.1.1.rbi +1 -0
- data/sorbet/rbi/gems/{rake@13.1.0.rbi → rake@13.3.0.rbi} +62 -58
- data/sorbet/rbi/gems/rbi@0.3.6.rbi +6893 -0
- data/sorbet/rbi/gems/rbs@3.9.4.rbi +6976 -0
- data/sorbet/rbi/gems/{regexp_parser@2.9.0.rbi → regexp_parser@2.10.0.rbi} +196 -172
- data/sorbet/rbi/gems/{reline@0.4.2.rbi → reline@0.6.1.rbi} +1 -0
- data/sorbet/rbi/gems/{rubocop-ast@1.30.0.rbi → rubocop-ast@1.45.1.rbi} +1673 -958
- data/sorbet/rbi/gems/{rubocop-performance@1.20.2.rbi → rubocop-performance@1.25.0.rbi} +1 -0
- data/sorbet/rbi/gems/{rubocop-sorbet@0.7.7.rbi → rubocop-sorbet@0.9.0.rbi} +1 -0
- data/sorbet/rbi/gems/{rubocop@1.60.2.rbi → rubocop@1.75.8.rbi} +9990 -5267
- data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1 -0
- data/sorbet/rbi/gems/spoom@1.6.1.rbi +7274 -0
- data/sorbet/rbi/gems/standard-custom@1.0.2.rbi +1 -0
- data/sorbet/rbi/gems/{standard-performance@1.3.1.rbi → standard-performance@1.8.0.rbi} +1 -0
- data/sorbet/rbi/gems/{standard-sorbet@0.0.2.rbi → standard-sorbet@0.0.3.rbi} +1 -0
- data/sorbet/rbi/gems/{standard@1.34.0.rbi → standard@1.50.0.rbi} +182 -97
- data/sorbet/rbi/gems/{stringio@3.1.0.rbi → stringio@3.1.7.rbi} +1 -0
- data/sorbet/rbi/gems/{tapioca@0.12.0.rbi → tapioca@0.16.11.rbi} +489 -364
- data/sorbet/rbi/gems/{thor@1.3.0.rbi → thor@1.3.2.rbi} +114 -81
- data/sorbet/rbi/gems/unicode-display_width@3.1.4.rbi +132 -0
- data/sorbet/rbi/gems/unicode-emoji@4.0.4.rbi +251 -0
- data/sorbet/rbi/gems/{yard-sorbet@0.8.1.rbi → yard-sorbet@0.9.0.rbi} +36 -29
- data/sorbet/rbi/gems/{yard@0.9.34.rbi → yard@0.9.37.rbi} +430 -270
- metadata +46 -55
- data/.tool-versions +0 -1
- data/sorbet/rbi/gems/prettier_print@1.2.1.rbi +0 -951
- data/sorbet/rbi/gems/prism@0.24.0.rbi +0 -31040
- data/sorbet/rbi/gems/rbi@0.1.9.rbi +0 -3006
- data/sorbet/rbi/gems/rexml@3.2.6.rbi +0 -4781
- data/sorbet/rbi/gems/spoom@1.2.4.rbi +0 -3777
- data/sorbet/rbi/gems/syntax_tree@6.2.0.rbi +0 -23133
- data/sorbet/rbi/gems/unicode-display_width@2.5.0.rbi +0 -65
@@ -4,17 +4,27 @@
|
|
4
4
|
# This is an autogenerated file for types exported from the `json` gem.
|
5
5
|
# Please instead update this file by running `bin/tapioca gem json`.
|
6
6
|
|
7
|
-
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
|
8
|
+
class Array
|
9
|
+
include ::Enumerable
|
10
|
+
include ::JSON::Ext::Generator::GeneratorMethods::Array
|
11
|
+
end
|
12
|
+
|
13
|
+
class FalseClass
|
14
|
+
include ::JSON::Ext::Generator::GeneratorMethods::FalseClass
|
15
|
+
end
|
16
|
+
|
17
|
+
class Float < ::Numeric
|
18
|
+
include ::JSON::Ext::Generator::GeneratorMethods::Float
|
19
|
+
end
|
20
|
+
|
21
|
+
class Hash
|
22
|
+
include ::Enumerable
|
23
|
+
include ::JSON::Ext::Generator::GeneratorMethods::Hash
|
24
|
+
end
|
25
|
+
|
26
|
+
class Integer < ::Numeric
|
27
|
+
include ::JSON::Ext::Generator::GeneratorMethods::Integer
|
18
28
|
end
|
19
29
|
|
20
30
|
# = JavaScript \Object Notation (\JSON)
|
@@ -393,13 +403,13 @@ end
|
|
393
403
|
# json1 = JSON.generate(ruby)
|
394
404
|
# ruby1 = JSON.parse(json1, create_additions: true)
|
395
405
|
# # Make a nice display.
|
396
|
-
# display =
|
397
|
-
#
|
398
|
-
#
|
399
|
-
#
|
400
|
-
#
|
401
|
-
#
|
402
|
-
#
|
406
|
+
# display = <<~EOT
|
407
|
+
# Generated JSON:
|
408
|
+
# Without addition: #{json0} (#{json0.class})
|
409
|
+
# With addition: #{json1} (#{json1.class})
|
410
|
+
# Parsed JSON:
|
411
|
+
# Without addition: #{ruby0.inspect} (#{ruby0.class})
|
412
|
+
# With addition: #{ruby1.inspect} (#{ruby1.class})
|
403
413
|
# EOT
|
404
414
|
# puts display
|
405
415
|
#
|
@@ -577,13 +587,13 @@ end
|
|
577
587
|
# json1 = JSON.generate(foo1)
|
578
588
|
# obj1 = JSON.parse(json1, create_additions: true)
|
579
589
|
# # Make a nice display.
|
580
|
-
# display =
|
581
|
-
#
|
582
|
-
#
|
583
|
-
#
|
584
|
-
#
|
585
|
-
#
|
586
|
-
#
|
590
|
+
# display = <<~EOT
|
591
|
+
# Generated JSON:
|
592
|
+
# Without custom addition: #{json0} (#{json0.class})
|
593
|
+
# With custom addition: #{json1} (#{json1.class})
|
594
|
+
# Parsed JSON:
|
595
|
+
# Without custom addition: #{obj0.inspect} (#{obj0.class})
|
596
|
+
# With custom addition: #{obj1.inspect} (#{obj1.class})
|
587
597
|
# EOT
|
588
598
|
# puts display
|
589
599
|
#
|
@@ -595,6 +605,8 @@ end
|
|
595
605
|
# Parsed JSON:
|
596
606
|
# Without custom addition: "#<Foo:0x0000000006534e80>" (String)
|
597
607
|
# With custom addition: #<Foo:0x0000000006473bb8 @bar=0, @baz=1> (Foo)
|
608
|
+
#
|
609
|
+
# source://json//lib/json/version.rb#3
|
598
610
|
module JSON
|
599
611
|
private
|
600
612
|
|
@@ -626,7 +638,7 @@ module JSON
|
|
626
638
|
# Output:
|
627
639
|
# {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
|
628
640
|
#
|
629
|
-
# source://json//json/common.rb#
|
641
|
+
# source://json//lib/json/common.rb#892
|
630
642
|
def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
|
631
643
|
|
632
644
|
# :call-seq:
|
@@ -643,14 +655,11 @@ module JSON
|
|
643
655
|
# # Raises SystemStackError (stack level too deep):
|
644
656
|
# JSON.fast_generate(a)
|
645
657
|
#
|
646
|
-
# source://json//json/common.rb#
|
658
|
+
# source://json//lib/json/common.rb#445
|
647
659
|
def fast_generate(obj, opts = T.unsafe(nil)); end
|
648
660
|
|
649
|
-
#
|
650
|
-
|
651
|
-
#
|
652
|
-
# source://json//json/common.rb#328
|
653
|
-
def fast_unparse(obj, opts = T.unsafe(nil)); end
|
661
|
+
# source://json//lib/json/common.rb#937
|
662
|
+
def fast_unparse(*_arg0, **_arg1, &_arg2); end
|
654
663
|
|
655
664
|
# :call-seq:
|
656
665
|
# JSON.generate(obj, opts = nil) -> new_string
|
@@ -688,7 +697,7 @@ module JSON
|
|
688
697
|
# # Raises JSON::NestingError (nesting of 100 is too deep):
|
689
698
|
# JSON.generate(a)
|
690
699
|
#
|
691
|
-
# source://json//json/common.rb#
|
700
|
+
# source://json//lib/json/common.rb#424
|
692
701
|
def generate(obj, opts = T.unsafe(nil)); end
|
693
702
|
|
694
703
|
# :call-seq:
|
@@ -696,6 +705,16 @@ module JSON
|
|
696
705
|
#
|
697
706
|
# Returns the Ruby objects created by parsing the given +source+.
|
698
707
|
#
|
708
|
+
# BEWARE: This method is meant to serialise data from trusted user input,
|
709
|
+
# like from your own database server or clients under your control, it could
|
710
|
+
# be dangerous to allow untrusted users to pass JSON sources into it.
|
711
|
+
# If you must use it, use JSON.unsafe_load instead to make it clear.
|
712
|
+
#
|
713
|
+
# Since JSON version 2.8.0, `load` emits a deprecation warning when a
|
714
|
+
# non native type is deserialized, without `create_additions` being explicitly
|
715
|
+
# enabled, and in JSON version 3.0, `load` will have `create_additions` disabled
|
716
|
+
# by default.
|
717
|
+
#
|
699
718
|
# - Argument +source+ must be, or be convertible to, a \String:
|
700
719
|
# - If +source+ responds to instance method +to_str+,
|
701
720
|
# <tt>source.to_str</tt> becomes the source.
|
@@ -710,9 +729,6 @@ module JSON
|
|
710
729
|
# - Argument +proc+, if given, must be a \Proc that accepts one argument.
|
711
730
|
# It will be called recursively with each result (depth-first order).
|
712
731
|
# See details below.
|
713
|
-
# BEWARE: This method is meant to serialise data from trusted user input,
|
714
|
-
# like from your own database server or clients under your control, it could
|
715
|
-
# be dangerous to allow untrusted users to pass JSON sources into it.
|
716
732
|
# - Argument +opts+, if given, contains a \Hash of options for the parsing.
|
717
733
|
# See {Parsing Options}[#module-JSON-label-Parsing+Options].
|
718
734
|
# The default options can be changed via method JSON.load_default_options=.
|
@@ -723,17 +739,17 @@ module JSON
|
|
723
739
|
# <tt>parse(source, opts)</tt>; see #parse.
|
724
740
|
#
|
725
741
|
# Source for following examples:
|
726
|
-
# source =
|
727
|
-
#
|
728
|
-
#
|
729
|
-
#
|
730
|
-
#
|
731
|
-
#
|
732
|
-
#
|
733
|
-
#
|
734
|
-
#
|
735
|
-
#
|
736
|
-
#
|
742
|
+
# source = <<~JSON
|
743
|
+
# {
|
744
|
+
# "name": "Dave",
|
745
|
+
# "age" :40,
|
746
|
+
# "hats": [
|
747
|
+
# "Cattleman's",
|
748
|
+
# "Panama",
|
749
|
+
# "Tophat"
|
750
|
+
# ]
|
751
|
+
# }
|
752
|
+
# JSON
|
737
753
|
#
|
738
754
|
# Load a \String:
|
739
755
|
# ruby = JSON.load(source)
|
@@ -819,7 +835,7 @@ module JSON
|
|
819
835
|
# #<Admin:0x00000000064c41f8
|
820
836
|
# @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
|
821
837
|
#
|
822
|
-
# source://json//json/common.rb#
|
838
|
+
# source://json//lib/json/common.rb#826
|
823
839
|
def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
|
824
840
|
|
825
841
|
# :call-seq:
|
@@ -830,7 +846,7 @@ module JSON
|
|
830
846
|
#
|
831
847
|
# See method #parse.
|
832
848
|
#
|
833
|
-
# source://json//json/common.rb#
|
849
|
+
# source://json//lib/json/common.rb#373
|
834
850
|
def load_file(filespec, opts = T.unsafe(nil)); end
|
835
851
|
|
836
852
|
# :call-seq:
|
@@ -841,12 +857,9 @@ module JSON
|
|
841
857
|
#
|
842
858
|
# See method #parse!
|
843
859
|
#
|
844
|
-
# source://json//json/common.rb#
|
860
|
+
# source://json//lib/json/common.rb#384
|
845
861
|
def load_file!(filespec, opts = T.unsafe(nil)); end
|
846
862
|
|
847
|
-
# source://json//json/common.rb#642
|
848
|
-
def merge_dump_options(opts, strict: T.unsafe(nil)); end
|
849
|
-
|
850
863
|
# :call-seq:
|
851
864
|
# JSON.parse(source, opts) -> object
|
852
865
|
#
|
@@ -875,17 +888,17 @@ module JSON
|
|
875
888
|
# {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
|
876
889
|
#
|
877
890
|
# Parses nested JSON objects:
|
878
|
-
# source =
|
879
|
-
#
|
880
|
-
#
|
881
|
-
#
|
882
|
-
#
|
883
|
-
#
|
884
|
-
#
|
885
|
-
#
|
886
|
-
#
|
887
|
-
#
|
888
|
-
#
|
891
|
+
# source = <<~JSON
|
892
|
+
# {
|
893
|
+
# "name": "Dave",
|
894
|
+
# "age" :40,
|
895
|
+
# "hats": [
|
896
|
+
# "Cattleman's",
|
897
|
+
# "Panama",
|
898
|
+
# "Tophat"
|
899
|
+
# ]
|
900
|
+
# }
|
901
|
+
# JSON
|
889
902
|
# ruby = JSON.parse(source)
|
890
903
|
# ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
891
904
|
#
|
@@ -895,7 +908,7 @@ module JSON
|
|
895
908
|
# # Raises JSON::ParserError (783: unexpected token at ''):
|
896
909
|
# JSON.parse('')
|
897
910
|
#
|
898
|
-
# source://json//json/common.rb#
|
911
|
+
# source://json//lib/json/common.rb#336
|
899
912
|
def parse(source, opts = T.unsafe(nil)); end
|
900
913
|
|
901
914
|
# :call-seq:
|
@@ -910,7 +923,7 @@ module JSON
|
|
910
923
|
# which disables checking for nesting depth.
|
911
924
|
# - Option +allow_nan+, if not provided, defaults to +true+.
|
912
925
|
#
|
913
|
-
# source://json//json/common.rb#
|
926
|
+
# source://json//lib/json/common.rb#358
|
914
927
|
def parse!(source, opts = T.unsafe(nil)); end
|
915
928
|
|
916
929
|
# :call-seq:
|
@@ -943,29 +956,153 @@ module JSON
|
|
943
956
|
# }
|
944
957
|
# }
|
945
958
|
#
|
946
|
-
# source://json//json/common.rb#
|
959
|
+
# source://json//lib/json/common.rb#492
|
947
960
|
def pretty_generate(obj, opts = T.unsafe(nil)); end
|
948
961
|
|
962
|
+
# source://json//lib/json/common.rb#947
|
963
|
+
def pretty_unparse(*_arg0, **_arg1, &_arg2); end
|
964
|
+
|
965
|
+
# source://json//lib/json/common.rb#957
|
966
|
+
def restore(*_arg0, **_arg1, &_arg2); end
|
967
|
+
|
949
968
|
# :stopdoc:
|
950
|
-
#
|
969
|
+
# All these were meant to be deprecated circa 2009, but were just set as undocumented
|
970
|
+
# so usage still exist in the wild.
|
951
971
|
#
|
952
|
-
# source://json//json/common.rb#
|
953
|
-
def
|
972
|
+
# source://json//lib/json/common.rb#927
|
973
|
+
def unparse(*_arg0, **_arg1, &_arg2); end
|
954
974
|
|
955
|
-
#
|
975
|
+
# :call-seq:
|
976
|
+
# JSON.unsafe_load(source, proc = nil, options = {}) -> object
|
956
977
|
#
|
957
|
-
# source
|
958
|
-
|
959
|
-
|
960
|
-
#
|
961
|
-
|
962
|
-
|
963
|
-
# :
|
964
|
-
#
|
965
|
-
#
|
978
|
+
# Returns the Ruby objects created by parsing the given +source+.
|
979
|
+
#
|
980
|
+
# BEWARE: This method is meant to serialise data from trusted user input,
|
981
|
+
# like from your own database server or clients under your control, it could
|
982
|
+
# be dangerous to allow untrusted users to pass JSON sources into it.
|
983
|
+
#
|
984
|
+
# - Argument +source+ must be, or be convertible to, a \String:
|
985
|
+
# - If +source+ responds to instance method +to_str+,
|
986
|
+
# <tt>source.to_str</tt> becomes the source.
|
987
|
+
# - If +source+ responds to instance method +to_io+,
|
988
|
+
# <tt>source.to_io.read</tt> becomes the source.
|
989
|
+
# - If +source+ responds to instance method +read+,
|
990
|
+
# <tt>source.read</tt> becomes the source.
|
991
|
+
# - If both of the following are true, source becomes the \String <tt>'null'</tt>:
|
992
|
+
# - Option +allow_blank+ specifies a truthy value.
|
993
|
+
# - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
|
994
|
+
# - Otherwise, +source+ remains the source.
|
995
|
+
# - Argument +proc+, if given, must be a \Proc that accepts one argument.
|
996
|
+
# It will be called recursively with each result (depth-first order).
|
997
|
+
# See details below.
|
998
|
+
# - Argument +opts+, if given, contains a \Hash of options for the parsing.
|
999
|
+
# See {Parsing Options}[#module-JSON-label-Parsing+Options].
|
1000
|
+
# The default options can be changed via method JSON.unsafe_load_default_options=.
|
1001
|
+
#
|
1002
|
+
# ---
|
1003
|
+
#
|
1004
|
+
# When no +proc+ is given, modifies +source+ as above and returns the result of
|
1005
|
+
# <tt>parse(source, opts)</tt>; see #parse.
|
1006
|
+
#
|
1007
|
+
# Source for following examples:
|
1008
|
+
# source = <<~JSON
|
1009
|
+
# {
|
1010
|
+
# "name": "Dave",
|
1011
|
+
# "age" :40,
|
1012
|
+
# "hats": [
|
1013
|
+
# "Cattleman's",
|
1014
|
+
# "Panama",
|
1015
|
+
# "Tophat"
|
1016
|
+
# ]
|
1017
|
+
# }
|
1018
|
+
# JSON
|
1019
|
+
#
|
1020
|
+
# Load a \String:
|
1021
|
+
# ruby = JSON.unsafe_load(source)
|
1022
|
+
# ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
1023
|
+
#
|
1024
|
+
# Load an \IO object:
|
1025
|
+
# require 'stringio'
|
1026
|
+
# object = JSON.unsafe_load(StringIO.new(source))
|
1027
|
+
# object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
1028
|
+
#
|
1029
|
+
# Load a \File object:
|
1030
|
+
# path = 't.json'
|
1031
|
+
# File.write(path, source)
|
1032
|
+
# File.open(path) do |file|
|
1033
|
+
# JSON.unsafe_load(file)
|
1034
|
+
# end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
1035
|
+
#
|
1036
|
+
# ---
|
1037
|
+
#
|
1038
|
+
# When +proc+ is given:
|
1039
|
+
# - Modifies +source+ as above.
|
1040
|
+
# - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
|
1041
|
+
# - Recursively calls <tt>proc(result)</tt>.
|
1042
|
+
# - Returns the final result.
|
1043
|
+
#
|
1044
|
+
# Example:
|
1045
|
+
# require 'json'
|
1046
|
+
#
|
1047
|
+
# # Some classes for the example.
|
1048
|
+
# class Base
|
1049
|
+
# def initialize(attributes)
|
1050
|
+
# @attributes = attributes
|
1051
|
+
# end
|
1052
|
+
# end
|
1053
|
+
# class User < Base; end
|
1054
|
+
# class Account < Base; end
|
1055
|
+
# class Admin < Base; end
|
1056
|
+
# # The JSON source.
|
1057
|
+
# json = <<-EOF
|
1058
|
+
# {
|
1059
|
+
# "users": [
|
1060
|
+
# {"type": "User", "username": "jane", "email": "jane@example.com"},
|
1061
|
+
# {"type": "User", "username": "john", "email": "john@example.com"}
|
1062
|
+
# ],
|
1063
|
+
# "accounts": [
|
1064
|
+
# {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
|
1065
|
+
# {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
|
1066
|
+
# ],
|
1067
|
+
# "admins": {"type": "Admin", "password": "0wn3d"}
|
1068
|
+
# }
|
1069
|
+
# EOF
|
1070
|
+
# # Deserializer method.
|
1071
|
+
# def deserialize_obj(obj, safe_types = %w(User Account Admin))
|
1072
|
+
# type = obj.is_a?(Hash) && obj["type"]
|
1073
|
+
# safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
|
1074
|
+
# end
|
1075
|
+
# # Call to JSON.unsafe_load
|
1076
|
+
# ruby = JSON.unsafe_load(json, proc {|obj|
|
1077
|
+
# case obj
|
1078
|
+
# when Hash
|
1079
|
+
# obj.each {|k, v| obj[k] = deserialize_obj v }
|
1080
|
+
# when Array
|
1081
|
+
# obj.map! {|v| deserialize_obj v }
|
1082
|
+
# end
|
1083
|
+
# })
|
1084
|
+
# pp ruby
|
1085
|
+
# Output:
|
1086
|
+
# {"users"=>
|
1087
|
+
# [#<User:0x00000000064c4c98
|
1088
|
+
# @attributes=
|
1089
|
+
# {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
|
1090
|
+
# #<User:0x00000000064c4bd0
|
1091
|
+
# @attributes=
|
1092
|
+
# {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
|
1093
|
+
# "accounts"=>
|
1094
|
+
# [{"account"=>
|
1095
|
+
# #<Account:0x00000000064c4928
|
1096
|
+
# @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
|
1097
|
+
# {"account"=>
|
1098
|
+
# #<Account:0x00000000064c4680
|
1099
|
+
# @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
|
1100
|
+
# "admins"=>
|
1101
|
+
# #<Admin:0x00000000064c41f8
|
1102
|
+
# @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
|
966
1103
|
#
|
967
|
-
# source://json//json/common.rb#
|
968
|
-
def
|
1104
|
+
# source://json//lib/json/common.rb#666
|
1105
|
+
def unsafe_load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
|
969
1106
|
|
970
1107
|
class << self
|
971
1108
|
# :call-seq:
|
@@ -980,34 +1117,28 @@ module JSON
|
|
980
1117
|
# ruby = [0, 1, nil]
|
981
1118
|
# JSON[ruby] # => '[0,1,null]'
|
982
1119
|
#
|
983
|
-
# source://json//json/common.rb#
|
1120
|
+
# source://json//lib/json/common.rb#126
|
984
1121
|
def [](object, opts = T.unsafe(nil)); end
|
985
1122
|
|
986
|
-
# source://json//json/common.rb#84
|
987
|
-
def create_fast_state; end
|
988
|
-
|
989
1123
|
# Returns the current create identifier.
|
990
1124
|
# See also JSON.create_id=.
|
991
1125
|
#
|
992
|
-
# source://json//json/common.rb#
|
1126
|
+
# source://json//lib/json/common.rb#219
|
993
1127
|
def create_id; end
|
994
1128
|
|
995
1129
|
# Sets create identifier, which is used to decide if the _json_create_
|
996
1130
|
# hook of a class should be called; initial value is +json_class+:
|
997
1131
|
# JSON.create_id # => 'json_class'
|
998
1132
|
#
|
999
|
-
# source://json//json/common.rb#
|
1133
|
+
# source://json//lib/json/common.rb#213
|
1000
1134
|
def create_id=(new_value); end
|
1001
1135
|
|
1002
|
-
# source://json//json/common.rb#94
|
1003
|
-
def create_pretty_state; end
|
1004
|
-
|
1005
1136
|
# Return the constant located at _path_. The format of _path_ has to be
|
1006
1137
|
# either ::A::B::C or A::B::C. In any case, A has to be located at the top
|
1007
1138
|
# level (absolute namespace path?). If there doesn't exist a constant at
|
1008
1139
|
# the given path, an ArgumentError is raised.
|
1009
1140
|
#
|
1010
|
-
# source://json//json/common.rb#
|
1141
|
+
# source://json//lib/json/common.rb#153
|
1011
1142
|
def deep_const_get(path); end
|
1012
1143
|
|
1013
1144
|
# :call-seq:
|
@@ -1038,25 +1169,9 @@ module JSON
|
|
1038
1169
|
# Output:
|
1039
1170
|
# {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
|
1040
1171
|
#
|
1041
|
-
# source://json//json/common.rb#
|
1172
|
+
# source://json//lib/json/common.rb#892
|
1042
1173
|
def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
|
1043
1174
|
|
1044
|
-
# Sets or returns the default options for the JSON.dump method.
|
1045
|
-
# Initially:
|
1046
|
-
# opts = JSON.dump_default_options
|
1047
|
-
# opts # => {:max_nesting=>false, :allow_nan=>true, :script_safe=>false}
|
1048
|
-
#
|
1049
|
-
# source://json//json/common.rb#579
|
1050
|
-
def dump_default_options; end
|
1051
|
-
|
1052
|
-
# Sets or returns the default options for the JSON.dump method.
|
1053
|
-
# Initially:
|
1054
|
-
# opts = JSON.dump_default_options
|
1055
|
-
# opts # => {:max_nesting=>false, :allow_nan=>true, :script_safe=>false}
|
1056
|
-
#
|
1057
|
-
# source://json//json/common.rb#579
|
1058
|
-
def dump_default_options=(_arg0); end
|
1059
|
-
|
1060
1175
|
# :call-seq:
|
1061
1176
|
# JSON.fast_generate(obj, opts) -> new_string
|
1062
1177
|
#
|
@@ -1071,14 +1186,11 @@ module JSON
|
|
1071
1186
|
# # Raises SystemStackError (stack level too deep):
|
1072
1187
|
# JSON.fast_generate(a)
|
1073
1188
|
#
|
1074
|
-
# source://json//json/common.rb#
|
1189
|
+
# source://json//lib/json/common.rb#445
|
1075
1190
|
def fast_generate(obj, opts = T.unsafe(nil)); end
|
1076
1191
|
|
1077
|
-
#
|
1078
|
-
|
1079
|
-
#
|
1080
|
-
# source://json//json/common.rb#328
|
1081
|
-
def fast_unparse(obj, opts = T.unsafe(nil)); end
|
1192
|
+
# source://json//lib/json/common.rb#937
|
1193
|
+
def fast_unparse(*_arg0, **_arg1, &_arg2); end
|
1082
1194
|
|
1083
1195
|
# :call-seq:
|
1084
1196
|
# JSON.generate(obj, opts = nil) -> new_string
|
@@ -1116,31 +1228,34 @@ module JSON
|
|
1116
1228
|
# # Raises JSON::NestingError (nesting of 100 is too deep):
|
1117
1229
|
# JSON.generate(a)
|
1118
1230
|
#
|
1119
|
-
# source://json//json/common.rb#
|
1231
|
+
# source://json//lib/json/common.rb#424
|
1120
1232
|
def generate(obj, opts = T.unsafe(nil)); end
|
1121
1233
|
|
1122
|
-
# Returns the JSON generator module that is used by JSON.
|
1123
|
-
# either JSON::Ext::Generator or JSON::Pure::Generator:
|
1124
|
-
# JSON.generator # => JSON::Ext::Generator
|
1234
|
+
# Returns the JSON generator module that is used by JSON.
|
1125
1235
|
#
|
1126
|
-
# source://json//json/common.rb#
|
1236
|
+
# source://json//lib/json/common.rb#181
|
1127
1237
|
def generator; end
|
1128
1238
|
|
1129
1239
|
# Set the module _generator_ to be used by JSON.
|
1130
1240
|
#
|
1131
|
-
# source://json//json/common.rb#
|
1241
|
+
# source://json//lib/json/common.rb#160
|
1132
1242
|
def generator=(generator); end
|
1133
1243
|
|
1134
|
-
# Encodes string using String.encode.
|
1135
|
-
#
|
1136
|
-
# source://json//json/common.rb#638
|
1137
|
-
def iconv(to, from, string); end
|
1138
|
-
|
1139
1244
|
# :call-seq:
|
1140
1245
|
# JSON.load(source, proc = nil, options = {}) -> object
|
1141
1246
|
#
|
1142
1247
|
# Returns the Ruby objects created by parsing the given +source+.
|
1143
1248
|
#
|
1249
|
+
# BEWARE: This method is meant to serialise data from trusted user input,
|
1250
|
+
# like from your own database server or clients under your control, it could
|
1251
|
+
# be dangerous to allow untrusted users to pass JSON sources into it.
|
1252
|
+
# If you must use it, use JSON.unsafe_load instead to make it clear.
|
1253
|
+
#
|
1254
|
+
# Since JSON version 2.8.0, `load` emits a deprecation warning when a
|
1255
|
+
# non native type is deserialized, without `create_additions` being explicitly
|
1256
|
+
# enabled, and in JSON version 3.0, `load` will have `create_additions` disabled
|
1257
|
+
# by default.
|
1258
|
+
#
|
1144
1259
|
# - Argument +source+ must be, or be convertible to, a \String:
|
1145
1260
|
# - If +source+ responds to instance method +to_str+,
|
1146
1261
|
# <tt>source.to_str</tt> becomes the source.
|
@@ -1155,9 +1270,6 @@ module JSON
|
|
1155
1270
|
# - Argument +proc+, if given, must be a \Proc that accepts one argument.
|
1156
1271
|
# It will be called recursively with each result (depth-first order).
|
1157
1272
|
# See details below.
|
1158
|
-
# BEWARE: This method is meant to serialise data from trusted user input,
|
1159
|
-
# like from your own database server or clients under your control, it could
|
1160
|
-
# be dangerous to allow untrusted users to pass JSON sources into it.
|
1161
1273
|
# - Argument +opts+, if given, contains a \Hash of options for the parsing.
|
1162
1274
|
# See {Parsing Options}[#module-JSON-label-Parsing+Options].
|
1163
1275
|
# The default options can be changed via method JSON.load_default_options=.
|
@@ -1168,17 +1280,17 @@ module JSON
|
|
1168
1280
|
# <tt>parse(source, opts)</tt>; see #parse.
|
1169
1281
|
#
|
1170
1282
|
# Source for following examples:
|
1171
|
-
# source =
|
1172
|
-
#
|
1173
|
-
#
|
1174
|
-
#
|
1175
|
-
#
|
1176
|
-
#
|
1177
|
-
#
|
1178
|
-
#
|
1179
|
-
#
|
1180
|
-
#
|
1181
|
-
#
|
1283
|
+
# source = <<~JSON
|
1284
|
+
# {
|
1285
|
+
# "name": "Dave",
|
1286
|
+
# "age" :40,
|
1287
|
+
# "hats": [
|
1288
|
+
# "Cattleman's",
|
1289
|
+
# "Panama",
|
1290
|
+
# "Tophat"
|
1291
|
+
# ]
|
1292
|
+
# }
|
1293
|
+
# JSON
|
1182
1294
|
#
|
1183
1295
|
# Load a \String:
|
1184
1296
|
# ruby = JSON.load(source)
|
@@ -1264,25 +1376,9 @@ module JSON
|
|
1264
1376
|
# #<Admin:0x00000000064c41f8
|
1265
1377
|
# @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
|
1266
1378
|
#
|
1267
|
-
# source://json//json/common.rb#
|
1379
|
+
# source://json//lib/json/common.rb#826
|
1268
1380
|
def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
|
1269
1381
|
|
1270
|
-
# Sets or returns default options for the JSON.load method.
|
1271
|
-
# Initially:
|
1272
|
-
# opts = JSON.load_default_options
|
1273
|
-
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
1274
|
-
#
|
1275
|
-
# source://json//json/common.rb#403
|
1276
|
-
def load_default_options; end
|
1277
|
-
|
1278
|
-
# Sets or returns default options for the JSON.load method.
|
1279
|
-
# Initially:
|
1280
|
-
# opts = JSON.load_default_options
|
1281
|
-
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
1282
|
-
#
|
1283
|
-
# source://json//json/common.rb#403
|
1284
|
-
def load_default_options=(_arg0); end
|
1285
|
-
|
1286
1382
|
# :call-seq:
|
1287
1383
|
# JSON.load_file(path, opts={}) -> object
|
1288
1384
|
#
|
@@ -1291,7 +1387,7 @@ module JSON
|
|
1291
1387
|
#
|
1292
1388
|
# See method #parse.
|
1293
1389
|
#
|
1294
|
-
# source://json//json/common.rb#
|
1390
|
+
# source://json//lib/json/common.rb#373
|
1295
1391
|
def load_file(filespec, opts = T.unsafe(nil)); end
|
1296
1392
|
|
1297
1393
|
# :call-seq:
|
@@ -1302,7 +1398,7 @@ module JSON
|
|
1302
1398
|
#
|
1303
1399
|
# See method #parse!
|
1304
1400
|
#
|
1305
|
-
# source://json//json/common.rb#
|
1401
|
+
# source://json//lib/json/common.rb#384
|
1306
1402
|
def load_file!(filespec, opts = T.unsafe(nil)); end
|
1307
1403
|
|
1308
1404
|
# :call-seq:
|
@@ -1333,17 +1429,17 @@ module JSON
|
|
1333
1429
|
# {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
|
1334
1430
|
#
|
1335
1431
|
# Parses nested JSON objects:
|
1336
|
-
# source =
|
1337
|
-
#
|
1338
|
-
#
|
1339
|
-
#
|
1340
|
-
#
|
1341
|
-
#
|
1342
|
-
#
|
1343
|
-
#
|
1344
|
-
#
|
1345
|
-
#
|
1346
|
-
#
|
1432
|
+
# source = <<~JSON
|
1433
|
+
# {
|
1434
|
+
# "name": "Dave",
|
1435
|
+
# "age" :40,
|
1436
|
+
# "hats": [
|
1437
|
+
# "Cattleman's",
|
1438
|
+
# "Panama",
|
1439
|
+
# "Tophat"
|
1440
|
+
# ]
|
1441
|
+
# }
|
1442
|
+
# JSON
|
1347
1443
|
# ruby = JSON.parse(source)
|
1348
1444
|
# ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
1349
1445
|
#
|
@@ -1353,7 +1449,7 @@ module JSON
|
|
1353
1449
|
# # Raises JSON::ParserError (783: unexpected token at ''):
|
1354
1450
|
# JSON.parse('')
|
1355
1451
|
#
|
1356
|
-
# source://json//json/common.rb#
|
1452
|
+
# source://json//lib/json/common.rb#336
|
1357
1453
|
def parse(source, opts = T.unsafe(nil)); end
|
1358
1454
|
|
1359
1455
|
# :call-seq:
|
@@ -1368,19 +1464,17 @@ module JSON
|
|
1368
1464
|
# which disables checking for nesting depth.
|
1369
1465
|
# - Option +allow_nan+, if not provided, defaults to +true+.
|
1370
1466
|
#
|
1371
|
-
# source://json//json/common.rb#
|
1467
|
+
# source://json//lib/json/common.rb#358
|
1372
1468
|
def parse!(source, opts = T.unsafe(nil)); end
|
1373
1469
|
|
1374
|
-
# Returns the JSON parser class that is used by JSON.
|
1375
|
-
# JSON::Ext::Parser or JSON::Pure::Parser:
|
1376
|
-
# JSON.parser # => JSON::Ext::Parser
|
1470
|
+
# Returns the JSON parser class that is used by JSON.
|
1377
1471
|
#
|
1378
|
-
# source://json//json/common.rb#
|
1472
|
+
# source://json//lib/json/common.rb#140
|
1379
1473
|
def parser; end
|
1380
1474
|
|
1381
1475
|
# Set the JSON parser class _parser_ to be used by JSON.
|
1382
1476
|
#
|
1383
|
-
# source://json//json/common.rb#
|
1477
|
+
# source://json//lib/json/common.rb#143
|
1384
1478
|
def parser=(parser); end
|
1385
1479
|
|
1386
1480
|
# :call-seq:
|
@@ -1413,119 +1507,503 @@ module JSON
|
|
1413
1507
|
# }
|
1414
1508
|
# }
|
1415
1509
|
#
|
1416
|
-
# source://json//json/common.rb#
|
1510
|
+
# source://json//lib/json/common.rb#492
|
1417
1511
|
def pretty_generate(obj, opts = T.unsafe(nil)); end
|
1418
1512
|
|
1419
|
-
#
|
1420
|
-
|
1421
|
-
#
|
1422
|
-
# source://json//json/common.rb#373
|
1423
|
-
def pretty_unparse(obj, opts = T.unsafe(nil)); end
|
1424
|
-
|
1425
|
-
# Recursively calls passed _Proc_ if the parsed data structure is an _Array_ or _Hash_
|
1426
|
-
#
|
1427
|
-
# source://json//json/common.rb#558
|
1428
|
-
def recurse_proc(result, &proc); end
|
1513
|
+
# source://json//lib/json/common.rb#947
|
1514
|
+
def pretty_unparse(*_arg0, **_arg1, &_arg2); end
|
1429
1515
|
|
1430
|
-
# source://json//json/common.rb#
|
1431
|
-
def restore(
|
1516
|
+
# source://json//lib/json/common.rb#957
|
1517
|
+
def restore(*_arg0, **_arg1, &_arg2); end
|
1432
1518
|
|
1433
|
-
# Sets or Returns the JSON generator state class that is used by JSON.
|
1434
|
-
# either JSON::Ext::Generator::State or JSON::Pure::Generator::State:
|
1435
|
-
# JSON.state # => JSON::Ext::Generator::State
|
1519
|
+
# Sets or Returns the JSON generator state class that is used by JSON.
|
1436
1520
|
#
|
1437
|
-
# source://json//json/common.rb#
|
1521
|
+
# source://json//lib/json/common.rb#184
|
1438
1522
|
def state; end
|
1439
1523
|
|
1440
|
-
# Sets or Returns the JSON generator state class that is used by JSON.
|
1441
|
-
# either JSON::Ext::Generator::State or JSON::Pure::Generator::State:
|
1442
|
-
# JSON.state # => JSON::Ext::Generator::State
|
1524
|
+
# Sets or Returns the JSON generator state class that is used by JSON.
|
1443
1525
|
#
|
1444
|
-
# source://json//json/common.rb#
|
1526
|
+
# source://json//lib/json/common.rb#184
|
1445
1527
|
def state=(_arg0); end
|
1446
1528
|
|
1447
1529
|
# :stopdoc:
|
1448
|
-
#
|
1449
|
-
#
|
1530
|
+
# All these were meant to be deprecated circa 2009, but were just set as undocumented
|
1531
|
+
# so usage still exist in the wild.
|
1450
1532
|
#
|
1451
|
-
# source://json//json/common.rb#
|
1452
|
-
def unparse(
|
1533
|
+
# source://json//lib/json/common.rb#927
|
1534
|
+
def unparse(*_arg0, **_arg1, &_arg2); end
|
1535
|
+
|
1536
|
+
# :call-seq:
|
1537
|
+
# JSON.unsafe_load(source, proc = nil, options = {}) -> object
|
1538
|
+
#
|
1539
|
+
# Returns the Ruby objects created by parsing the given +source+.
|
1540
|
+
#
|
1541
|
+
# BEWARE: This method is meant to serialise data from trusted user input,
|
1542
|
+
# like from your own database server or clients under your control, it could
|
1543
|
+
# be dangerous to allow untrusted users to pass JSON sources into it.
|
1544
|
+
#
|
1545
|
+
# - Argument +source+ must be, or be convertible to, a \String:
|
1546
|
+
# - If +source+ responds to instance method +to_str+,
|
1547
|
+
# <tt>source.to_str</tt> becomes the source.
|
1548
|
+
# - If +source+ responds to instance method +to_io+,
|
1549
|
+
# <tt>source.to_io.read</tt> becomes the source.
|
1550
|
+
# - If +source+ responds to instance method +read+,
|
1551
|
+
# <tt>source.read</tt> becomes the source.
|
1552
|
+
# - If both of the following are true, source becomes the \String <tt>'null'</tt>:
|
1553
|
+
# - Option +allow_blank+ specifies a truthy value.
|
1554
|
+
# - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
|
1555
|
+
# - Otherwise, +source+ remains the source.
|
1556
|
+
# - Argument +proc+, if given, must be a \Proc that accepts one argument.
|
1557
|
+
# It will be called recursively with each result (depth-first order).
|
1558
|
+
# See details below.
|
1559
|
+
# - Argument +opts+, if given, contains a \Hash of options for the parsing.
|
1560
|
+
# See {Parsing Options}[#module-JSON-label-Parsing+Options].
|
1561
|
+
# The default options can be changed via method JSON.unsafe_load_default_options=.
|
1562
|
+
#
|
1563
|
+
# ---
|
1564
|
+
#
|
1565
|
+
# When no +proc+ is given, modifies +source+ as above and returns the result of
|
1566
|
+
# <tt>parse(source, opts)</tt>; see #parse.
|
1567
|
+
#
|
1568
|
+
# Source for following examples:
|
1569
|
+
# source = <<~JSON
|
1570
|
+
# {
|
1571
|
+
# "name": "Dave",
|
1572
|
+
# "age" :40,
|
1573
|
+
# "hats": [
|
1574
|
+
# "Cattleman's",
|
1575
|
+
# "Panama",
|
1576
|
+
# "Tophat"
|
1577
|
+
# ]
|
1578
|
+
# }
|
1579
|
+
# JSON
|
1580
|
+
#
|
1581
|
+
# Load a \String:
|
1582
|
+
# ruby = JSON.unsafe_load(source)
|
1583
|
+
# ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
1584
|
+
#
|
1585
|
+
# Load an \IO object:
|
1586
|
+
# require 'stringio'
|
1587
|
+
# object = JSON.unsafe_load(StringIO.new(source))
|
1588
|
+
# object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
1589
|
+
#
|
1590
|
+
# Load a \File object:
|
1591
|
+
# path = 't.json'
|
1592
|
+
# File.write(path, source)
|
1593
|
+
# File.open(path) do |file|
|
1594
|
+
# JSON.unsafe_load(file)
|
1595
|
+
# end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
1596
|
+
#
|
1597
|
+
# ---
|
1598
|
+
#
|
1599
|
+
# When +proc+ is given:
|
1600
|
+
# - Modifies +source+ as above.
|
1601
|
+
# - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
|
1602
|
+
# - Recursively calls <tt>proc(result)</tt>.
|
1603
|
+
# - Returns the final result.
|
1604
|
+
#
|
1605
|
+
# Example:
|
1606
|
+
# require 'json'
|
1607
|
+
#
|
1608
|
+
# # Some classes for the example.
|
1609
|
+
# class Base
|
1610
|
+
# def initialize(attributes)
|
1611
|
+
# @attributes = attributes
|
1612
|
+
# end
|
1613
|
+
# end
|
1614
|
+
# class User < Base; end
|
1615
|
+
# class Account < Base; end
|
1616
|
+
# class Admin < Base; end
|
1617
|
+
# # The JSON source.
|
1618
|
+
# json = <<-EOF
|
1619
|
+
# {
|
1620
|
+
# "users": [
|
1621
|
+
# {"type": "User", "username": "jane", "email": "jane@example.com"},
|
1622
|
+
# {"type": "User", "username": "john", "email": "john@example.com"}
|
1623
|
+
# ],
|
1624
|
+
# "accounts": [
|
1625
|
+
# {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
|
1626
|
+
# {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
|
1627
|
+
# ],
|
1628
|
+
# "admins": {"type": "Admin", "password": "0wn3d"}
|
1629
|
+
# }
|
1630
|
+
# EOF
|
1631
|
+
# # Deserializer method.
|
1632
|
+
# def deserialize_obj(obj, safe_types = %w(User Account Admin))
|
1633
|
+
# type = obj.is_a?(Hash) && obj["type"]
|
1634
|
+
# safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
|
1635
|
+
# end
|
1636
|
+
# # Call to JSON.unsafe_load
|
1637
|
+
# ruby = JSON.unsafe_load(json, proc {|obj|
|
1638
|
+
# case obj
|
1639
|
+
# when Hash
|
1640
|
+
# obj.each {|k, v| obj[k] = deserialize_obj v }
|
1641
|
+
# when Array
|
1642
|
+
# obj.map! {|v| deserialize_obj v }
|
1643
|
+
# end
|
1644
|
+
# })
|
1645
|
+
# pp ruby
|
1646
|
+
# Output:
|
1647
|
+
# {"users"=>
|
1648
|
+
# [#<User:0x00000000064c4c98
|
1649
|
+
# @attributes=
|
1650
|
+
# {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
|
1651
|
+
# #<User:0x00000000064c4bd0
|
1652
|
+
# @attributes=
|
1653
|
+
# {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
|
1654
|
+
# "accounts"=>
|
1655
|
+
# [{"account"=>
|
1656
|
+
# #<Account:0x00000000064c4928
|
1657
|
+
# @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
|
1658
|
+
# {"account"=>
|
1659
|
+
# #<Account:0x00000000064c4680
|
1660
|
+
# @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
|
1661
|
+
# "admins"=>
|
1662
|
+
# #<Admin:0x00000000064c41f8
|
1663
|
+
# @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
|
1664
|
+
#
|
1665
|
+
# source://json//lib/json/common.rb#666
|
1666
|
+
def unsafe_load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
|
1453
1667
|
|
1454
1668
|
private
|
1455
1669
|
|
1456
|
-
# source://json//json/common.rb#
|
1457
|
-
def
|
1670
|
+
# source://json//lib/json/common.rb#970
|
1671
|
+
def const_missing(const_name); end
|
1672
|
+
|
1673
|
+
# source://json//lib/json/common.rb#188
|
1674
|
+
def deprecated_singleton_attr_accessor(*attrs); end
|
1458
1675
|
end
|
1459
1676
|
end
|
1460
1677
|
|
1461
|
-
#
|
1462
|
-
|
1678
|
+
# JSON::Coder holds a parser and generator configuration.
|
1679
|
+
#
|
1680
|
+
# module MyApp
|
1681
|
+
# JSONC_CODER = JSON::Coder.new(
|
1682
|
+
# allow_trailing_comma: true
|
1683
|
+
# )
|
1684
|
+
# end
|
1685
|
+
#
|
1686
|
+
# MyApp::JSONC_CODER.load(document)
|
1687
|
+
#
|
1688
|
+
# source://json//lib/json/common.rb#996
|
1689
|
+
class JSON::Coder
|
1690
|
+
# :call-seq:
|
1691
|
+
# JSON.new(options = nil, &block)
|
1692
|
+
#
|
1693
|
+
# Argument +options+, if given, contains a \Hash of options for both parsing and generating.
|
1694
|
+
# See {Parsing Options}[#module-JSON-label-Parsing+Options], and {Generating Options}[#module-JSON-label-Generating+Options].
|
1695
|
+
#
|
1696
|
+
# For generation, the <tt>strict: true</tt> option is always set. When a Ruby object with no native \JSON counterpart is
|
1697
|
+
# encoutered, the block provided to the initialize method is invoked, and must return a Ruby object that has a native
|
1698
|
+
# \JSON counterpart:
|
1699
|
+
#
|
1700
|
+
# module MyApp
|
1701
|
+
# API_JSON_CODER = JSON::Coder.new do |object|
|
1702
|
+
# case object
|
1703
|
+
# when Time
|
1704
|
+
# object.iso8601(3)
|
1705
|
+
# else
|
1706
|
+
# object # Unknown type, will raise
|
1707
|
+
# end
|
1708
|
+
# end
|
1709
|
+
# end
|
1710
|
+
#
|
1711
|
+
# puts MyApp::API_JSON_CODER.dump(Time.now.utc) # => "2025-01-21T08:41:44.286Z"
|
1712
|
+
#
|
1713
|
+
# @return [Coder] a new instance of Coder
|
1714
|
+
#
|
1715
|
+
# source://json//lib/json/common.rb#1020
|
1716
|
+
def initialize(options = T.unsafe(nil), &as_json); end
|
1463
1717
|
|
1464
|
-
#
|
1465
|
-
|
1718
|
+
# call-seq:
|
1719
|
+
# dump(object) -> String
|
1720
|
+
# dump(object, io) -> io
|
1721
|
+
#
|
1722
|
+
# Serialize the given object into a \JSON document.
|
1723
|
+
#
|
1724
|
+
# source://json//lib/json/common.rb#1038
|
1725
|
+
def dump(object, io = T.unsafe(nil)); end
|
1466
1726
|
|
1727
|
+
# call-seq:
|
1728
|
+
# dump(object) -> String
|
1729
|
+
# dump(object, io) -> io
|
1730
|
+
#
|
1731
|
+
# Serialize the given object into a \JSON document.
|
1732
|
+
#
|
1733
|
+
# source://json//lib/json/common.rb#1038
|
1734
|
+
def generate(object, io = T.unsafe(nil)); end
|
1735
|
+
|
1736
|
+
# call-seq:
|
1737
|
+
# load(string) -> Object
|
1738
|
+
#
|
1739
|
+
# Parse the given \JSON document and return an equivalent Ruby object.
|
1740
|
+
#
|
1741
|
+
# source://json//lib/json/common.rb#1047
|
1742
|
+
def load(source); end
|
1743
|
+
|
1744
|
+
# call-seq:
|
1745
|
+
# load(path) -> Object
|
1746
|
+
#
|
1747
|
+
# Parse the given \JSON document and return an equivalent Ruby object.
|
1748
|
+
#
|
1749
|
+
# source://json//lib/json/common.rb#1056
|
1750
|
+
def load_file(path); end
|
1751
|
+
|
1752
|
+
# call-seq:
|
1753
|
+
# load(string) -> Object
|
1754
|
+
#
|
1755
|
+
# Parse the given \JSON document and return an equivalent Ruby object.
|
1756
|
+
#
|
1757
|
+
# source://json//lib/json/common.rb#1047
|
1758
|
+
def parse(source); end
|
1759
|
+
end
|
1760
|
+
|
1761
|
+
module JSON::Ext::Generator::GeneratorMethods::String
|
1762
|
+
mixes_in_class_methods ::JSON::Ext::Generator::GeneratorMethods::String::Extend
|
1763
|
+
end
|
1764
|
+
|
1765
|
+
# source://json//lib/json/ext/generator/state.rb#6
|
1766
|
+
class JSON::Ext::Generator::State
|
1767
|
+
# call-seq: new(opts = {})
|
1768
|
+
#
|
1769
|
+
# Instantiates a new State object, configured by _opts_.
|
1770
|
+
#
|
1771
|
+
# _opts_ can have the following keys:
|
1772
|
+
#
|
1773
|
+
# * *indent*: a string used to indent levels (default: ''),
|
1774
|
+
# * *space*: a string that is put after, a : or , delimiter (default: ''),
|
1775
|
+
# * *space_before*: a string that is put before a : pair delimiter (default: ''),
|
1776
|
+
# * *object_nl*: a string that is put at the end of a JSON object (default: ''),
|
1777
|
+
# * *array_nl*: a string that is put at the end of a JSON array (default: ''),
|
1778
|
+
# * *allow_nan*: true if NaN, Infinity, and -Infinity should be
|
1779
|
+
# generated, otherwise an exception is thrown, if these values are
|
1780
|
+
# encountered. This options defaults to false.
|
1781
|
+
# * *ascii_only*: true if only ASCII characters should be generated. This
|
1782
|
+
# option defaults to false.
|
1783
|
+
# * *buffer_initial_length*: sets the initial length of the generator's
|
1784
|
+
# internal buffer.
|
1785
|
+
#
|
1786
|
+
# @return [State] a new instance of State
|
1787
|
+
#
|
1788
|
+
# source://json//lib/json/ext/generator/state.rb#25
|
1789
|
+
def initialize(opts = T.unsafe(nil)); end
|
1790
|
+
|
1791
|
+
# call-seq: [](name)
|
1792
|
+
#
|
1793
|
+
# Returns the value returned by method +name+.
|
1794
|
+
#
|
1795
|
+
# source://json//lib/json/ext/generator/state.rb#84
|
1796
|
+
def [](name); end
|
1797
|
+
|
1798
|
+
# call-seq: []=(name, value)
|
1799
|
+
#
|
1800
|
+
# Sets the attribute name to value.
|
1801
|
+
#
|
1802
|
+
# source://json//lib/json/ext/generator/state.rb#96
|
1803
|
+
def []=(name, value); end
|
1804
|
+
|
1805
|
+
# call-seq: configure(opts)
|
1806
|
+
#
|
1807
|
+
# Configure this State instance with the Hash _opts_, and return
|
1808
|
+
# itself.
|
1809
|
+
#
|
1810
|
+
# source://json//lib/json/ext/generator/state.rb#35
|
1811
|
+
def configure(opts); end
|
1812
|
+
|
1813
|
+
# call-seq: configure(opts)
|
1814
|
+
#
|
1815
|
+
# Configure this State instance with the Hash _opts_, and return
|
1816
|
+
# itself.
|
1817
|
+
#
|
1818
|
+
# source://json//lib/json/ext/generator/state.rb#35
|
1819
|
+
def merge(opts); end
|
1820
|
+
|
1821
|
+
# call-seq: to_h
|
1822
|
+
#
|
1823
|
+
# Returns the configuration instance variables as a hash, that can be
|
1824
|
+
# passed to the configure method.
|
1825
|
+
#
|
1826
|
+
# source://json//lib/json/ext/generator/state.rb#54
|
1827
|
+
def to_h; end
|
1828
|
+
|
1829
|
+
# call-seq: to_h
|
1830
|
+
#
|
1831
|
+
# Returns the configuration instance variables as a hash, that can be
|
1832
|
+
# passed to the configure method.
|
1833
|
+
#
|
1834
|
+
# source://json//lib/json/ext/generator/state.rb#54
|
1835
|
+
def to_hash; end
|
1836
|
+
end
|
1837
|
+
|
1838
|
+
# source://json//lib/json/ext.rb#9
|
1839
|
+
class JSON::Ext::Parser
|
1840
|
+
# @return [Parser] a new instance of Parser
|
1841
|
+
#
|
1842
|
+
# source://json//lib/json/ext.rb#17
|
1843
|
+
def initialize(source, opts = T.unsafe(nil)); end
|
1844
|
+
|
1845
|
+
# source://json//lib/json/ext.rb#26
|
1846
|
+
def parse; end
|
1847
|
+
|
1848
|
+
# source://json//lib/json/ext.rb#22
|
1849
|
+
def source; end
|
1850
|
+
end
|
1851
|
+
|
1852
|
+
# source://json//lib/json/ext.rb#32
|
1853
|
+
JSON::Ext::Parser::Config = JSON::Ext::ParserConfig
|
1854
|
+
|
1855
|
+
# Fragment of JSON document that is to be included as is:
|
1856
|
+
# fragment = JSON::Fragment.new("[1, 2, 3]")
|
1857
|
+
# JSON.generate({ count: 3, items: fragments })
|
1858
|
+
#
|
1859
|
+
# This allows to easily assemble multiple JSON fragments that have
|
1860
|
+
# been persisted somewhere without having to parse them nor resorting
|
1861
|
+
# to string interpolation.
|
1862
|
+
#
|
1863
|
+
# Note: no validation is performed on the provided string. It is the
|
1864
|
+
# responsability of the caller to ensure the string contains valid JSON.
|
1865
|
+
#
|
1866
|
+
# source://json//lib/json/common.rb#272
|
1867
|
+
class JSON::Fragment < ::Struct
|
1868
|
+
# @return [Fragment] a new instance of Fragment
|
1869
|
+
#
|
1870
|
+
# source://json//lib/json/common.rb#273
|
1871
|
+
def initialize(json); end
|
1872
|
+
|
1873
|
+
# Returns the value of attribute json
|
1874
|
+
#
|
1875
|
+
# @return [Object] the current value of json
|
1876
|
+
def json; end
|
1877
|
+
|
1878
|
+
# Sets the attribute json
|
1879
|
+
#
|
1880
|
+
# @param value [Object] the value to set the attribute json to.
|
1881
|
+
# @return [Object] the newly set value
|
1882
|
+
def json=(_); end
|
1883
|
+
|
1884
|
+
# source://json//lib/json/common.rb#281
|
1885
|
+
def to_json(state = T.unsafe(nil), *_arg1); end
|
1886
|
+
|
1887
|
+
class << self
|
1888
|
+
def [](*_arg0); end
|
1889
|
+
def inspect; end
|
1890
|
+
def keyword_init?; end
|
1891
|
+
def members; end
|
1892
|
+
def new(*_arg0); end
|
1893
|
+
end
|
1894
|
+
end
|
1895
|
+
|
1896
|
+
# This exception is raised if a generator or unparser error occurs.
|
1897
|
+
#
|
1898
|
+
# source://json//lib/json/common.rb#242
|
1899
|
+
class JSON::GeneratorError < ::JSON::JSONError
|
1900
|
+
# @return [GeneratorError] a new instance of GeneratorError
|
1901
|
+
#
|
1902
|
+
# source://json//lib/json/common.rb#245
|
1903
|
+
def initialize(message, invalid_object = T.unsafe(nil)); end
|
1904
|
+
|
1905
|
+
# source://json//lib/json/common.rb#250
|
1906
|
+
def detailed_message(*_arg0, **_arg1, &_arg2); end
|
1907
|
+
|
1908
|
+
# Returns the value of attribute invalid_object.
|
1909
|
+
#
|
1910
|
+
# source://json//lib/json/common.rb#243
|
1911
|
+
def invalid_object; end
|
1912
|
+
end
|
1913
|
+
|
1914
|
+
# source://json//lib/json/generic_object.rb#9
|
1467
1915
|
class JSON::GenericObject < ::OpenStruct
|
1468
|
-
# source://json//json/generic_object.rb#
|
1916
|
+
# source://json//lib/json/generic_object.rb#67
|
1469
1917
|
def as_json(*_arg0); end
|
1470
1918
|
|
1471
|
-
# source://json//json/generic_object.rb#
|
1919
|
+
# source://json//lib/json/generic_object.rb#51
|
1472
1920
|
def to_hash; end
|
1473
1921
|
|
1474
|
-
# source://json//json/generic_object.rb#
|
1922
|
+
# source://json//lib/json/generic_object.rb#71
|
1475
1923
|
def to_json(*a); end
|
1476
1924
|
|
1477
|
-
# source://json//json/generic_object.rb#
|
1925
|
+
# source://json//lib/json/generic_object.rb#63
|
1478
1926
|
def |(other); end
|
1479
1927
|
|
1480
1928
|
class << self
|
1481
|
-
# source://json//json/generic_object.rb#
|
1929
|
+
# source://json//lib/json/generic_object.rb#45
|
1482
1930
|
def dump(obj, *args); end
|
1483
1931
|
|
1484
|
-
# source://json//json/generic_object.rb#
|
1932
|
+
# source://json//lib/json/generic_object.rb#25
|
1485
1933
|
def from_hash(object); end
|
1486
1934
|
|
1487
1935
|
# Sets the attribute json_creatable
|
1488
1936
|
#
|
1489
1937
|
# @param value the value to set the attribute json_creatable to.
|
1490
1938
|
#
|
1491
|
-
# source://json//json/generic_object.rb#
|
1939
|
+
# source://json//lib/json/generic_object.rb#17
|
1492
1940
|
def json_creatable=(_arg0); end
|
1493
1941
|
|
1494
1942
|
# @return [Boolean]
|
1495
1943
|
#
|
1496
|
-
# source://json//json/generic_object.rb#
|
1944
|
+
# source://json//lib/json/generic_object.rb#13
|
1497
1945
|
def json_creatable?; end
|
1498
1946
|
|
1499
|
-
# source://json//json/generic_object.rb#
|
1947
|
+
# source://json//lib/json/generic_object.rb#19
|
1500
1948
|
def json_create(data); end
|
1501
1949
|
|
1502
|
-
# source://json//json/generic_object.rb#
|
1950
|
+
# source://json//lib/json/generic_object.rb#40
|
1503
1951
|
def load(source, proc = T.unsafe(nil), opts = T.unsafe(nil)); end
|
1504
1952
|
end
|
1505
1953
|
end
|
1506
1954
|
|
1507
|
-
#
|
1508
|
-
|
1509
|
-
class << self
|
1510
|
-
# source://json//json/common.rb#141
|
1511
|
-
def wrap(exception); end
|
1512
|
-
end
|
1513
|
-
end
|
1955
|
+
# source://json//lib/json/common.rb#341
|
1956
|
+
JSON::PARSE_L_OPTIONS = T.let(T.unsafe(nil), Hash)
|
1514
1957
|
|
1515
|
-
# source://json//json/common.rb#
|
1516
|
-
JSON::
|
1958
|
+
# source://json//lib/json/common.rb#454
|
1959
|
+
JSON::PRETTY_GENERATE_OPTIONS = T.let(T.unsafe(nil), Hash)
|
1517
1960
|
|
1518
|
-
# source://json//json/common.rb#
|
1961
|
+
# source://json//lib/json/common.rb#146
|
1519
1962
|
JSON::Parser = JSON::Ext::Parser
|
1520
1963
|
|
1521
|
-
#
|
1522
|
-
JSON::State = JSON::Ext::Generator::State
|
1523
|
-
|
1524
|
-
# For backwards compatibility
|
1964
|
+
# This exception is raised if a parser error occurs.
|
1525
1965
|
#
|
1526
|
-
# source://json//json/common.rb#
|
1527
|
-
JSON::
|
1966
|
+
# source://json//lib/json/common.rb#233
|
1967
|
+
class JSON::ParserError < ::JSON::JSONError
|
1968
|
+
# Returns the value of attribute column.
|
1969
|
+
#
|
1970
|
+
# source://json//lib/json/common.rb#234
|
1971
|
+
def column; end
|
1528
1972
|
|
1973
|
+
# Returns the value of attribute line.
|
1974
|
+
#
|
1975
|
+
# source://json//lib/json/common.rb#234
|
1976
|
+
def line; end
|
1977
|
+
end
|
1978
|
+
|
1979
|
+
# source://json//lib/json/common.rb#8
|
1980
|
+
module JSON::ParserOptions
|
1981
|
+
class << self
|
1982
|
+
# source://json//lib/json/common.rb#10
|
1983
|
+
def prepare(opts); end
|
1984
|
+
|
1985
|
+
private
|
1986
|
+
|
1987
|
+
# source://json//lib/json/common.rb#40
|
1988
|
+
def array_class_proc(array_class, on_load); end
|
1989
|
+
|
1990
|
+
# TODO: exctract :create_additions support to another gem for version 3.0
|
1991
|
+
#
|
1992
|
+
# source://json//lib/json/common.rb#52
|
1993
|
+
def create_additions_proc(opts); end
|
1994
|
+
|
1995
|
+
# source://json//lib/json/common.rb#91
|
1996
|
+
def create_additions_warning; end
|
1997
|
+
|
1998
|
+
# source://json//lib/json/common.rb#29
|
1999
|
+
def object_class_proc(object_class, on_load); end
|
2000
|
+
end
|
2001
|
+
end
|
2002
|
+
|
2003
|
+
# source://json//lib/json/common.rb#175
|
2004
|
+
JSON::State = JSON::Ext::Generator::State
|
2005
|
+
|
2006
|
+
# source://json//lib/json/common.rb#1062
|
1529
2007
|
module Kernel
|
1530
2008
|
private
|
1531
2009
|
|
@@ -1536,18 +2014,38 @@ module Kernel
|
|
1536
2014
|
# The _opts_ argument is passed through to generate/parse respectively. See
|
1537
2015
|
# generate and parse for their documentation.
|
1538
2016
|
#
|
1539
|
-
# source://json//json/common.rb#
|
1540
|
-
def JSON(object,
|
2017
|
+
# source://json//lib/json/common.rb#1101
|
2018
|
+
def JSON(object, opts = T.unsafe(nil)); end
|
1541
2019
|
|
1542
2020
|
# Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
|
1543
2021
|
# one line.
|
1544
2022
|
#
|
1545
|
-
# source://json//json/common.rb#
|
2023
|
+
# source://json//lib/json/common.rb#1067
|
1546
2024
|
def j(*objs); end
|
1547
2025
|
|
1548
2026
|
# Outputs _objs_ to STDOUT as JSON strings in a pretty format, with
|
1549
2027
|
# indentation and over many lines.
|
1550
2028
|
#
|
1551
|
-
# source://json//json/common.rb#
|
2029
|
+
# source://json//lib/json/common.rb#1082
|
1552
2030
|
def jj(*objs); end
|
1553
2031
|
end
|
2032
|
+
|
2033
|
+
class NilClass
|
2034
|
+
include ::JSON::Ext::Generator::GeneratorMethods::NilClass
|
2035
|
+
end
|
2036
|
+
|
2037
|
+
class Object < ::BasicObject
|
2038
|
+
include ::Kernel
|
2039
|
+
include ::PP::ObjectMixin
|
2040
|
+
include ::JSON::Ext::Generator::GeneratorMethods::Object
|
2041
|
+
end
|
2042
|
+
|
2043
|
+
class String
|
2044
|
+
include ::Comparable
|
2045
|
+
include ::JSON::Ext::Generator::GeneratorMethods::String
|
2046
|
+
extend ::JSON::Ext::Generator::GeneratorMethods::String::Extend
|
2047
|
+
end
|
2048
|
+
|
2049
|
+
class TrueClass
|
2050
|
+
include ::JSON::Ext::Generator::GeneratorMethods::TrueClass
|
2051
|
+
end
|