danger-packwerk 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/lib/danger-packwerk/packwerk_wrapper.rb +2 -2
  3. data/lib/danger-packwerk/version.rb +1 -1
  4. data/sorbet/config +1 -0
  5. data/sorbet/rbi/gems/actionview@7.0.4.rbi +11543 -0
  6. data/sorbet/rbi/gems/activesupport@7.0.4.rbi +12959 -0
  7. data/sorbet/rbi/gems/addressable@2.8.1.rbi +1505 -0
  8. data/sorbet/rbi/gems/ast@2.4.2.rbi +522 -0
  9. data/sorbet/rbi/gems/better_html@2.0.1.rbi +286 -0
  10. data/sorbet/rbi/gems/builder@3.2.4.rbi +8 -0
  11. data/sorbet/rbi/gems/claide-plugins@0.9.2.rbi +791 -0
  12. data/sorbet/rbi/gems/claide@1.1.0.rbi +1132 -0
  13. data/sorbet/rbi/gems/coderay@1.1.3.rbi +2256 -0
  14. data/sorbet/rbi/gems/colored2@3.1.2.rbi +130 -0
  15. data/sorbet/rbi/gems/concurrent-ruby@1.1.10.rbi +8695 -0
  16. data/sorbet/rbi/gems/cork@0.3.0.rbi +248 -0
  17. data/sorbet/rbi/gems/crass@1.0.6.rbi +436 -0
  18. data/sorbet/rbi/gems/danger-plugin-api@1.0.0.rbi +8 -0
  19. data/sorbet/rbi/gems/danger@9.0.0.rbi +4722 -0
  20. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +862 -0
  21. data/sorbet/rbi/gems/erubi@1.11.0.rbi +102 -0
  22. data/sorbet/rbi/gems/faraday-em_http@1.0.0.rbi +266 -0
  23. data/sorbet/rbi/gems/faraday-em_synchrony@1.0.0.rbi +209 -0
  24. data/sorbet/rbi/gems/faraday-excon@1.1.0.rbi +212 -0
  25. data/sorbet/rbi/gems/faraday-http-cache@2.4.1.rbi +805 -0
  26. data/sorbet/rbi/gems/faraday-httpclient@1.0.1.rbi +221 -0
  27. data/sorbet/rbi/gems/faraday-multipart@1.0.4.rbi +266 -0
  28. data/sorbet/rbi/gems/faraday-net_http@1.0.1.rbi +216 -0
  29. data/sorbet/rbi/gems/faraday-net_http_persistent@1.2.0.rbi +206 -0
  30. data/sorbet/rbi/gems/faraday-patron@1.0.0.rbi +212 -0
  31. data/sorbet/rbi/gems/faraday-rack@1.0.0.rbi +225 -0
  32. data/sorbet/rbi/gems/faraday-retry@1.0.3.rbi +222 -0
  33. data/sorbet/rbi/gems/faraday@1.10.2.rbi +1862 -0
  34. data/sorbet/rbi/gems/git@1.12.0.rbi +1936 -0
  35. data/sorbet/rbi/gems/i18n@1.12.0.rbi +1643 -0
  36. data/sorbet/rbi/gems/json@2.6.2.rbi +1418 -0
  37. data/sorbet/rbi/gems/kramdown-parser-gfm@1.1.0.rbi +8 -0
  38. data/sorbet/rbi/gems/kramdown@2.4.0.rbi +2168 -0
  39. data/sorbet/rbi/gems/loofah@2.19.0.rbi +646 -0
  40. data/sorbet/rbi/gems/method_source@1.0.0.rbi +199 -0
  41. data/sorbet/rbi/gems/minitest@5.16.3.rbi +997 -0
  42. data/sorbet/rbi/gems/multipart-post@2.2.3.rbi +165 -0
  43. data/sorbet/rbi/gems/nap@1.1.0.rbi +351 -0
  44. data/sorbet/rbi/gems/no_proxy_fix@0.1.2.rbi +8 -0
  45. data/sorbet/rbi/gems/nokogiri@1.13.8.rbi +4916 -0
  46. data/sorbet/rbi/gems/octokit@5.6.1.rbi +8939 -0
  47. data/sorbet/rbi/gems/open4@1.3.4.rbi +8 -0
  48. data/sorbet/rbi/gems/{packwerk@2.1.1.rbi → packwerk@2.2.1.rbi} +602 -51
  49. data/sorbet/rbi/gems/parallel@1.22.1.rbi +163 -0
  50. data/sorbet/rbi/gems/parser@3.1.2.1.rbi +5988 -0
  51. data/sorbet/rbi/gems/pry@0.14.1.rbi +6969 -0
  52. data/sorbet/rbi/gems/public_suffix@5.0.0.rbi +779 -0
  53. data/sorbet/rbi/gems/racc@1.6.0.rbi +92 -0
  54. data/sorbet/rbi/gems/rails-dom-testing@2.0.3.rbi +8 -0
  55. data/sorbet/rbi/gems/rails-html-sanitizer@1.4.3.rbi +493 -0
  56. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +227 -0
  57. data/sorbet/rbi/gems/rake@13.0.6.rbi +1865 -0
  58. data/sorbet/rbi/gems/rbi@0.0.14.rbi +2337 -0
  59. data/sorbet/rbi/gems/rchardet@1.8.0.rbi +587 -0
  60. data/sorbet/rbi/gems/regexp_parser@2.5.0.rbi +1851 -0
  61. data/sorbet/rbi/gems/rexml@3.2.5.rbi +3852 -0
  62. data/sorbet/rbi/gems/rspec-core@3.11.0.rbi +7725 -0
  63. data/sorbet/rbi/gems/rspec-expectations@3.11.0.rbi +6201 -0
  64. data/sorbet/rbi/gems/rspec-mocks@3.11.1.rbi +3625 -0
  65. data/sorbet/rbi/gems/rspec-support@3.11.0.rbi +1176 -0
  66. data/sorbet/rbi/gems/rspec@3.11.0.rbi +40 -0
  67. data/sorbet/rbi/gems/rubocop-ast@1.21.0.rbi +4193 -0
  68. data/sorbet/rbi/gems/rubocop-sorbet@0.6.8.rbi +677 -0
  69. data/sorbet/rbi/gems/rubocop@1.36.0.rbi +37914 -0
  70. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +732 -0
  71. data/sorbet/rbi/gems/ruby2_keywords@0.0.5.rbi +8 -0
  72. data/sorbet/rbi/gems/sawyer@0.9.2.rbi +513 -0
  73. data/sorbet/rbi/gems/smart_properties@1.17.0.rbi +326 -0
  74. data/sorbet/rbi/gems/spoom@1.1.11.rbi +1600 -0
  75. data/sorbet/rbi/gems/tapioca@0.8.0.rbi +1959 -0
  76. data/sorbet/rbi/gems/terminal-table@3.0.2.rbi +438 -0
  77. data/sorbet/rbi/gems/thor@1.2.1.rbi +2921 -0
  78. data/sorbet/rbi/gems/tzinfo@2.0.5.rbi +4879 -0
  79. data/sorbet/rbi/gems/unicode-display_width@2.3.0.rbi +27 -0
  80. data/sorbet/rbi/gems/unparser@0.6.5.rbi +2789 -0
  81. data/sorbet/rbi/gems/webrick@1.7.0.rbi +1802 -0
  82. data/sorbet/rbi/gems/yard-sorbet@0.6.1.rbi +288 -0
  83. data/sorbet/rbi/gems/yard@0.9.27.rbi +12668 -0
  84. data/sorbet/rbi/todo.rbi +122 -0
  85. metadata +84 -7
  86. data/sorbet/rbi/gems/danger@8.5.0.rbi +0 -122
@@ -0,0 +1,1418 @@
1
+ # typed: true
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This is an autogenerated file for types exported from the `json` gem.
5
+ # Please instead update this file by running `bin/tapioca gem json`.
6
+
7
+ # Extends any Class to include _json_creatable?_ method.
8
+ class Class < ::Module
9
+ # Returns true if this class can be used to create an instance
10
+ # from a serialised JSON string. The class has to implement a class
11
+ # method _json_create_ that expects a hash as first parameter. The hash
12
+ # should include the required data.
13
+ #
14
+ # @return [Boolean]
15
+ def json_creatable?; end
16
+ end
17
+
18
+ # = JavaScript \Object Notation (\JSON)
19
+ #
20
+ # \JSON is a lightweight data-interchange format.
21
+ #
22
+ # A \JSON value is one of the following:
23
+ # - Double-quoted text: <tt>"foo"</tt>.
24
+ # - Number: +1+, +1.0+, +2.0e2+.
25
+ # - Boolean: +true+, +false+.
26
+ # - Null: +null+.
27
+ # - \Array: an ordered list of values, enclosed by square brackets:
28
+ # ["foo", 1, 1.0, 2.0e2, true, false, null]
29
+ #
30
+ # - \Object: a collection of name/value pairs, enclosed by curly braces;
31
+ # each name is double-quoted text;
32
+ # the values may be any \JSON values:
33
+ # {"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}
34
+ #
35
+ # A \JSON array or object may contain nested arrays, objects, and scalars
36
+ # to any depth:
37
+ # {"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}
38
+ # [{"foo": 0, "bar": 1}, ["baz", 2]]
39
+ #
40
+ # == Using \Module \JSON
41
+ #
42
+ # To make module \JSON available in your code, begin with:
43
+ # require 'json'
44
+ #
45
+ # All examples here assume that this has been done.
46
+ #
47
+ # === Parsing \JSON
48
+ #
49
+ # You can parse a \String containing \JSON data using
50
+ # either of two methods:
51
+ # - <tt>JSON.parse(source, opts)</tt>
52
+ # - <tt>JSON.parse!(source, opts)</tt>
53
+ #
54
+ # where
55
+ # - +source+ is a Ruby object.
56
+ # - +opts+ is a \Hash object containing options
57
+ # that control both input allowed and output formatting.
58
+ #
59
+ # The difference between the two methods
60
+ # is that JSON.parse! omits some checks
61
+ # and may not be safe for some +source+ data;
62
+ # use it only for data from trusted sources.
63
+ # Use the safer method JSON.parse for less trusted sources.
64
+ #
65
+ # ==== Parsing \JSON Arrays
66
+ #
67
+ # When +source+ is a \JSON array, JSON.parse by default returns a Ruby \Array:
68
+ # json = '["foo", 1, 1.0, 2.0e2, true, false, null]'
69
+ # ruby = JSON.parse(json)
70
+ # ruby # => ["foo", 1, 1.0, 200.0, true, false, nil]
71
+ # ruby.class # => Array
72
+ #
73
+ # The \JSON array may contain nested arrays, objects, and scalars
74
+ # to any depth:
75
+ # json = '[{"foo": 0, "bar": 1}, ["baz", 2]]'
76
+ # JSON.parse(json) # => [{"foo"=>0, "bar"=>1}, ["baz", 2]]
77
+ #
78
+ # ==== Parsing \JSON \Objects
79
+ #
80
+ # When the source is a \JSON object, JSON.parse by default returns a Ruby \Hash:
81
+ # json = '{"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}'
82
+ # ruby = JSON.parse(json)
83
+ # ruby # => {"a"=>"foo", "b"=>1, "c"=>1.0, "d"=>200.0, "e"=>true, "f"=>false, "g"=>nil}
84
+ # ruby.class # => Hash
85
+ #
86
+ # The \JSON object may contain nested arrays, objects, and scalars
87
+ # to any depth:
88
+ # json = '{"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}'
89
+ # JSON.parse(json) # => {"foo"=>{"bar"=>1, "baz"=>2}, "bat"=>[0, 1, 2]}
90
+ #
91
+ # ==== Parsing \JSON Scalars
92
+ #
93
+ # When the source is a \JSON scalar (not an array or object),
94
+ # JSON.parse returns a Ruby scalar.
95
+ #
96
+ # \String:
97
+ # ruby = JSON.parse('"foo"')
98
+ # ruby # => 'foo'
99
+ # ruby.class # => String
100
+ # \Integer:
101
+ # ruby = JSON.parse('1')
102
+ # ruby # => 1
103
+ # ruby.class # => Integer
104
+ # \Float:
105
+ # ruby = JSON.parse('1.0')
106
+ # ruby # => 1.0
107
+ # ruby.class # => Float
108
+ # ruby = JSON.parse('2.0e2')
109
+ # ruby # => 200
110
+ # ruby.class # => Float
111
+ # Boolean:
112
+ # ruby = JSON.parse('true')
113
+ # ruby # => true
114
+ # ruby.class # => TrueClass
115
+ # ruby = JSON.parse('false')
116
+ # ruby # => false
117
+ # ruby.class # => FalseClass
118
+ # Null:
119
+ # ruby = JSON.parse('null')
120
+ # ruby # => nil
121
+ # ruby.class # => NilClass
122
+ #
123
+ # ==== Parsing Options
124
+ #
125
+ # ====== Input Options
126
+ #
127
+ # Option +max_nesting+ (\Integer) specifies the maximum nesting depth allowed;
128
+ # defaults to +100+; specify +false+ to disable depth checking.
129
+ #
130
+ # With the default, +false+:
131
+ # source = '[0, [1, [2, [3]]]]'
132
+ # ruby = JSON.parse(source)
133
+ # ruby # => [0, [1, [2, [3]]]]
134
+ # Too deep:
135
+ # # Raises JSON::NestingError (nesting of 2 is too deep):
136
+ # JSON.parse(source, {max_nesting: 1})
137
+ # Bad value:
138
+ # # Raises TypeError (wrong argument type Symbol (expected Fixnum)):
139
+ # JSON.parse(source, {max_nesting: :foo})
140
+ #
141
+ # ---
142
+ #
143
+ # Option +allow_nan+ (boolean) specifies whether to allow
144
+ # NaN, Infinity, and MinusInfinity in +source+;
145
+ # defaults to +false+.
146
+ #
147
+ # With the default, +false+:
148
+ # # Raises JSON::ParserError (225: unexpected token at '[NaN]'):
149
+ # JSON.parse('[NaN]')
150
+ # # Raises JSON::ParserError (232: unexpected token at '[Infinity]'):
151
+ # JSON.parse('[Infinity]')
152
+ # # Raises JSON::ParserError (248: unexpected token at '[-Infinity]'):
153
+ # JSON.parse('[-Infinity]')
154
+ # Allow:
155
+ # source = '[NaN, Infinity, -Infinity]'
156
+ # ruby = JSON.parse(source, {allow_nan: true})
157
+ # ruby # => [NaN, Infinity, -Infinity]
158
+ #
159
+ # ====== Output Options
160
+ #
161
+ # Option +symbolize_names+ (boolean) specifies whether returned \Hash keys
162
+ # should be Symbols;
163
+ # defaults to +false+ (use Strings).
164
+ #
165
+ # With the default, +false+:
166
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
167
+ # ruby = JSON.parse(source)
168
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
169
+ # Use Symbols:
170
+ # ruby = JSON.parse(source, {symbolize_names: true})
171
+ # ruby # => {:a=>"foo", :b=>1.0, :c=>true, :d=>false, :e=>nil}
172
+ #
173
+ # ---
174
+ #
175
+ # Option +object_class+ (\Class) specifies the Ruby class to be used
176
+ # for each \JSON object;
177
+ # defaults to \Hash.
178
+ #
179
+ # With the default, \Hash:
180
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
181
+ # ruby = JSON.parse(source)
182
+ # ruby.class # => Hash
183
+ # Use class \OpenStruct:
184
+ # ruby = JSON.parse(source, {object_class: OpenStruct})
185
+ # ruby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil>
186
+ #
187
+ # ---
188
+ #
189
+ # Option +array_class+ (\Class) specifies the Ruby class to be used
190
+ # for each \JSON array;
191
+ # defaults to \Array.
192
+ #
193
+ # With the default, \Array:
194
+ # source = '["foo", 1.0, true, false, null]'
195
+ # ruby = JSON.parse(source)
196
+ # ruby.class # => Array
197
+ # Use class \Set:
198
+ # ruby = JSON.parse(source, {array_class: Set})
199
+ # ruby # => #<Set: {"foo", 1.0, true, false, nil}>
200
+ #
201
+ # ---
202
+ #
203
+ # Option +create_additions+ (boolean) specifies whether to use \JSON additions in parsing.
204
+ # See {\JSON Additions}[#module-JSON-label-JSON+Additions].
205
+ #
206
+ # === Generating \JSON
207
+ #
208
+ # To generate a Ruby \String containing \JSON data,
209
+ # use method <tt>JSON.generate(source, opts)</tt>, where
210
+ # - +source+ is a Ruby object.
211
+ # - +opts+ is a \Hash object containing options
212
+ # that control both input allowed and output formatting.
213
+ #
214
+ # ==== Generating \JSON from Arrays
215
+ #
216
+ # When the source is a Ruby \Array, JSON.generate returns
217
+ # a \String containing a \JSON array:
218
+ # ruby = [0, 's', :foo]
219
+ # json = JSON.generate(ruby)
220
+ # json # => '[0,"s","foo"]'
221
+ #
222
+ # The Ruby \Array array may contain nested arrays, hashes, and scalars
223
+ # to any depth:
224
+ # ruby = [0, [1, 2], {foo: 3, bar: 4}]
225
+ # json = JSON.generate(ruby)
226
+ # json # => '[0,[1,2],{"foo":3,"bar":4}]'
227
+ #
228
+ # ==== Generating \JSON from Hashes
229
+ #
230
+ # When the source is a Ruby \Hash, JSON.generate returns
231
+ # a \String containing a \JSON object:
232
+ # ruby = {foo: 0, bar: 's', baz: :bat}
233
+ # json = JSON.generate(ruby)
234
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
235
+ #
236
+ # The Ruby \Hash array may contain nested arrays, hashes, and scalars
237
+ # to any depth:
238
+ # ruby = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
239
+ # json = JSON.generate(ruby)
240
+ # json # => '{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}'
241
+ #
242
+ # ==== Generating \JSON from Other Objects
243
+ #
244
+ # When the source is neither an \Array nor a \Hash,
245
+ # the generated \JSON data depends on the class of the source.
246
+ #
247
+ # When the source is a Ruby \Integer or \Float, JSON.generate returns
248
+ # a \String containing a \JSON number:
249
+ # JSON.generate(42) # => '42'
250
+ # JSON.generate(0.42) # => '0.42'
251
+ #
252
+ # When the source is a Ruby \String, JSON.generate returns
253
+ # a \String containing a \JSON string (with double-quotes):
254
+ # JSON.generate('A string') # => '"A string"'
255
+ #
256
+ # When the source is +true+, +false+ or +nil+, JSON.generate returns
257
+ # a \String containing the corresponding \JSON token:
258
+ # JSON.generate(true) # => 'true'
259
+ # JSON.generate(false) # => 'false'
260
+ # JSON.generate(nil) # => 'null'
261
+ #
262
+ # When the source is none of the above, JSON.generate returns
263
+ # a \String containing a \JSON string representation of the source:
264
+ # JSON.generate(:foo) # => '"foo"'
265
+ # JSON.generate(Complex(0, 0)) # => '"0+0i"'
266
+ # JSON.generate(Dir.new('.')) # => '"#<Dir>"'
267
+ #
268
+ # ==== Generating Options
269
+ #
270
+ # ====== Input Options
271
+ #
272
+ # Option +allow_nan+ (boolean) specifies whether
273
+ # +NaN+, +Infinity+, and <tt>-Infinity</tt> may be generated;
274
+ # defaults to +false+.
275
+ #
276
+ # With the default, +false+:
277
+ # # Raises JSON::GeneratorError (920: NaN not allowed in JSON):
278
+ # JSON.generate(JSON::NaN)
279
+ # # Raises JSON::GeneratorError (917: Infinity not allowed in JSON):
280
+ # JSON.generate(JSON::Infinity)
281
+ # # Raises JSON::GeneratorError (917: -Infinity not allowed in JSON):
282
+ # JSON.generate(JSON::MinusInfinity)
283
+ #
284
+ # Allow:
285
+ # ruby = [Float::NaN, Float::Infinity, Float::MinusInfinity]
286
+ # JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,-Infinity]'
287
+ #
288
+ # ---
289
+ #
290
+ # Option +max_nesting+ (\Integer) specifies the maximum nesting depth
291
+ # in +obj+; defaults to +100+.
292
+ #
293
+ # With the default, +100+:
294
+ # obj = [[[[[[0]]]]]]
295
+ # JSON.generate(obj) # => '[[[[[[0]]]]]]'
296
+ #
297
+ # Too deep:
298
+ # # Raises JSON::NestingError (nesting of 2 is too deep):
299
+ # JSON.generate(obj, max_nesting: 2)
300
+ #
301
+ # ====== Output Options
302
+ #
303
+ # The default formatting options generate the most compact
304
+ # \JSON data, all on one line and with no whitespace.
305
+ #
306
+ # You can use these formatting options to generate
307
+ # \JSON data in a more open format, using whitespace.
308
+ # See also JSON.pretty_generate.
309
+ #
310
+ # - Option +array_nl+ (\String) specifies a string (usually a newline)
311
+ # to be inserted after each \JSON array; defaults to the empty \String, <tt>''</tt>.
312
+ # - Option +object_nl+ (\String) specifies a string (usually a newline)
313
+ # to be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>.
314
+ # - Option +indent+ (\String) specifies the string (usually spaces) to be
315
+ # used for indentation; defaults to the empty \String, <tt>''</tt>;
316
+ # defaults to the empty \String, <tt>''</tt>;
317
+ # has no effect unless options +array_nl+ or +object_nl+ specify newlines.
318
+ # - Option +space+ (\String) specifies a string (usually a space) to be
319
+ # inserted after the colon in each \JSON object's pair;
320
+ # defaults to the empty \String, <tt>''</tt>.
321
+ # - Option +space_before+ (\String) specifies a string (usually a space) to be
322
+ # inserted before the colon in each \JSON object's pair;
323
+ # defaults to the empty \String, <tt>''</tt>.
324
+ #
325
+ # In this example, +obj+ is used first to generate the shortest
326
+ # \JSON data (no whitespace), then again with all formatting options
327
+ # specified:
328
+ #
329
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
330
+ # json = JSON.generate(obj)
331
+ # puts 'Compact:', json
332
+ # opts = {
333
+ # array_nl: "\n",
334
+ # object_nl: "\n",
335
+ # indent: ' ',
336
+ # space_before: ' ',
337
+ # space: ' '
338
+ # }
339
+ # puts 'Open:', JSON.generate(obj, opts)
340
+ #
341
+ # Output:
342
+ # Compact:
343
+ # {"foo":["bar","baz"],"bat":{"bam":0,"bad":1}}
344
+ # Open:
345
+ # {
346
+ # "foo" : [
347
+ # "bar",
348
+ # "baz"
349
+ # ],
350
+ # "bat" : {
351
+ # "bam" : 0,
352
+ # "bad" : 1
353
+ # }
354
+ # }
355
+ #
356
+ # == \JSON Additions
357
+ #
358
+ # When you "round trip" a non-\String object from Ruby to \JSON and back,
359
+ # you have a new \String, instead of the object you began with:
360
+ # ruby0 = Range.new(0, 2)
361
+ # json = JSON.generate(ruby0)
362
+ # json # => '0..2"'
363
+ # ruby1 = JSON.parse(json)
364
+ # ruby1 # => '0..2'
365
+ # ruby1.class # => String
366
+ #
367
+ # You can use \JSON _additions_ to preserve the original object.
368
+ # The addition is an extension of a ruby class, so that:
369
+ # - \JSON.generate stores more information in the \JSON string.
370
+ # - \JSON.parse, called with option +create_additions+,
371
+ # uses that information to create a proper Ruby object.
372
+ #
373
+ # This example shows a \Range being generated into \JSON
374
+ # and parsed back into Ruby, both without and with
375
+ # the addition for \Range:
376
+ # ruby = Range.new(0, 2)
377
+ # # This passage does not use the addition for Range.
378
+ # json0 = JSON.generate(ruby)
379
+ # ruby0 = JSON.parse(json0)
380
+ # # This passage uses the addition for Range.
381
+ # require 'json/add/range'
382
+ # json1 = JSON.generate(ruby)
383
+ # ruby1 = JSON.parse(json1, create_additions: true)
384
+ # # Make a nice display.
385
+ # display = <<EOT
386
+ # Generated JSON:
387
+ # Without addition: #{json0} (#{json0.class})
388
+ # With addition: #{json1} (#{json1.class})
389
+ # Parsed JSON:
390
+ # Without addition: #{ruby0.inspect} (#{ruby0.class})
391
+ # With addition: #{ruby1.inspect} (#{ruby1.class})
392
+ # EOT
393
+ # puts display
394
+ #
395
+ # This output shows the different results:
396
+ # Generated JSON:
397
+ # Without addition: "0..2" (String)
398
+ # With addition: {"json_class":"Range","a":[0,2,false]} (String)
399
+ # Parsed JSON:
400
+ # Without addition: "0..2" (String)
401
+ # With addition: 0..2 (Range)
402
+ #
403
+ # The \JSON module includes additions for certain classes.
404
+ # You can also craft custom additions.
405
+ # See {Custom \JSON Additions}[#module-JSON-label-Custom+JSON+Additions].
406
+ #
407
+ # === Built-in Additions
408
+ #
409
+ # The \JSON module includes additions for certain classes.
410
+ # To use an addition, +require+ its source:
411
+ # - BigDecimal: <tt>require 'json/add/bigdecimal'</tt>
412
+ # - Complex: <tt>require 'json/add/complex'</tt>
413
+ # - Date: <tt>require 'json/add/date'</tt>
414
+ # - DateTime: <tt>require 'json/add/date_time'</tt>
415
+ # - Exception: <tt>require 'json/add/exception'</tt>
416
+ # - OpenStruct: <tt>require 'json/add/ostruct'</tt>
417
+ # - Range: <tt>require 'json/add/range'</tt>
418
+ # - Rational: <tt>require 'json/add/rational'</tt>
419
+ # - Regexp: <tt>require 'json/add/regexp'</tt>
420
+ # - Set: <tt>require 'json/add/set'</tt>
421
+ # - Struct: <tt>require 'json/add/struct'</tt>
422
+ # - Symbol: <tt>require 'json/add/symbol'</tt>
423
+ # - Time: <tt>require 'json/add/time'</tt>
424
+ #
425
+ # To reduce punctuation clutter, the examples below
426
+ # show the generated \JSON via +puts+, rather than the usual +inspect+,
427
+ #
428
+ # \BigDecimal:
429
+ # require 'json/add/bigdecimal'
430
+ # ruby0 = BigDecimal(0) # 0.0
431
+ # json = JSON.generate(ruby0) # {"json_class":"BigDecimal","b":"27:0.0"}
432
+ # ruby1 = JSON.parse(json, create_additions: true) # 0.0
433
+ # ruby1.class # => BigDecimal
434
+ #
435
+ # \Complex:
436
+ # require 'json/add/complex'
437
+ # ruby0 = Complex(1+0i) # 1+0i
438
+ # json = JSON.generate(ruby0) # {"json_class":"Complex","r":1,"i":0}
439
+ # ruby1 = JSON.parse(json, create_additions: true) # 1+0i
440
+ # ruby1.class # Complex
441
+ #
442
+ # \Date:
443
+ # require 'json/add/date'
444
+ # ruby0 = Date.today # 2020-05-02
445
+ # json = JSON.generate(ruby0) # {"json_class":"Date","y":2020,"m":5,"d":2,"sg":2299161.0}
446
+ # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02
447
+ # ruby1.class # Date
448
+ #
449
+ # \DateTime:
450
+ # require 'json/add/date_time'
451
+ # ruby0 = DateTime.now # 2020-05-02T10:38:13-05:00
452
+ # json = JSON.generate(ruby0) # {"json_class":"DateTime","y":2020,"m":5,"d":2,"H":10,"M":38,"S":13,"of":"-5/24","sg":2299161.0}
453
+ # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02T10:38:13-05:00
454
+ # ruby1.class # DateTime
455
+ #
456
+ # \Exception (and its subclasses including \RuntimeError):
457
+ # require 'json/add/exception'
458
+ # ruby0 = Exception.new('A message') # A message
459
+ # json = JSON.generate(ruby0) # {"json_class":"Exception","m":"A message","b":null}
460
+ # ruby1 = JSON.parse(json, create_additions: true) # A message
461
+ # ruby1.class # Exception
462
+ # ruby0 = RuntimeError.new('Another message') # Another message
463
+ # json = JSON.generate(ruby0) # {"json_class":"RuntimeError","m":"Another message","b":null}
464
+ # ruby1 = JSON.parse(json, create_additions: true) # Another message
465
+ # ruby1.class # RuntimeError
466
+ #
467
+ # \OpenStruct:
468
+ # require 'json/add/ostruct'
469
+ # ruby0 = OpenStruct.new(name: 'Matz', language: 'Ruby') # #<OpenStruct name="Matz", language="Ruby">
470
+ # json = JSON.generate(ruby0) # {"json_class":"OpenStruct","t":{"name":"Matz","language":"Ruby"}}
471
+ # ruby1 = JSON.parse(json, create_additions: true) # #<OpenStruct name="Matz", language="Ruby">
472
+ # ruby1.class # OpenStruct
473
+ #
474
+ # \Range:
475
+ # require 'json/add/range'
476
+ # ruby0 = Range.new(0, 2) # 0..2
477
+ # json = JSON.generate(ruby0) # {"json_class":"Range","a":[0,2,false]}
478
+ # ruby1 = JSON.parse(json, create_additions: true) # 0..2
479
+ # ruby1.class # Range
480
+ #
481
+ # \Rational:
482
+ # require 'json/add/rational'
483
+ # ruby0 = Rational(1, 3) # 1/3
484
+ # json = JSON.generate(ruby0) # {"json_class":"Rational","n":1,"d":3}
485
+ # ruby1 = JSON.parse(json, create_additions: true) # 1/3
486
+ # ruby1.class # Rational
487
+ #
488
+ # \Regexp:
489
+ # require 'json/add/regexp'
490
+ # ruby0 = Regexp.new('foo') # (?-mix:foo)
491
+ # json = JSON.generate(ruby0) # {"json_class":"Regexp","o":0,"s":"foo"}
492
+ # ruby1 = JSON.parse(json, create_additions: true) # (?-mix:foo)
493
+ # ruby1.class # Regexp
494
+ #
495
+ # \Set:
496
+ # require 'json/add/set'
497
+ # ruby0 = Set.new([0, 1, 2]) # #<Set: {0, 1, 2}>
498
+ # json = JSON.generate(ruby0) # {"json_class":"Set","a":[0,1,2]}
499
+ # ruby1 = JSON.parse(json, create_additions: true) # #<Set: {0, 1, 2}>
500
+ # ruby1.class # Set
501
+ #
502
+ # \Struct:
503
+ # require 'json/add/struct'
504
+ # Customer = Struct.new(:name, :address) # Customer
505
+ # ruby0 = Customer.new("Dave", "123 Main") # #<struct Customer name="Dave", address="123 Main">
506
+ # json = JSON.generate(ruby0) # {"json_class":"Customer","v":["Dave","123 Main"]}
507
+ # ruby1 = JSON.parse(json, create_additions: true) # #<struct Customer name="Dave", address="123 Main">
508
+ # ruby1.class # Customer
509
+ #
510
+ # \Symbol:
511
+ # require 'json/add/symbol'
512
+ # ruby0 = :foo # foo
513
+ # json = JSON.generate(ruby0) # {"json_class":"Symbol","s":"foo"}
514
+ # ruby1 = JSON.parse(json, create_additions: true) # foo
515
+ # ruby1.class # Symbol
516
+ #
517
+ # \Time:
518
+ # require 'json/add/time'
519
+ # ruby0 = Time.now # 2020-05-02 11:28:26 -0500
520
+ # json = JSON.generate(ruby0) # {"json_class":"Time","s":1588436906,"n":840560000}
521
+ # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02 11:28:26 -0500
522
+ # ruby1.class # Time
523
+ #
524
+ #
525
+ # === Custom \JSON Additions
526
+ #
527
+ # In addition to the \JSON additions provided,
528
+ # you can craft \JSON additions of your own,
529
+ # either for Ruby built-in classes or for user-defined classes.
530
+ #
531
+ # Here's a user-defined class +Foo+:
532
+ # class Foo
533
+ # attr_accessor :bar, :baz
534
+ # def initialize(bar, baz)
535
+ # self.bar = bar
536
+ # self.baz = baz
537
+ # end
538
+ # end
539
+ #
540
+ # Here's the \JSON addition for it:
541
+ # # Extend class Foo with JSON addition.
542
+ # class Foo
543
+ # # Serialize Foo object with its class name and arguments
544
+ # def to_json(*args)
545
+ # {
546
+ # JSON.create_id => self.class.name,
547
+ # 'a' => [ bar, baz ]
548
+ # }.to_json(*args)
549
+ # end
550
+ # # Deserialize JSON string by constructing new Foo object with arguments.
551
+ # def self.json_create(object)
552
+ # new(*object['a'])
553
+ # end
554
+ # end
555
+ #
556
+ # Demonstration:
557
+ # require 'json'
558
+ # # This Foo object has no custom addition.
559
+ # foo0 = Foo.new(0, 1)
560
+ # json0 = JSON.generate(foo0)
561
+ # obj0 = JSON.parse(json0)
562
+ # # Lood the custom addition.
563
+ # require_relative 'foo_addition'
564
+ # # This foo has the custom addition.
565
+ # foo1 = Foo.new(0, 1)
566
+ # json1 = JSON.generate(foo1)
567
+ # obj1 = JSON.parse(json1, create_additions: true)
568
+ # # Make a nice display.
569
+ # display = <<EOT
570
+ # Generated JSON:
571
+ # Without custom addition: #{json0} (#{json0.class})
572
+ # With custom addition: #{json1} (#{json1.class})
573
+ # Parsed JSON:
574
+ # Without custom addition: #{obj0.inspect} (#{obj0.class})
575
+ # With custom addition: #{obj1.inspect} (#{obj1.class})
576
+ # EOT
577
+ # puts display
578
+ #
579
+ # Output:
580
+ #
581
+ # Generated JSON:
582
+ # Without custom addition: "#<Foo:0x0000000006534e80>" (String)
583
+ # With custom addition: {"json_class":"Foo","a":[0,1]} (String)
584
+ # Parsed JSON:
585
+ # Without custom addition: "#<Foo:0x0000000006534e80>" (String)
586
+ # With custom addition: #<Foo:0x0000000006473bb8 @bar=0, @baz=1> (Foo)
587
+ module JSON
588
+ private
589
+
590
+ # :call-seq:
591
+ # JSON.dump(obj, io = nil, limit = nil)
592
+ #
593
+ # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
594
+ #
595
+ # The default options can be changed via method JSON.dump_default_options.
596
+ #
597
+ # - Argument +io+, if given, should respond to method +write+;
598
+ # the \JSON \String is written to +io+, and +io+ is returned.
599
+ # If +io+ is not given, the \JSON \String is returned.
600
+ # - Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
601
+ #
602
+ # ---
603
+ #
604
+ # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
605
+ # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
606
+ # json = JSON.dump(obj)
607
+ # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
608
+ #
609
+ # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
610
+ # path = 't.json'
611
+ # File.open(path, 'w') do |file|
612
+ # JSON.dump(obj, file)
613
+ # end # => #<File:t.json (closed)>
614
+ # puts File.read(path)
615
+ # Output:
616
+ # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
617
+ def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil)); end
618
+
619
+ # :call-seq:
620
+ # JSON.fast_generate(obj, opts) -> new_string
621
+ #
622
+ # Arguments +obj+ and +opts+ here are the same as
623
+ # arguments +obj+ and +opts+ in JSON.generate.
624
+ #
625
+ # By default, generates \JSON data without checking
626
+ # for circular references in +obj+ (option +max_nesting+ set to +false+, disabled).
627
+ #
628
+ # Raises an exception if +obj+ contains circular references:
629
+ # a = []; b = []; a.push(b); b.push(a)
630
+ # # Raises SystemStackError (stack level too deep):
631
+ # JSON.fast_generate(a)
632
+ def fast_generate(obj, opts = T.unsafe(nil)); end
633
+
634
+ # :stopdoc:
635
+ # I want to deprecate these later, so I'll first be silent about them, and later delete them.
636
+ def fast_unparse(obj, opts = T.unsafe(nil)); end
637
+
638
+ # :call-seq:
639
+ # JSON.generate(obj, opts = nil) -> new_string
640
+ #
641
+ # Returns a \String containing the generated \JSON data.
642
+ #
643
+ # See also JSON.fast_generate, JSON.pretty_generate.
644
+ #
645
+ # Argument +obj+ is the Ruby object to be converted to \JSON.
646
+ #
647
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
648
+ # See {Generating Options}[#module-JSON-label-Generating+Options].
649
+ #
650
+ # ---
651
+ #
652
+ # When +obj+ is an \Array, returns a \String containing a \JSON array:
653
+ # obj = ["foo", 1.0, true, false, nil]
654
+ # json = JSON.generate(obj)
655
+ # json # => '["foo",1.0,true,false,null]'
656
+ #
657
+ # When +obj+ is a \Hash, returns a \String containing a \JSON object:
658
+ # obj = {foo: 0, bar: 's', baz: :bat}
659
+ # json = JSON.generate(obj)
660
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
661
+ #
662
+ # For examples of generating from other Ruby objects, see
663
+ # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
664
+ #
665
+ # ---
666
+ #
667
+ # Raises an exception if any formatting option is not a \String.
668
+ #
669
+ # Raises an exception if +obj+ contains circular references:
670
+ # a = []; b = []; a.push(b); b.push(a)
671
+ # # Raises JSON::NestingError (nesting of 100 is too deep):
672
+ # JSON.generate(a)
673
+ def generate(obj, opts = T.unsafe(nil)); end
674
+
675
+ # :call-seq:
676
+ # JSON.load(source, proc = nil, options = {}) -> object
677
+ #
678
+ # Returns the Ruby objects created by parsing the given +source+.
679
+ #
680
+ # - Argument +source+ must be, or be convertible to, a \String:
681
+ # - If +source+ responds to instance method +to_str+,
682
+ # <tt>source.to_str</tt> becomes the source.
683
+ # - If +source+ responds to instance method +to_io+,
684
+ # <tt>source.to_io.read</tt> becomes the source.
685
+ # - If +source+ responds to instance method +read+,
686
+ # <tt>source.read</tt> becomes the source.
687
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
688
+ # - Option +allow_blank+ specifies a truthy value.
689
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
690
+ # - Otherwise, +source+ remains the source.
691
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
692
+ # It will be called recursively with each result (depth-first order).
693
+ # See details below.
694
+ # BEWARE: This method is meant to serialise data from trusted user input,
695
+ # like from your own database server or clients under your control, it could
696
+ # be dangerous to allow untrusted users to pass JSON sources into it.
697
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
698
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
699
+ # The default options can be changed via method JSON.load_default_options=.
700
+ #
701
+ # ---
702
+ #
703
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
704
+ # <tt>parse(source, opts)</tt>; see #parse.
705
+ #
706
+ # Source for following examples:
707
+ # source = <<-EOT
708
+ # {
709
+ # "name": "Dave",
710
+ # "age" :40,
711
+ # "hats": [
712
+ # "Cattleman's",
713
+ # "Panama",
714
+ # "Tophat"
715
+ # ]
716
+ # }
717
+ # EOT
718
+ #
719
+ # Load a \String:
720
+ # ruby = JSON.load(source)
721
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
722
+ #
723
+ # Load an \IO object:
724
+ # require 'stringio'
725
+ # object = JSON.load(StringIO.new(source))
726
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
727
+ #
728
+ # Load a \File object:
729
+ # path = 't.json'
730
+ # File.write(path, source)
731
+ # File.open(path) do |file|
732
+ # JSON.load(file)
733
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
734
+ #
735
+ # ---
736
+ #
737
+ # When +proc+ is given:
738
+ # - Modifies +source+ as above.
739
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
740
+ # - Recursively calls <tt>proc(result)</tt>.
741
+ # - Returns the final result.
742
+ #
743
+ # Example:
744
+ # require 'json'
745
+ #
746
+ # # Some classes for the example.
747
+ # class Base
748
+ # def initialize(attributes)
749
+ # @attributes = attributes
750
+ # end
751
+ # end
752
+ # class User < Base; end
753
+ # class Account < Base; end
754
+ # class Admin < Base; end
755
+ # # The JSON source.
756
+ # json = <<-EOF
757
+ # {
758
+ # "users": [
759
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
760
+ # {"type": "User", "username": "john", "email": "john@example.com"}
761
+ # ],
762
+ # "accounts": [
763
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
764
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
765
+ # ],
766
+ # "admins": {"type": "Admin", "password": "0wn3d"}
767
+ # }
768
+ # EOF
769
+ # # Deserializer method.
770
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
771
+ # type = obj.is_a?(Hash) && obj["type"]
772
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
773
+ # end
774
+ # # Call to JSON.load
775
+ # ruby = JSON.load(json, proc {|obj|
776
+ # case obj
777
+ # when Hash
778
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
779
+ # when Array
780
+ # obj.map! {|v| deserialize_obj v }
781
+ # end
782
+ # })
783
+ # pp ruby
784
+ # Output:
785
+ # {"users"=>
786
+ # [#<User:0x00000000064c4c98
787
+ # @attributes=
788
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
789
+ # #<User:0x00000000064c4bd0
790
+ # @attributes=
791
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
792
+ # "accounts"=>
793
+ # [{"account"=>
794
+ # #<Account:0x00000000064c4928
795
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
796
+ # {"account"=>
797
+ # #<Account:0x00000000064c4680
798
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
799
+ # "admins"=>
800
+ # #<Admin:0x00000000064c41f8
801
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
802
+ def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
803
+
804
+ # :call-seq:
805
+ # JSON.load_file(path, opts={}) -> object
806
+ #
807
+ # Calls:
808
+ # parse(File.read(path), opts)
809
+ #
810
+ # See method #parse.
811
+ def load_file(filespec, opts = T.unsafe(nil)); end
812
+
813
+ # :call-seq:
814
+ # JSON.load_file!(path, opts = {})
815
+ #
816
+ # Calls:
817
+ # JSON.parse!(File.read(path, opts))
818
+ #
819
+ # See method #parse!
820
+ def load_file!(filespec, opts = T.unsafe(nil)); end
821
+
822
+ # :call-seq:
823
+ # JSON.parse(source, opts) -> object
824
+ #
825
+ # Returns the Ruby objects created by parsing the given +source+.
826
+ #
827
+ # Argument +source+ contains the \String to be parsed.
828
+ #
829
+ # Argument +opts+, if given, contains a \Hash of options for the parsing.
830
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
831
+ #
832
+ # ---
833
+ #
834
+ # When +source+ is a \JSON array, returns a Ruby \Array:
835
+ # source = '["foo", 1.0, true, false, null]'
836
+ # ruby = JSON.parse(source)
837
+ # ruby # => ["foo", 1.0, true, false, nil]
838
+ # ruby.class # => Array
839
+ #
840
+ # When +source+ is a \JSON object, returns a Ruby \Hash:
841
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
842
+ # ruby = JSON.parse(source)
843
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
844
+ # ruby.class # => Hash
845
+ #
846
+ # For examples of parsing for all \JSON data types, see
847
+ # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
848
+ #
849
+ # Parses nested JSON objects:
850
+ # source = <<-EOT
851
+ # {
852
+ # "name": "Dave",
853
+ # "age" :40,
854
+ # "hats": [
855
+ # "Cattleman's",
856
+ # "Panama",
857
+ # "Tophat"
858
+ # ]
859
+ # }
860
+ # EOT
861
+ # ruby = JSON.parse(source)
862
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
863
+ #
864
+ # ---
865
+ #
866
+ # Raises an exception if +source+ is not valid JSON:
867
+ # # Raises JSON::ParserError (783: unexpected token at ''):
868
+ # JSON.parse('')
869
+ def parse(source, opts = T.unsafe(nil)); end
870
+
871
+ # :call-seq:
872
+ # JSON.parse!(source, opts) -> object
873
+ #
874
+ # Calls
875
+ # parse(source, opts)
876
+ # with +source+ and possibly modified +opts+.
877
+ #
878
+ # Differences from JSON.parse:
879
+ # - Option +max_nesting+, if not provided, defaults to +false+,
880
+ # which disables checking for nesting depth.
881
+ # - Option +allow_nan+, if not provided, defaults to +true+.
882
+ def parse!(source, opts = T.unsafe(nil)); end
883
+
884
+ # :call-seq:
885
+ # JSON.pretty_generate(obj, opts = nil) -> new_string
886
+ #
887
+ # Arguments +obj+ and +opts+ here are the same as
888
+ # arguments +obj+ and +opts+ in JSON.generate.
889
+ #
890
+ # Default options are:
891
+ # {
892
+ # indent: ' ', # Two spaces
893
+ # space: ' ', # One space
894
+ # array_nl: "\n", # Newline
895
+ # object_nl: "\n" # Newline
896
+ # }
897
+ #
898
+ # Example:
899
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
900
+ # json = JSON.pretty_generate(obj)
901
+ # puts json
902
+ # Output:
903
+ # {
904
+ # "foo": [
905
+ # "bar",
906
+ # "baz"
907
+ # ],
908
+ # "bat": {
909
+ # "bam": 0,
910
+ # "bad": 1
911
+ # }
912
+ # }
913
+ def pretty_generate(obj, opts = T.unsafe(nil)); end
914
+
915
+ # :stopdoc:
916
+ # I want to deprecate these later, so I'll first be silent about them, and later delete them.
917
+ def pretty_unparse(obj, opts = T.unsafe(nil)); end
918
+
919
+ # Recursively calls passed _Proc_ if the parsed data structure is an _Array_ or _Hash_
920
+ def recurse_proc(result, &proc); end
921
+
922
+ def restore(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
923
+
924
+ # :stopdoc:
925
+ # I want to deprecate these later, so I'll first be silent about them, and
926
+ # later delete them.
927
+ def unparse(obj, opts = T.unsafe(nil)); end
928
+
929
+ class << self
930
+ # :call-seq:
931
+ # JSON[object] -> new_array or new_string
932
+ #
933
+ # If +object+ is a \String,
934
+ # calls JSON.parse with +object+ and +opts+ (see method #parse):
935
+ # json = '[0, 1, null]'
936
+ # JSON[json]# => [0, 1, nil]
937
+ #
938
+ # Otherwise, calls JSON.generate with +object+ and +opts+ (see method #generate):
939
+ # ruby = [0, 1, nil]
940
+ # JSON[ruby] # => '[0,1,null]'
941
+ def [](object, opts = T.unsafe(nil)); end
942
+
943
+ def create_fast_state; end
944
+
945
+ # Returns the current create identifier.
946
+ # See also JSON.create_id=.
947
+ def create_id; end
948
+
949
+ # Sets create identifier, which is used to decide if the _json_create_
950
+ # hook of a class should be called; initial value is +json_class+:
951
+ # JSON.create_id # => 'json_class'
952
+ def create_id=(new_value); end
953
+
954
+ def create_pretty_state; end
955
+
956
+ # Return the constant located at _path_. The format of _path_ has to be
957
+ # either ::A::B::C or A::B::C. In any case, A has to be located at the top
958
+ # level (absolute namespace path?). If there doesn't exist a constant at
959
+ # the given path, an ArgumentError is raised.
960
+ def deep_const_get(path); end
961
+
962
+ # :call-seq:
963
+ # JSON.dump(obj, io = nil, limit = nil)
964
+ #
965
+ # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
966
+ #
967
+ # The default options can be changed via method JSON.dump_default_options.
968
+ #
969
+ # - Argument +io+, if given, should respond to method +write+;
970
+ # the \JSON \String is written to +io+, and +io+ is returned.
971
+ # If +io+ is not given, the \JSON \String is returned.
972
+ # - Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
973
+ #
974
+ # ---
975
+ #
976
+ # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
977
+ # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
978
+ # json = JSON.dump(obj)
979
+ # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
980
+ #
981
+ # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
982
+ # path = 't.json'
983
+ # File.open(path, 'w') do |file|
984
+ # JSON.dump(obj, file)
985
+ # end # => #<File:t.json (closed)>
986
+ # puts File.read(path)
987
+ # Output:
988
+ # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
989
+ def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil)); end
990
+
991
+ # Sets or returns the default options for the JSON.dump method.
992
+ # Initially:
993
+ # opts = JSON.dump_default_options
994
+ # opts # => {:max_nesting=>false, :allow_nan=>true, :escape_slash=>false}
995
+ def dump_default_options; end
996
+
997
+ # Sets or returns the default options for the JSON.dump method.
998
+ # Initially:
999
+ # opts = JSON.dump_default_options
1000
+ # opts # => {:max_nesting=>false, :allow_nan=>true, :escape_slash=>false}
1001
+ def dump_default_options=(_arg0); end
1002
+
1003
+ # :call-seq:
1004
+ # JSON.fast_generate(obj, opts) -> new_string
1005
+ #
1006
+ # Arguments +obj+ and +opts+ here are the same as
1007
+ # arguments +obj+ and +opts+ in JSON.generate.
1008
+ #
1009
+ # By default, generates \JSON data without checking
1010
+ # for circular references in +obj+ (option +max_nesting+ set to +false+, disabled).
1011
+ #
1012
+ # Raises an exception if +obj+ contains circular references:
1013
+ # a = []; b = []; a.push(b); b.push(a)
1014
+ # # Raises SystemStackError (stack level too deep):
1015
+ # JSON.fast_generate(a)
1016
+ def fast_generate(obj, opts = T.unsafe(nil)); end
1017
+
1018
+ # :stopdoc:
1019
+ # I want to deprecate these later, so I'll first be silent about them, and later delete them.
1020
+ def fast_unparse(obj, opts = T.unsafe(nil)); end
1021
+
1022
+ # :call-seq:
1023
+ # JSON.generate(obj, opts = nil) -> new_string
1024
+ #
1025
+ # Returns a \String containing the generated \JSON data.
1026
+ #
1027
+ # See also JSON.fast_generate, JSON.pretty_generate.
1028
+ #
1029
+ # Argument +obj+ is the Ruby object to be converted to \JSON.
1030
+ #
1031
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
1032
+ # See {Generating Options}[#module-JSON-label-Generating+Options].
1033
+ #
1034
+ # ---
1035
+ #
1036
+ # When +obj+ is an \Array, returns a \String containing a \JSON array:
1037
+ # obj = ["foo", 1.0, true, false, nil]
1038
+ # json = JSON.generate(obj)
1039
+ # json # => '["foo",1.0,true,false,null]'
1040
+ #
1041
+ # When +obj+ is a \Hash, returns a \String containing a \JSON object:
1042
+ # obj = {foo: 0, bar: 's', baz: :bat}
1043
+ # json = JSON.generate(obj)
1044
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
1045
+ #
1046
+ # For examples of generating from other Ruby objects, see
1047
+ # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
1048
+ #
1049
+ # ---
1050
+ #
1051
+ # Raises an exception if any formatting option is not a \String.
1052
+ #
1053
+ # Raises an exception if +obj+ contains circular references:
1054
+ # a = []; b = []; a.push(b); b.push(a)
1055
+ # # Raises JSON::NestingError (nesting of 100 is too deep):
1056
+ # JSON.generate(a)
1057
+ def generate(obj, opts = T.unsafe(nil)); end
1058
+
1059
+ # Returns the JSON generator module that is used by JSON. This is
1060
+ # either JSON::Ext::Generator or JSON::Pure::Generator:
1061
+ # JSON.generator # => JSON::Ext::Generator
1062
+ def generator; end
1063
+
1064
+ # Set the module _generator_ to be used by JSON.
1065
+ def generator=(generator); end
1066
+
1067
+ # Encodes string using String.encode.
1068
+ def iconv(to, from, string); end
1069
+
1070
+ # :call-seq:
1071
+ # JSON.load(source, proc = nil, options = {}) -> object
1072
+ #
1073
+ # Returns the Ruby objects created by parsing the given +source+.
1074
+ #
1075
+ # - Argument +source+ must be, or be convertible to, a \String:
1076
+ # - If +source+ responds to instance method +to_str+,
1077
+ # <tt>source.to_str</tt> becomes the source.
1078
+ # - If +source+ responds to instance method +to_io+,
1079
+ # <tt>source.to_io.read</tt> becomes the source.
1080
+ # - If +source+ responds to instance method +read+,
1081
+ # <tt>source.read</tt> becomes the source.
1082
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
1083
+ # - Option +allow_blank+ specifies a truthy value.
1084
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
1085
+ # - Otherwise, +source+ remains the source.
1086
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
1087
+ # It will be called recursively with each result (depth-first order).
1088
+ # See details below.
1089
+ # BEWARE: This method is meant to serialise data from trusted user input,
1090
+ # like from your own database server or clients under your control, it could
1091
+ # be dangerous to allow untrusted users to pass JSON sources into it.
1092
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
1093
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1094
+ # The default options can be changed via method JSON.load_default_options=.
1095
+ #
1096
+ # ---
1097
+ #
1098
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
1099
+ # <tt>parse(source, opts)</tt>; see #parse.
1100
+ #
1101
+ # Source for following examples:
1102
+ # source = <<-EOT
1103
+ # {
1104
+ # "name": "Dave",
1105
+ # "age" :40,
1106
+ # "hats": [
1107
+ # "Cattleman's",
1108
+ # "Panama",
1109
+ # "Tophat"
1110
+ # ]
1111
+ # }
1112
+ # EOT
1113
+ #
1114
+ # Load a \String:
1115
+ # ruby = JSON.load(source)
1116
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1117
+ #
1118
+ # Load an \IO object:
1119
+ # require 'stringio'
1120
+ # object = JSON.load(StringIO.new(source))
1121
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1122
+ #
1123
+ # Load a \File object:
1124
+ # path = 't.json'
1125
+ # File.write(path, source)
1126
+ # File.open(path) do |file|
1127
+ # JSON.load(file)
1128
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1129
+ #
1130
+ # ---
1131
+ #
1132
+ # When +proc+ is given:
1133
+ # - Modifies +source+ as above.
1134
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
1135
+ # - Recursively calls <tt>proc(result)</tt>.
1136
+ # - Returns the final result.
1137
+ #
1138
+ # Example:
1139
+ # require 'json'
1140
+ #
1141
+ # # Some classes for the example.
1142
+ # class Base
1143
+ # def initialize(attributes)
1144
+ # @attributes = attributes
1145
+ # end
1146
+ # end
1147
+ # class User < Base; end
1148
+ # class Account < Base; end
1149
+ # class Admin < Base; end
1150
+ # # The JSON source.
1151
+ # json = <<-EOF
1152
+ # {
1153
+ # "users": [
1154
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
1155
+ # {"type": "User", "username": "john", "email": "john@example.com"}
1156
+ # ],
1157
+ # "accounts": [
1158
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
1159
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
1160
+ # ],
1161
+ # "admins": {"type": "Admin", "password": "0wn3d"}
1162
+ # }
1163
+ # EOF
1164
+ # # Deserializer method.
1165
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
1166
+ # type = obj.is_a?(Hash) && obj["type"]
1167
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
1168
+ # end
1169
+ # # Call to JSON.load
1170
+ # ruby = JSON.load(json, proc {|obj|
1171
+ # case obj
1172
+ # when Hash
1173
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
1174
+ # when Array
1175
+ # obj.map! {|v| deserialize_obj v }
1176
+ # end
1177
+ # })
1178
+ # pp ruby
1179
+ # Output:
1180
+ # {"users"=>
1181
+ # [#<User:0x00000000064c4c98
1182
+ # @attributes=
1183
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
1184
+ # #<User:0x00000000064c4bd0
1185
+ # @attributes=
1186
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
1187
+ # "accounts"=>
1188
+ # [{"account"=>
1189
+ # #<Account:0x00000000064c4928
1190
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
1191
+ # {"account"=>
1192
+ # #<Account:0x00000000064c4680
1193
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
1194
+ # "admins"=>
1195
+ # #<Admin:0x00000000064c41f8
1196
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
1197
+ def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1198
+
1199
+ # Sets or returns default options for the JSON.load method.
1200
+ # Initially:
1201
+ # opts = JSON.load_default_options
1202
+ # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
1203
+ def load_default_options; end
1204
+
1205
+ # Sets or returns default options for the JSON.load method.
1206
+ # Initially:
1207
+ # opts = JSON.load_default_options
1208
+ # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
1209
+ def load_default_options=(_arg0); end
1210
+
1211
+ # :call-seq:
1212
+ # JSON.load_file(path, opts={}) -> object
1213
+ #
1214
+ # Calls:
1215
+ # parse(File.read(path), opts)
1216
+ #
1217
+ # See method #parse.
1218
+ def load_file(filespec, opts = T.unsafe(nil)); end
1219
+
1220
+ # :call-seq:
1221
+ # JSON.load_file!(path, opts = {})
1222
+ #
1223
+ # Calls:
1224
+ # JSON.parse!(File.read(path, opts))
1225
+ #
1226
+ # See method #parse!
1227
+ def load_file!(filespec, opts = T.unsafe(nil)); end
1228
+
1229
+ # :call-seq:
1230
+ # JSON.parse(source, opts) -> object
1231
+ #
1232
+ # Returns the Ruby objects created by parsing the given +source+.
1233
+ #
1234
+ # Argument +source+ contains the \String to be parsed.
1235
+ #
1236
+ # Argument +opts+, if given, contains a \Hash of options for the parsing.
1237
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1238
+ #
1239
+ # ---
1240
+ #
1241
+ # When +source+ is a \JSON array, returns a Ruby \Array:
1242
+ # source = '["foo", 1.0, true, false, null]'
1243
+ # ruby = JSON.parse(source)
1244
+ # ruby # => ["foo", 1.0, true, false, nil]
1245
+ # ruby.class # => Array
1246
+ #
1247
+ # When +source+ is a \JSON object, returns a Ruby \Hash:
1248
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
1249
+ # ruby = JSON.parse(source)
1250
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
1251
+ # ruby.class # => Hash
1252
+ #
1253
+ # For examples of parsing for all \JSON data types, see
1254
+ # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
1255
+ #
1256
+ # Parses nested JSON objects:
1257
+ # source = <<-EOT
1258
+ # {
1259
+ # "name": "Dave",
1260
+ # "age" :40,
1261
+ # "hats": [
1262
+ # "Cattleman's",
1263
+ # "Panama",
1264
+ # "Tophat"
1265
+ # ]
1266
+ # }
1267
+ # EOT
1268
+ # ruby = JSON.parse(source)
1269
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1270
+ #
1271
+ # ---
1272
+ #
1273
+ # Raises an exception if +source+ is not valid JSON:
1274
+ # # Raises JSON::ParserError (783: unexpected token at ''):
1275
+ # JSON.parse('')
1276
+ def parse(source, opts = T.unsafe(nil)); end
1277
+
1278
+ # :call-seq:
1279
+ # JSON.parse!(source, opts) -> object
1280
+ #
1281
+ # Calls
1282
+ # parse(source, opts)
1283
+ # with +source+ and possibly modified +opts+.
1284
+ #
1285
+ # Differences from JSON.parse:
1286
+ # - Option +max_nesting+, if not provided, defaults to +false+,
1287
+ # which disables checking for nesting depth.
1288
+ # - Option +allow_nan+, if not provided, defaults to +true+.
1289
+ def parse!(source, opts = T.unsafe(nil)); end
1290
+
1291
+ # Returns the JSON parser class that is used by JSON. This is either
1292
+ # JSON::Ext::Parser or JSON::Pure::Parser:
1293
+ # JSON.parser # => JSON::Ext::Parser
1294
+ def parser; end
1295
+
1296
+ # Set the JSON parser class _parser_ to be used by JSON.
1297
+ def parser=(parser); end
1298
+
1299
+ # :call-seq:
1300
+ # JSON.pretty_generate(obj, opts = nil) -> new_string
1301
+ #
1302
+ # Arguments +obj+ and +opts+ here are the same as
1303
+ # arguments +obj+ and +opts+ in JSON.generate.
1304
+ #
1305
+ # Default options are:
1306
+ # {
1307
+ # indent: ' ', # Two spaces
1308
+ # space: ' ', # One space
1309
+ # array_nl: "\n", # Newline
1310
+ # object_nl: "\n" # Newline
1311
+ # }
1312
+ #
1313
+ # Example:
1314
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
1315
+ # json = JSON.pretty_generate(obj)
1316
+ # puts json
1317
+ # Output:
1318
+ # {
1319
+ # "foo": [
1320
+ # "bar",
1321
+ # "baz"
1322
+ # ],
1323
+ # "bat": {
1324
+ # "bam": 0,
1325
+ # "bad": 1
1326
+ # }
1327
+ # }
1328
+ def pretty_generate(obj, opts = T.unsafe(nil)); end
1329
+
1330
+ # :stopdoc:
1331
+ # I want to deprecate these later, so I'll first be silent about them, and later delete them.
1332
+ def pretty_unparse(obj, opts = T.unsafe(nil)); end
1333
+
1334
+ # Recursively calls passed _Proc_ if the parsed data structure is an _Array_ or _Hash_
1335
+ def recurse_proc(result, &proc); end
1336
+
1337
+ def restore(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1338
+
1339
+ # Sets or Returns the JSON generator state class that is used by JSON. This is
1340
+ # either JSON::Ext::Generator::State or JSON::Pure::Generator::State:
1341
+ # JSON.state # => JSON::Ext::Generator::State
1342
+ def state; end
1343
+
1344
+ # Sets or Returns the JSON generator state class that is used by JSON. This is
1345
+ # either JSON::Ext::Generator::State or JSON::Pure::Generator::State:
1346
+ # JSON.state # => JSON::Ext::Generator::State
1347
+ def state=(_arg0); end
1348
+
1349
+ # :stopdoc:
1350
+ # I want to deprecate these later, so I'll first be silent about them, and
1351
+ # later delete them.
1352
+ def unparse(obj, opts = T.unsafe(nil)); end
1353
+ end
1354
+ end
1355
+
1356
+ JSON::CREATE_ID_TLS_KEY = T.let(T.unsafe(nil), String)
1357
+ JSON::DEFAULT_CREATE_ID = T.let(T.unsafe(nil), String)
1358
+
1359
+ class JSON::GenericObject < ::OpenStruct
1360
+ def as_json(*_arg0); end
1361
+ def to_hash; end
1362
+ def to_json(*a); end
1363
+ def |(other); end
1364
+
1365
+ class << self
1366
+ def dump(obj, *args); end
1367
+ def from_hash(object); end
1368
+
1369
+ # Sets the attribute json_creatable
1370
+ #
1371
+ # @param value the value to set the attribute json_creatable to.
1372
+ def json_creatable=(_arg0); end
1373
+
1374
+ # @return [Boolean]
1375
+ def json_creatable?; end
1376
+
1377
+ def json_create(data); end
1378
+ def load(source, proc = T.unsafe(nil), opts = T.unsafe(nil)); end
1379
+ end
1380
+ end
1381
+
1382
+ # The base exception for JSON errors.
1383
+ class JSON::JSONError < ::StandardError
1384
+ class << self
1385
+ def wrap(exception); end
1386
+ end
1387
+ end
1388
+
1389
+ JSON::Parser = JSON::Ext::Parser
1390
+ JSON::State = JSON::Ext::Generator::State
1391
+
1392
+ # For backwards compatibility
1393
+ JSON::UnparserError = JSON::GeneratorError
1394
+
1395
+ # Since Ruby is very dynamic, methods added to the ancestors of
1396
+ # BlankSlate <em>after BlankSlate is defined</em> will show up in the
1397
+ # list of available BlankSlate methods. We handle this by defining a
1398
+ # hook in the Object and Kernel classes that will hide any method
1399
+ # defined after BlankSlate has been loaded.
1400
+ module Kernel
1401
+ private
1402
+
1403
+ # If _object_ is string-like, parse the string and return the parsed result as
1404
+ # a Ruby data structure. Otherwise, generate a JSON text from the Ruby data
1405
+ # structure object and return it.
1406
+ #
1407
+ # The _opts_ argument is passed through to generate/parse respectively. See
1408
+ # generate and parse for their documentation.
1409
+ def JSON(object, *args); end
1410
+
1411
+ # Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
1412
+ # one line.
1413
+ def j(*objs); end
1414
+
1415
+ # Outputs _objs_ to STDOUT as JSON strings in a pretty format, with
1416
+ # indentation and over many lines.
1417
+ def jj(*objs); end
1418
+ end