tickrb 0.1.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.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +15 -0
  4. data/Gemfile +17 -0
  5. data/Gemfile.lock +143 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +112 -0
  8. data/Rakefile +53 -0
  9. data/lib/tickrb/auth.rb +106 -0
  10. data/lib/tickrb/client.rb +144 -0
  11. data/lib/tickrb/mcp_server.rb +445 -0
  12. data/lib/tickrb/token_store.rb +29 -0
  13. data/lib/tickrb/version.rb +6 -0
  14. data/lib/tickrb.rb +37 -0
  15. data/sorbet/config +4 -0
  16. data/sorbet/rbi/gems/.gitattributes +1 -0
  17. data/sorbet/rbi/gems/ast@2.4.3.rbi +585 -0
  18. data/sorbet/rbi/gems/benchmark@0.4.1.rbi +619 -0
  19. data/sorbet/rbi/gems/diff-lcs@1.6.2.rbi +1134 -0
  20. data/sorbet/rbi/gems/dotenv@3.1.8.rbi +295 -0
  21. data/sorbet/rbi/gems/erubi@1.13.1.rbi +155 -0
  22. data/sorbet/rbi/gems/json@2.12.2.rbi +2051 -0
  23. data/sorbet/rbi/gems/language_server-protocol@3.17.0.5.rbi +14244 -0
  24. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +240 -0
  25. data/sorbet/rbi/gems/logger@1.7.0.rbi +963 -0
  26. data/sorbet/rbi/gems/net-http@0.6.0.rbi +4247 -0
  27. data/sorbet/rbi/gems/netrc@0.11.0.rbi +159 -0
  28. data/sorbet/rbi/gems/parallel@1.27.0.rbi +291 -0
  29. data/sorbet/rbi/gems/parser@3.3.8.0.rbi +5535 -0
  30. data/sorbet/rbi/gems/prism@1.4.0.rbi +41732 -0
  31. data/sorbet/rbi/gems/racc@1.8.1.rbi +164 -0
  32. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +403 -0
  33. data/sorbet/rbi/gems/rake@13.3.0.rbi +3031 -0
  34. data/sorbet/rbi/gems/rbi@0.3.3.rbi +6742 -0
  35. data/sorbet/rbi/gems/rbs@3.9.4.rbi +6976 -0
  36. data/sorbet/rbi/gems/regexp_parser@2.10.0.rbi +3795 -0
  37. data/sorbet/rbi/gems/rexml@3.4.1.rbi +5243 -0
  38. data/sorbet/rbi/gems/rspec-core@3.13.4.rbi +11238 -0
  39. data/sorbet/rbi/gems/rspec-expectations@3.13.5.rbi +8189 -0
  40. data/sorbet/rbi/gems/rspec-mocks@3.13.5.rbi +5350 -0
  41. data/sorbet/rbi/gems/rspec-sorbet-types@0.3.0.rbi +130 -0
  42. data/sorbet/rbi/gems/rspec-support@3.13.4.rbi +1630 -0
  43. data/sorbet/rbi/gems/rspec@3.13.1.rbi +83 -0
  44. data/sorbet/rbi/gems/rubocop-ast@1.45.0.rbi +7721 -0
  45. data/sorbet/rbi/gems/rubocop-performance@1.25.0.rbi +9 -0
  46. data/sorbet/rbi/gems/rubocop@1.75.8.rbi +62104 -0
  47. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1318 -0
  48. data/sorbet/rbi/gems/spoom@1.6.3.rbi +6985 -0
  49. data/sorbet/rbi/gems/standard-custom@1.0.2.rbi +9 -0
  50. data/sorbet/rbi/gems/standard-performance@1.8.0.rbi +9 -0
  51. data/sorbet/rbi/gems/standard@1.50.0.rbi +1146 -0
  52. data/sorbet/rbi/gems/tapioca@0.16.11.rbi +3628 -0
  53. data/sorbet/rbi/gems/thor@1.3.2.rbi +4378 -0
  54. data/sorbet/rbi/gems/unicode-display_width@3.1.4.rbi +132 -0
  55. data/sorbet/rbi/gems/unicode-emoji@4.0.4.rbi +251 -0
  56. data/sorbet/rbi/gems/uri@1.0.3.rbi +2325 -0
  57. data/sorbet/rbi/gems/webrick@1.9.1.rbi +2856 -0
  58. data/sorbet/rbi/gems/yard-sorbet@0.9.0.rbi +435 -0
  59. data/sorbet/rbi/gems/yard@0.9.37.rbi +18445 -0
  60. data/sorbet/rbi/tickrb.rbi +9 -0
  61. data/sorbet/tapioca.yml +10 -0
  62. data/test_api_direct.rb +98 -0
  63. data/test_mcp_server.rb +157 -0
  64. data/tickrb.gemspec +47 -0
  65. metadata +278 -0
@@ -0,0 +1,2051 @@
1
+ # typed: false
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
+
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
28
+ end
29
+
30
+ # = JavaScript \Object Notation (\JSON)
31
+ #
32
+ # \JSON is a lightweight data-interchange format.
33
+ #
34
+ # A \JSON value is one of the following:
35
+ # - Double-quoted text: <tt>"foo"</tt>.
36
+ # - Number: +1+, +1.0+, +2.0e2+.
37
+ # - Boolean: +true+, +false+.
38
+ # - Null: +null+.
39
+ # - \Array: an ordered list of values, enclosed by square brackets:
40
+ # ["foo", 1, 1.0, 2.0e2, true, false, null]
41
+ #
42
+ # - \Object: a collection of name/value pairs, enclosed by curly braces;
43
+ # each name is double-quoted text;
44
+ # the values may be any \JSON values:
45
+ # {"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}
46
+ #
47
+ # A \JSON array or object may contain nested arrays, objects, and scalars
48
+ # to any depth:
49
+ # {"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}
50
+ # [{"foo": 0, "bar": 1}, ["baz", 2]]
51
+ #
52
+ # == Using \Module \JSON
53
+ #
54
+ # To make module \JSON available in your code, begin with:
55
+ # require 'json'
56
+ #
57
+ # All examples here assume that this has been done.
58
+ #
59
+ # === Parsing \JSON
60
+ #
61
+ # You can parse a \String containing \JSON data using
62
+ # either of two methods:
63
+ # - <tt>JSON.parse(source, opts)</tt>
64
+ # - <tt>JSON.parse!(source, opts)</tt>
65
+ #
66
+ # where
67
+ # - +source+ is a Ruby object.
68
+ # - +opts+ is a \Hash object containing options
69
+ # that control both input allowed and output formatting.
70
+ #
71
+ # The difference between the two methods
72
+ # is that JSON.parse! omits some checks
73
+ # and may not be safe for some +source+ data;
74
+ # use it only for data from trusted sources.
75
+ # Use the safer method JSON.parse for less trusted sources.
76
+ #
77
+ # ==== Parsing \JSON Arrays
78
+ #
79
+ # When +source+ is a \JSON array, JSON.parse by default returns a Ruby \Array:
80
+ # json = '["foo", 1, 1.0, 2.0e2, true, false, null]'
81
+ # ruby = JSON.parse(json)
82
+ # ruby # => ["foo", 1, 1.0, 200.0, true, false, nil]
83
+ # ruby.class # => Array
84
+ #
85
+ # The \JSON array may contain nested arrays, objects, and scalars
86
+ # to any depth:
87
+ # json = '[{"foo": 0, "bar": 1}, ["baz", 2]]'
88
+ # JSON.parse(json) # => [{"foo"=>0, "bar"=>1}, ["baz", 2]]
89
+ #
90
+ # ==== Parsing \JSON \Objects
91
+ #
92
+ # When the source is a \JSON object, JSON.parse by default returns a Ruby \Hash:
93
+ # json = '{"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}'
94
+ # ruby = JSON.parse(json)
95
+ # ruby # => {"a"=>"foo", "b"=>1, "c"=>1.0, "d"=>200.0, "e"=>true, "f"=>false, "g"=>nil}
96
+ # ruby.class # => Hash
97
+ #
98
+ # The \JSON object may contain nested arrays, objects, and scalars
99
+ # to any depth:
100
+ # json = '{"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}'
101
+ # JSON.parse(json) # => {"foo"=>{"bar"=>1, "baz"=>2}, "bat"=>[0, 1, 2]}
102
+ #
103
+ # ==== Parsing \JSON Scalars
104
+ #
105
+ # When the source is a \JSON scalar (not an array or object),
106
+ # JSON.parse returns a Ruby scalar.
107
+ #
108
+ # \String:
109
+ # ruby = JSON.parse('"foo"')
110
+ # ruby # => 'foo'
111
+ # ruby.class # => String
112
+ # \Integer:
113
+ # ruby = JSON.parse('1')
114
+ # ruby # => 1
115
+ # ruby.class # => Integer
116
+ # \Float:
117
+ # ruby = JSON.parse('1.0')
118
+ # ruby # => 1.0
119
+ # ruby.class # => Float
120
+ # ruby = JSON.parse('2.0e2')
121
+ # ruby # => 200
122
+ # ruby.class # => Float
123
+ # Boolean:
124
+ # ruby = JSON.parse('true')
125
+ # ruby # => true
126
+ # ruby.class # => TrueClass
127
+ # ruby = JSON.parse('false')
128
+ # ruby # => false
129
+ # ruby.class # => FalseClass
130
+ # Null:
131
+ # ruby = JSON.parse('null')
132
+ # ruby # => nil
133
+ # ruby.class # => NilClass
134
+ #
135
+ # ==== Parsing Options
136
+ #
137
+ # ====== Input Options
138
+ #
139
+ # Option +max_nesting+ (\Integer) specifies the maximum nesting depth allowed;
140
+ # defaults to +100+; specify +false+ to disable depth checking.
141
+ #
142
+ # With the default, +false+:
143
+ # source = '[0, [1, [2, [3]]]]'
144
+ # ruby = JSON.parse(source)
145
+ # ruby # => [0, [1, [2, [3]]]]
146
+ # Too deep:
147
+ # # Raises JSON::NestingError (nesting of 2 is too deep):
148
+ # JSON.parse(source, {max_nesting: 1})
149
+ # Bad value:
150
+ # # Raises TypeError (wrong argument type Symbol (expected Fixnum)):
151
+ # JSON.parse(source, {max_nesting: :foo})
152
+ #
153
+ # ---
154
+ #
155
+ # Option +allow_nan+ (boolean) specifies whether to allow
156
+ # NaN, Infinity, and MinusInfinity in +source+;
157
+ # defaults to +false+.
158
+ #
159
+ # With the default, +false+:
160
+ # # Raises JSON::ParserError (225: unexpected token at '[NaN]'):
161
+ # JSON.parse('[NaN]')
162
+ # # Raises JSON::ParserError (232: unexpected token at '[Infinity]'):
163
+ # JSON.parse('[Infinity]')
164
+ # # Raises JSON::ParserError (248: unexpected token at '[-Infinity]'):
165
+ # JSON.parse('[-Infinity]')
166
+ # Allow:
167
+ # source = '[NaN, Infinity, -Infinity]'
168
+ # ruby = JSON.parse(source, {allow_nan: true})
169
+ # ruby # => [NaN, Infinity, -Infinity]
170
+ #
171
+ # ====== Output Options
172
+ #
173
+ # Option +symbolize_names+ (boolean) specifies whether returned \Hash keys
174
+ # should be Symbols;
175
+ # defaults to +false+ (use Strings).
176
+ #
177
+ # With the default, +false+:
178
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
179
+ # ruby = JSON.parse(source)
180
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
181
+ # Use Symbols:
182
+ # ruby = JSON.parse(source, {symbolize_names: true})
183
+ # ruby # => {:a=>"foo", :b=>1.0, :c=>true, :d=>false, :e=>nil}
184
+ #
185
+ # ---
186
+ #
187
+ # Option +object_class+ (\Class) specifies the Ruby class to be used
188
+ # for each \JSON object;
189
+ # defaults to \Hash.
190
+ #
191
+ # With the default, \Hash:
192
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
193
+ # ruby = JSON.parse(source)
194
+ # ruby.class # => Hash
195
+ # Use class \OpenStruct:
196
+ # ruby = JSON.parse(source, {object_class: OpenStruct})
197
+ # ruby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil>
198
+ #
199
+ # ---
200
+ #
201
+ # Option +array_class+ (\Class) specifies the Ruby class to be used
202
+ # for each \JSON array;
203
+ # defaults to \Array.
204
+ #
205
+ # With the default, \Array:
206
+ # source = '["foo", 1.0, true, false, null]'
207
+ # ruby = JSON.parse(source)
208
+ # ruby.class # => Array
209
+ # Use class \Set:
210
+ # ruby = JSON.parse(source, {array_class: Set})
211
+ # ruby # => #<Set: {"foo", 1.0, true, false, nil}>
212
+ #
213
+ # ---
214
+ #
215
+ # Option +create_additions+ (boolean) specifies whether to use \JSON additions in parsing.
216
+ # See {\JSON Additions}[#module-JSON-label-JSON+Additions].
217
+ #
218
+ # === Generating \JSON
219
+ #
220
+ # To generate a Ruby \String containing \JSON data,
221
+ # use method <tt>JSON.generate(source, opts)</tt>, where
222
+ # - +source+ is a Ruby object.
223
+ # - +opts+ is a \Hash object containing options
224
+ # that control both input allowed and output formatting.
225
+ #
226
+ # ==== Generating \JSON from Arrays
227
+ #
228
+ # When the source is a Ruby \Array, JSON.generate returns
229
+ # a \String containing a \JSON array:
230
+ # ruby = [0, 's', :foo]
231
+ # json = JSON.generate(ruby)
232
+ # json # => '[0,"s","foo"]'
233
+ #
234
+ # The Ruby \Array array may contain nested arrays, hashes, and scalars
235
+ # to any depth:
236
+ # ruby = [0, [1, 2], {foo: 3, bar: 4}]
237
+ # json = JSON.generate(ruby)
238
+ # json # => '[0,[1,2],{"foo":3,"bar":4}]'
239
+ #
240
+ # ==== Generating \JSON from Hashes
241
+ #
242
+ # When the source is a Ruby \Hash, JSON.generate returns
243
+ # a \String containing a \JSON object:
244
+ # ruby = {foo: 0, bar: 's', baz: :bat}
245
+ # json = JSON.generate(ruby)
246
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
247
+ #
248
+ # The Ruby \Hash array may contain nested arrays, hashes, and scalars
249
+ # to any depth:
250
+ # ruby = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
251
+ # json = JSON.generate(ruby)
252
+ # json # => '{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}'
253
+ #
254
+ # ==== Generating \JSON from Other Objects
255
+ #
256
+ # When the source is neither an \Array nor a \Hash,
257
+ # the generated \JSON data depends on the class of the source.
258
+ #
259
+ # When the source is a Ruby \Integer or \Float, JSON.generate returns
260
+ # a \String containing a \JSON number:
261
+ # JSON.generate(42) # => '42'
262
+ # JSON.generate(0.42) # => '0.42'
263
+ #
264
+ # When the source is a Ruby \String, JSON.generate returns
265
+ # a \String containing a \JSON string (with double-quotes):
266
+ # JSON.generate('A string') # => '"A string"'
267
+ #
268
+ # When the source is +true+, +false+ or +nil+, JSON.generate returns
269
+ # a \String containing the corresponding \JSON token:
270
+ # JSON.generate(true) # => 'true'
271
+ # JSON.generate(false) # => 'false'
272
+ # JSON.generate(nil) # => 'null'
273
+ #
274
+ # When the source is none of the above, JSON.generate returns
275
+ # a \String containing a \JSON string representation of the source:
276
+ # JSON.generate(:foo) # => '"foo"'
277
+ # JSON.generate(Complex(0, 0)) # => '"0+0i"'
278
+ # JSON.generate(Dir.new('.')) # => '"#<Dir>"'
279
+ #
280
+ # ==== Generating Options
281
+ #
282
+ # ====== Input Options
283
+ #
284
+ # Option +allow_nan+ (boolean) specifies whether
285
+ # +NaN+, +Infinity+, and <tt>-Infinity</tt> may be generated;
286
+ # defaults to +false+.
287
+ #
288
+ # With the default, +false+:
289
+ # # Raises JSON::GeneratorError (920: NaN not allowed in JSON):
290
+ # JSON.generate(JSON::NaN)
291
+ # # Raises JSON::GeneratorError (917: Infinity not allowed in JSON):
292
+ # JSON.generate(JSON::Infinity)
293
+ # # Raises JSON::GeneratorError (917: -Infinity not allowed in JSON):
294
+ # JSON.generate(JSON::MinusInfinity)
295
+ #
296
+ # Allow:
297
+ # ruby = [Float::NaN, Float::Infinity, Float::MinusInfinity]
298
+ # JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,-Infinity]'
299
+ #
300
+ # ---
301
+ #
302
+ # Option +max_nesting+ (\Integer) specifies the maximum nesting depth
303
+ # in +obj+; defaults to +100+.
304
+ #
305
+ # With the default, +100+:
306
+ # obj = [[[[[[0]]]]]]
307
+ # JSON.generate(obj) # => '[[[[[[0]]]]]]'
308
+ #
309
+ # Too deep:
310
+ # # Raises JSON::NestingError (nesting of 2 is too deep):
311
+ # JSON.generate(obj, max_nesting: 2)
312
+ #
313
+ # ====== Escaping Options
314
+ #
315
+ # Options +script_safe+ (boolean) specifies wether <tt>'\u2028'</tt>, <tt>'\u2029'</tt>
316
+ # and <tt>'/'</tt> should be escaped as to make the JSON object safe to interpolate in script
317
+ # tags.
318
+ #
319
+ # Options +ascii_only+ (boolean) specifies wether all characters outside the ASCII range
320
+ # should be escaped.
321
+ #
322
+ # ====== Output Options
323
+ #
324
+ # The default formatting options generate the most compact
325
+ # \JSON data, all on one line and with no whitespace.
326
+ #
327
+ # You can use these formatting options to generate
328
+ # \JSON data in a more open format, using whitespace.
329
+ # See also JSON.pretty_generate.
330
+ #
331
+ # - Option +array_nl+ (\String) specifies a string (usually a newline)
332
+ # to be inserted after each \JSON array; defaults to the empty \String, <tt>''</tt>.
333
+ # - Option +object_nl+ (\String) specifies a string (usually a newline)
334
+ # to be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>.
335
+ # - Option +indent+ (\String) specifies the string (usually spaces) to be
336
+ # used for indentation; defaults to the empty \String, <tt>''</tt>;
337
+ # defaults to the empty \String, <tt>''</tt>;
338
+ # has no effect unless options +array_nl+ or +object_nl+ specify newlines.
339
+ # - Option +space+ (\String) specifies a string (usually a space) to be
340
+ # inserted after the colon in each \JSON object's pair;
341
+ # defaults to the empty \String, <tt>''</tt>.
342
+ # - Option +space_before+ (\String) specifies a string (usually a space) to be
343
+ # inserted before the colon in each \JSON object's pair;
344
+ # defaults to the empty \String, <tt>''</tt>.
345
+ #
346
+ # In this example, +obj+ is used first to generate the shortest
347
+ # \JSON data (no whitespace), then again with all formatting options
348
+ # specified:
349
+ #
350
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
351
+ # json = JSON.generate(obj)
352
+ # puts 'Compact:', json
353
+ # opts = {
354
+ # array_nl: "\n",
355
+ # object_nl: "\n",
356
+ # indent: ' ',
357
+ # space_before: ' ',
358
+ # space: ' '
359
+ # }
360
+ # puts 'Open:', JSON.generate(obj, opts)
361
+ #
362
+ # Output:
363
+ # Compact:
364
+ # {"foo":["bar","baz"],"bat":{"bam":0,"bad":1}}
365
+ # Open:
366
+ # {
367
+ # "foo" : [
368
+ # "bar",
369
+ # "baz"
370
+ # ],
371
+ # "bat" : {
372
+ # "bam" : 0,
373
+ # "bad" : 1
374
+ # }
375
+ # }
376
+ #
377
+ # == \JSON Additions
378
+ #
379
+ # When you "round trip" a non-\String object from Ruby to \JSON and back,
380
+ # you have a new \String, instead of the object you began with:
381
+ # ruby0 = Range.new(0, 2)
382
+ # json = JSON.generate(ruby0)
383
+ # json # => '0..2"'
384
+ # ruby1 = JSON.parse(json)
385
+ # ruby1 # => '0..2'
386
+ # ruby1.class # => String
387
+ #
388
+ # You can use \JSON _additions_ to preserve the original object.
389
+ # The addition is an extension of a ruby class, so that:
390
+ # - \JSON.generate stores more information in the \JSON string.
391
+ # - \JSON.parse, called with option +create_additions+,
392
+ # uses that information to create a proper Ruby object.
393
+ #
394
+ # This example shows a \Range being generated into \JSON
395
+ # and parsed back into Ruby, both without and with
396
+ # the addition for \Range:
397
+ # ruby = Range.new(0, 2)
398
+ # # This passage does not use the addition for Range.
399
+ # json0 = JSON.generate(ruby)
400
+ # ruby0 = JSON.parse(json0)
401
+ # # This passage uses the addition for Range.
402
+ # require 'json/add/range'
403
+ # json1 = JSON.generate(ruby)
404
+ # ruby1 = JSON.parse(json1, create_additions: true)
405
+ # # Make a nice display.
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})
413
+ # EOT
414
+ # puts display
415
+ #
416
+ # This output shows the different results:
417
+ # Generated JSON:
418
+ # Without addition: "0..2" (String)
419
+ # With addition: {"json_class":"Range","a":[0,2,false]} (String)
420
+ # Parsed JSON:
421
+ # Without addition: "0..2" (String)
422
+ # With addition: 0..2 (Range)
423
+ #
424
+ # The \JSON module includes additions for certain classes.
425
+ # You can also craft custom additions.
426
+ # See {Custom \JSON Additions}[#module-JSON-label-Custom+JSON+Additions].
427
+ #
428
+ # === Built-in Additions
429
+ #
430
+ # The \JSON module includes additions for certain classes.
431
+ # To use an addition, +require+ its source:
432
+ # - BigDecimal: <tt>require 'json/add/bigdecimal'</tt>
433
+ # - Complex: <tt>require 'json/add/complex'</tt>
434
+ # - Date: <tt>require 'json/add/date'</tt>
435
+ # - DateTime: <tt>require 'json/add/date_time'</tt>
436
+ # - Exception: <tt>require 'json/add/exception'</tt>
437
+ # - OpenStruct: <tt>require 'json/add/ostruct'</tt>
438
+ # - Range: <tt>require 'json/add/range'</tt>
439
+ # - Rational: <tt>require 'json/add/rational'</tt>
440
+ # - Regexp: <tt>require 'json/add/regexp'</tt>
441
+ # - Set: <tt>require 'json/add/set'</tt>
442
+ # - Struct: <tt>require 'json/add/struct'</tt>
443
+ # - Symbol: <tt>require 'json/add/symbol'</tt>
444
+ # - Time: <tt>require 'json/add/time'</tt>
445
+ #
446
+ # To reduce punctuation clutter, the examples below
447
+ # show the generated \JSON via +puts+, rather than the usual +inspect+,
448
+ #
449
+ # \BigDecimal:
450
+ # require 'json/add/bigdecimal'
451
+ # ruby0 = BigDecimal(0) # 0.0
452
+ # json = JSON.generate(ruby0) # {"json_class":"BigDecimal","b":"27:0.0"}
453
+ # ruby1 = JSON.parse(json, create_additions: true) # 0.0
454
+ # ruby1.class # => BigDecimal
455
+ #
456
+ # \Complex:
457
+ # require 'json/add/complex'
458
+ # ruby0 = Complex(1+0i) # 1+0i
459
+ # json = JSON.generate(ruby0) # {"json_class":"Complex","r":1,"i":0}
460
+ # ruby1 = JSON.parse(json, create_additions: true) # 1+0i
461
+ # ruby1.class # Complex
462
+ #
463
+ # \Date:
464
+ # require 'json/add/date'
465
+ # ruby0 = Date.today # 2020-05-02
466
+ # json = JSON.generate(ruby0) # {"json_class":"Date","y":2020,"m":5,"d":2,"sg":2299161.0}
467
+ # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02
468
+ # ruby1.class # Date
469
+ #
470
+ # \DateTime:
471
+ # require 'json/add/date_time'
472
+ # ruby0 = DateTime.now # 2020-05-02T10:38:13-05:00
473
+ # 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}
474
+ # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02T10:38:13-05:00
475
+ # ruby1.class # DateTime
476
+ #
477
+ # \Exception (and its subclasses including \RuntimeError):
478
+ # require 'json/add/exception'
479
+ # ruby0 = Exception.new('A message') # A message
480
+ # json = JSON.generate(ruby0) # {"json_class":"Exception","m":"A message","b":null}
481
+ # ruby1 = JSON.parse(json, create_additions: true) # A message
482
+ # ruby1.class # Exception
483
+ # ruby0 = RuntimeError.new('Another message') # Another message
484
+ # json = JSON.generate(ruby0) # {"json_class":"RuntimeError","m":"Another message","b":null}
485
+ # ruby1 = JSON.parse(json, create_additions: true) # Another message
486
+ # ruby1.class # RuntimeError
487
+ #
488
+ # \OpenStruct:
489
+ # require 'json/add/ostruct'
490
+ # ruby0 = OpenStruct.new(name: 'Matz', language: 'Ruby') # #<OpenStruct name="Matz", language="Ruby">
491
+ # json = JSON.generate(ruby0) # {"json_class":"OpenStruct","t":{"name":"Matz","language":"Ruby"}}
492
+ # ruby1 = JSON.parse(json, create_additions: true) # #<OpenStruct name="Matz", language="Ruby">
493
+ # ruby1.class # OpenStruct
494
+ #
495
+ # \Range:
496
+ # require 'json/add/range'
497
+ # ruby0 = Range.new(0, 2) # 0..2
498
+ # json = JSON.generate(ruby0) # {"json_class":"Range","a":[0,2,false]}
499
+ # ruby1 = JSON.parse(json, create_additions: true) # 0..2
500
+ # ruby1.class # Range
501
+ #
502
+ # \Rational:
503
+ # require 'json/add/rational'
504
+ # ruby0 = Rational(1, 3) # 1/3
505
+ # json = JSON.generate(ruby0) # {"json_class":"Rational","n":1,"d":3}
506
+ # ruby1 = JSON.parse(json, create_additions: true) # 1/3
507
+ # ruby1.class # Rational
508
+ #
509
+ # \Regexp:
510
+ # require 'json/add/regexp'
511
+ # ruby0 = Regexp.new('foo') # (?-mix:foo)
512
+ # json = JSON.generate(ruby0) # {"json_class":"Regexp","o":0,"s":"foo"}
513
+ # ruby1 = JSON.parse(json, create_additions: true) # (?-mix:foo)
514
+ # ruby1.class # Regexp
515
+ #
516
+ # \Set:
517
+ # require 'json/add/set'
518
+ # ruby0 = Set.new([0, 1, 2]) # #<Set: {0, 1, 2}>
519
+ # json = JSON.generate(ruby0) # {"json_class":"Set","a":[0,1,2]}
520
+ # ruby1 = JSON.parse(json, create_additions: true) # #<Set: {0, 1, 2}>
521
+ # ruby1.class # Set
522
+ #
523
+ # \Struct:
524
+ # require 'json/add/struct'
525
+ # Customer = Struct.new(:name, :address) # Customer
526
+ # ruby0 = Customer.new("Dave", "123 Main") # #<struct Customer name="Dave", address="123 Main">
527
+ # json = JSON.generate(ruby0) # {"json_class":"Customer","v":["Dave","123 Main"]}
528
+ # ruby1 = JSON.parse(json, create_additions: true) # #<struct Customer name="Dave", address="123 Main">
529
+ # ruby1.class # Customer
530
+ #
531
+ # \Symbol:
532
+ # require 'json/add/symbol'
533
+ # ruby0 = :foo # foo
534
+ # json = JSON.generate(ruby0) # {"json_class":"Symbol","s":"foo"}
535
+ # ruby1 = JSON.parse(json, create_additions: true) # foo
536
+ # ruby1.class # Symbol
537
+ #
538
+ # \Time:
539
+ # require 'json/add/time'
540
+ # ruby0 = Time.now # 2020-05-02 11:28:26 -0500
541
+ # json = JSON.generate(ruby0) # {"json_class":"Time","s":1588436906,"n":840560000}
542
+ # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02 11:28:26 -0500
543
+ # ruby1.class # Time
544
+ #
545
+ #
546
+ # === Custom \JSON Additions
547
+ #
548
+ # In addition to the \JSON additions provided,
549
+ # you can craft \JSON additions of your own,
550
+ # either for Ruby built-in classes or for user-defined classes.
551
+ #
552
+ # Here's a user-defined class +Foo+:
553
+ # class Foo
554
+ # attr_accessor :bar, :baz
555
+ # def initialize(bar, baz)
556
+ # self.bar = bar
557
+ # self.baz = baz
558
+ # end
559
+ # end
560
+ #
561
+ # Here's the \JSON addition for it:
562
+ # # Extend class Foo with JSON addition.
563
+ # class Foo
564
+ # # Serialize Foo object with its class name and arguments
565
+ # def to_json(*args)
566
+ # {
567
+ # JSON.create_id => self.class.name,
568
+ # 'a' => [ bar, baz ]
569
+ # }.to_json(*args)
570
+ # end
571
+ # # Deserialize JSON string by constructing new Foo object with arguments.
572
+ # def self.json_create(object)
573
+ # new(*object['a'])
574
+ # end
575
+ # end
576
+ #
577
+ # Demonstration:
578
+ # require 'json'
579
+ # # This Foo object has no custom addition.
580
+ # foo0 = Foo.new(0, 1)
581
+ # json0 = JSON.generate(foo0)
582
+ # obj0 = JSON.parse(json0)
583
+ # # Lood the custom addition.
584
+ # require_relative 'foo_addition'
585
+ # # This foo has the custom addition.
586
+ # foo1 = Foo.new(0, 1)
587
+ # json1 = JSON.generate(foo1)
588
+ # obj1 = JSON.parse(json1, create_additions: true)
589
+ # # Make a nice display.
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})
597
+ # EOT
598
+ # puts display
599
+ #
600
+ # Output:
601
+ #
602
+ # Generated JSON:
603
+ # Without custom addition: "#<Foo:0x0000000006534e80>" (String)
604
+ # With custom addition: {"json_class":"Foo","a":[0,1]} (String)
605
+ # Parsed JSON:
606
+ # Without custom addition: "#<Foo:0x0000000006534e80>" (String)
607
+ # With custom addition: #<Foo:0x0000000006473bb8 @bar=0, @baz=1> (Foo)
608
+ #
609
+ # source://json//lib/json/version.rb#3
610
+ module JSON
611
+ private
612
+
613
+ # :call-seq:
614
+ # JSON.dump(obj, io = nil, limit = nil)
615
+ #
616
+ # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
617
+ #
618
+ # The default options can be changed via method JSON.dump_default_options.
619
+ #
620
+ # - Argument +io+, if given, should respond to method +write+;
621
+ # the \JSON \String is written to +io+, and +io+ is returned.
622
+ # If +io+ is not given, the \JSON \String is returned.
623
+ # - Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
624
+ #
625
+ # ---
626
+ #
627
+ # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
628
+ # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
629
+ # json = JSON.dump(obj)
630
+ # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
631
+ #
632
+ # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
633
+ # path = 't.json'
634
+ # File.open(path, 'w') do |file|
635
+ # JSON.dump(obj, file)
636
+ # end # => #<File:t.json (closed)>
637
+ # puts File.read(path)
638
+ # Output:
639
+ # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
640
+ #
641
+ # source://json//lib/json/common.rb#892
642
+ def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
643
+
644
+ # :call-seq:
645
+ # JSON.fast_generate(obj, opts) -> new_string
646
+ #
647
+ # Arguments +obj+ and +opts+ here are the same as
648
+ # arguments +obj+ and +opts+ in JSON.generate.
649
+ #
650
+ # By default, generates \JSON data without checking
651
+ # for circular references in +obj+ (option +max_nesting+ set to +false+, disabled).
652
+ #
653
+ # Raises an exception if +obj+ contains circular references:
654
+ # a = []; b = []; a.push(b); b.push(a)
655
+ # # Raises SystemStackError (stack level too deep):
656
+ # JSON.fast_generate(a)
657
+ #
658
+ # source://json//lib/json/common.rb#445
659
+ def fast_generate(obj, opts = T.unsafe(nil)); end
660
+
661
+ # source://json//lib/json/common.rb#937
662
+ def fast_unparse(*_arg0, **_arg1, &_arg2); end
663
+
664
+ # :call-seq:
665
+ # JSON.generate(obj, opts = nil) -> new_string
666
+ #
667
+ # Returns a \String containing the generated \JSON data.
668
+ #
669
+ # See also JSON.fast_generate, JSON.pretty_generate.
670
+ #
671
+ # Argument +obj+ is the Ruby object to be converted to \JSON.
672
+ #
673
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
674
+ # See {Generating Options}[#module-JSON-label-Generating+Options].
675
+ #
676
+ # ---
677
+ #
678
+ # When +obj+ is an \Array, returns a \String containing a \JSON array:
679
+ # obj = ["foo", 1.0, true, false, nil]
680
+ # json = JSON.generate(obj)
681
+ # json # => '["foo",1.0,true,false,null]'
682
+ #
683
+ # When +obj+ is a \Hash, returns a \String containing a \JSON object:
684
+ # obj = {foo: 0, bar: 's', baz: :bat}
685
+ # json = JSON.generate(obj)
686
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
687
+ #
688
+ # For examples of generating from other Ruby objects, see
689
+ # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
690
+ #
691
+ # ---
692
+ #
693
+ # Raises an exception if any formatting option is not a \String.
694
+ #
695
+ # Raises an exception if +obj+ contains circular references:
696
+ # a = []; b = []; a.push(b); b.push(a)
697
+ # # Raises JSON::NestingError (nesting of 100 is too deep):
698
+ # JSON.generate(a)
699
+ #
700
+ # source://json//lib/json/common.rb#424
701
+ def generate(obj, opts = T.unsafe(nil)); end
702
+
703
+ # :call-seq:
704
+ # JSON.load(source, proc = nil, options = {}) -> object
705
+ #
706
+ # Returns the Ruby objects created by parsing the given +source+.
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
+ #
718
+ # - Argument +source+ must be, or be convertible to, a \String:
719
+ # - If +source+ responds to instance method +to_str+,
720
+ # <tt>source.to_str</tt> becomes the source.
721
+ # - If +source+ responds to instance method +to_io+,
722
+ # <tt>source.to_io.read</tt> becomes the source.
723
+ # - If +source+ responds to instance method +read+,
724
+ # <tt>source.read</tt> becomes the source.
725
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
726
+ # - Option +allow_blank+ specifies a truthy value.
727
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
728
+ # - Otherwise, +source+ remains the source.
729
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
730
+ # It will be called recursively with each result (depth-first order).
731
+ # See details below.
732
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
733
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
734
+ # The default options can be changed via method JSON.load_default_options=.
735
+ #
736
+ # ---
737
+ #
738
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
739
+ # <tt>parse(source, opts)</tt>; see #parse.
740
+ #
741
+ # Source for following examples:
742
+ # source = <<~JSON
743
+ # {
744
+ # "name": "Dave",
745
+ # "age" :40,
746
+ # "hats": [
747
+ # "Cattleman's",
748
+ # "Panama",
749
+ # "Tophat"
750
+ # ]
751
+ # }
752
+ # JSON
753
+ #
754
+ # Load a \String:
755
+ # ruby = JSON.load(source)
756
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
757
+ #
758
+ # Load an \IO object:
759
+ # require 'stringio'
760
+ # object = JSON.load(StringIO.new(source))
761
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
762
+ #
763
+ # Load a \File object:
764
+ # path = 't.json'
765
+ # File.write(path, source)
766
+ # File.open(path) do |file|
767
+ # JSON.load(file)
768
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
769
+ #
770
+ # ---
771
+ #
772
+ # When +proc+ is given:
773
+ # - Modifies +source+ as above.
774
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
775
+ # - Recursively calls <tt>proc(result)</tt>.
776
+ # - Returns the final result.
777
+ #
778
+ # Example:
779
+ # require 'json'
780
+ #
781
+ # # Some classes for the example.
782
+ # class Base
783
+ # def initialize(attributes)
784
+ # @attributes = attributes
785
+ # end
786
+ # end
787
+ # class User < Base; end
788
+ # class Account < Base; end
789
+ # class Admin < Base; end
790
+ # # The JSON source.
791
+ # json = <<-EOF
792
+ # {
793
+ # "users": [
794
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
795
+ # {"type": "User", "username": "john", "email": "john@example.com"}
796
+ # ],
797
+ # "accounts": [
798
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
799
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
800
+ # ],
801
+ # "admins": {"type": "Admin", "password": "0wn3d"}
802
+ # }
803
+ # EOF
804
+ # # Deserializer method.
805
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
806
+ # type = obj.is_a?(Hash) && obj["type"]
807
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
808
+ # end
809
+ # # Call to JSON.load
810
+ # ruby = JSON.load(json, proc {|obj|
811
+ # case obj
812
+ # when Hash
813
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
814
+ # when Array
815
+ # obj.map! {|v| deserialize_obj v }
816
+ # end
817
+ # })
818
+ # pp ruby
819
+ # Output:
820
+ # {"users"=>
821
+ # [#<User:0x00000000064c4c98
822
+ # @attributes=
823
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
824
+ # #<User:0x00000000064c4bd0
825
+ # @attributes=
826
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
827
+ # "accounts"=>
828
+ # [{"account"=>
829
+ # #<Account:0x00000000064c4928
830
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
831
+ # {"account"=>
832
+ # #<Account:0x00000000064c4680
833
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
834
+ # "admins"=>
835
+ # #<Admin:0x00000000064c41f8
836
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
837
+ #
838
+ # source://json//lib/json/common.rb#826
839
+ def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
840
+
841
+ # :call-seq:
842
+ # JSON.load_file(path, opts={}) -> object
843
+ #
844
+ # Calls:
845
+ # parse(File.read(path), opts)
846
+ #
847
+ # See method #parse.
848
+ #
849
+ # source://json//lib/json/common.rb#373
850
+ def load_file(filespec, opts = T.unsafe(nil)); end
851
+
852
+ # :call-seq:
853
+ # JSON.load_file!(path, opts = {})
854
+ #
855
+ # Calls:
856
+ # JSON.parse!(File.read(path, opts))
857
+ #
858
+ # See method #parse!
859
+ #
860
+ # source://json//lib/json/common.rb#384
861
+ def load_file!(filespec, opts = T.unsafe(nil)); end
862
+
863
+ # :call-seq:
864
+ # JSON.parse(source, opts) -> object
865
+ #
866
+ # Returns the Ruby objects created by parsing the given +source+.
867
+ #
868
+ # Argument +source+ contains the \String to be parsed.
869
+ #
870
+ # Argument +opts+, if given, contains a \Hash of options for the parsing.
871
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
872
+ #
873
+ # ---
874
+ #
875
+ # When +source+ is a \JSON array, returns a Ruby \Array:
876
+ # source = '["foo", 1.0, true, false, null]'
877
+ # ruby = JSON.parse(source)
878
+ # ruby # => ["foo", 1.0, true, false, nil]
879
+ # ruby.class # => Array
880
+ #
881
+ # When +source+ is a \JSON object, returns a Ruby \Hash:
882
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
883
+ # ruby = JSON.parse(source)
884
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
885
+ # ruby.class # => Hash
886
+ #
887
+ # For examples of parsing for all \JSON data types, see
888
+ # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
889
+ #
890
+ # Parses nested JSON objects:
891
+ # source = <<~JSON
892
+ # {
893
+ # "name": "Dave",
894
+ # "age" :40,
895
+ # "hats": [
896
+ # "Cattleman's",
897
+ # "Panama",
898
+ # "Tophat"
899
+ # ]
900
+ # }
901
+ # JSON
902
+ # ruby = JSON.parse(source)
903
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
904
+ #
905
+ # ---
906
+ #
907
+ # Raises an exception if +source+ is not valid JSON:
908
+ # # Raises JSON::ParserError (783: unexpected token at ''):
909
+ # JSON.parse('')
910
+ #
911
+ # source://json//lib/json/common.rb#336
912
+ def parse(source, opts = T.unsafe(nil)); end
913
+
914
+ # :call-seq:
915
+ # JSON.parse!(source, opts) -> object
916
+ #
917
+ # Calls
918
+ # parse(source, opts)
919
+ # with +source+ and possibly modified +opts+.
920
+ #
921
+ # Differences from JSON.parse:
922
+ # - Option +max_nesting+, if not provided, defaults to +false+,
923
+ # which disables checking for nesting depth.
924
+ # - Option +allow_nan+, if not provided, defaults to +true+.
925
+ #
926
+ # source://json//lib/json/common.rb#358
927
+ def parse!(source, opts = T.unsafe(nil)); end
928
+
929
+ # :call-seq:
930
+ # JSON.pretty_generate(obj, opts = nil) -> new_string
931
+ #
932
+ # Arguments +obj+ and +opts+ here are the same as
933
+ # arguments +obj+ and +opts+ in JSON.generate.
934
+ #
935
+ # Default options are:
936
+ # {
937
+ # indent: ' ', # Two spaces
938
+ # space: ' ', # One space
939
+ # array_nl: "\n", # Newline
940
+ # object_nl: "\n" # Newline
941
+ # }
942
+ #
943
+ # Example:
944
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
945
+ # json = JSON.pretty_generate(obj)
946
+ # puts json
947
+ # Output:
948
+ # {
949
+ # "foo": [
950
+ # "bar",
951
+ # "baz"
952
+ # ],
953
+ # "bat": {
954
+ # "bam": 0,
955
+ # "bad": 1
956
+ # }
957
+ # }
958
+ #
959
+ # source://json//lib/json/common.rb#492
960
+ def pretty_generate(obj, opts = T.unsafe(nil)); end
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
+
968
+ # :stopdoc:
969
+ # All these were meant to be deprecated circa 2009, but were just set as undocumented
970
+ # so usage still exist in the wild.
971
+ #
972
+ # source://json//lib/json/common.rb#927
973
+ def unparse(*_arg0, **_arg1, &_arg2); end
974
+
975
+ # :call-seq:
976
+ # JSON.unsafe_load(source, proc = nil, options = {}) -> object
977
+ #
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"}>}
1103
+ #
1104
+ # source://json//lib/json/common.rb#666
1105
+ def unsafe_load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1106
+
1107
+ class << self
1108
+ # :call-seq:
1109
+ # JSON[object] -> new_array or new_string
1110
+ #
1111
+ # If +object+ is a \String,
1112
+ # calls JSON.parse with +object+ and +opts+ (see method #parse):
1113
+ # json = '[0, 1, null]'
1114
+ # JSON[json]# => [0, 1, nil]
1115
+ #
1116
+ # Otherwise, calls JSON.generate with +object+ and +opts+ (see method #generate):
1117
+ # ruby = [0, 1, nil]
1118
+ # JSON[ruby] # => '[0,1,null]'
1119
+ #
1120
+ # source://json//lib/json/common.rb#126
1121
+ def [](object, opts = T.unsafe(nil)); end
1122
+
1123
+ # Returns the current create identifier.
1124
+ # See also JSON.create_id=.
1125
+ #
1126
+ # source://json//lib/json/common.rb#219
1127
+ def create_id; end
1128
+
1129
+ # Sets create identifier, which is used to decide if the _json_create_
1130
+ # hook of a class should be called; initial value is +json_class+:
1131
+ # JSON.create_id # => 'json_class'
1132
+ #
1133
+ # source://json//lib/json/common.rb#213
1134
+ def create_id=(new_value); end
1135
+
1136
+ # Return the constant located at _path_. The format of _path_ has to be
1137
+ # either ::A::B::C or A::B::C. In any case, A has to be located at the top
1138
+ # level (absolute namespace path?). If there doesn't exist a constant at
1139
+ # the given path, an ArgumentError is raised.
1140
+ #
1141
+ # source://json//lib/json/common.rb#153
1142
+ def deep_const_get(path); end
1143
+
1144
+ # :call-seq:
1145
+ # JSON.dump(obj, io = nil, limit = nil)
1146
+ #
1147
+ # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
1148
+ #
1149
+ # The default options can be changed via method JSON.dump_default_options.
1150
+ #
1151
+ # - Argument +io+, if given, should respond to method +write+;
1152
+ # the \JSON \String is written to +io+, and +io+ is returned.
1153
+ # If +io+ is not given, the \JSON \String is returned.
1154
+ # - Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
1155
+ #
1156
+ # ---
1157
+ #
1158
+ # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
1159
+ # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
1160
+ # json = JSON.dump(obj)
1161
+ # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
1162
+ #
1163
+ # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
1164
+ # path = 't.json'
1165
+ # File.open(path, 'w') do |file|
1166
+ # JSON.dump(obj, file)
1167
+ # end # => #<File:t.json (closed)>
1168
+ # puts File.read(path)
1169
+ # Output:
1170
+ # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
1171
+ #
1172
+ # source://json//lib/json/common.rb#892
1173
+ def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
1174
+
1175
+ # :call-seq:
1176
+ # JSON.fast_generate(obj, opts) -> new_string
1177
+ #
1178
+ # Arguments +obj+ and +opts+ here are the same as
1179
+ # arguments +obj+ and +opts+ in JSON.generate.
1180
+ #
1181
+ # By default, generates \JSON data without checking
1182
+ # for circular references in +obj+ (option +max_nesting+ set to +false+, disabled).
1183
+ #
1184
+ # Raises an exception if +obj+ contains circular references:
1185
+ # a = []; b = []; a.push(b); b.push(a)
1186
+ # # Raises SystemStackError (stack level too deep):
1187
+ # JSON.fast_generate(a)
1188
+ #
1189
+ # source://json//lib/json/common.rb#445
1190
+ def fast_generate(obj, opts = T.unsafe(nil)); end
1191
+
1192
+ # source://json//lib/json/common.rb#937
1193
+ def fast_unparse(*_arg0, **_arg1, &_arg2); end
1194
+
1195
+ # :call-seq:
1196
+ # JSON.generate(obj, opts = nil) -> new_string
1197
+ #
1198
+ # Returns a \String containing the generated \JSON data.
1199
+ #
1200
+ # See also JSON.fast_generate, JSON.pretty_generate.
1201
+ #
1202
+ # Argument +obj+ is the Ruby object to be converted to \JSON.
1203
+ #
1204
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
1205
+ # See {Generating Options}[#module-JSON-label-Generating+Options].
1206
+ #
1207
+ # ---
1208
+ #
1209
+ # When +obj+ is an \Array, returns a \String containing a \JSON array:
1210
+ # obj = ["foo", 1.0, true, false, nil]
1211
+ # json = JSON.generate(obj)
1212
+ # json # => '["foo",1.0,true,false,null]'
1213
+ #
1214
+ # When +obj+ is a \Hash, returns a \String containing a \JSON object:
1215
+ # obj = {foo: 0, bar: 's', baz: :bat}
1216
+ # json = JSON.generate(obj)
1217
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
1218
+ #
1219
+ # For examples of generating from other Ruby objects, see
1220
+ # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
1221
+ #
1222
+ # ---
1223
+ #
1224
+ # Raises an exception if any formatting option is not a \String.
1225
+ #
1226
+ # Raises an exception if +obj+ contains circular references:
1227
+ # a = []; b = []; a.push(b); b.push(a)
1228
+ # # Raises JSON::NestingError (nesting of 100 is too deep):
1229
+ # JSON.generate(a)
1230
+ #
1231
+ # source://json//lib/json/common.rb#424
1232
+ def generate(obj, opts = T.unsafe(nil)); end
1233
+
1234
+ # Returns the JSON generator module that is used by JSON.
1235
+ #
1236
+ # source://json//lib/json/common.rb#181
1237
+ def generator; end
1238
+
1239
+ # Set the module _generator_ to be used by JSON.
1240
+ #
1241
+ # source://json//lib/json/common.rb#160
1242
+ def generator=(generator); end
1243
+
1244
+ # :call-seq:
1245
+ # JSON.load(source, proc = nil, options = {}) -> object
1246
+ #
1247
+ # Returns the Ruby objects created by parsing the given +source+.
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
+ #
1259
+ # - Argument +source+ must be, or be convertible to, a \String:
1260
+ # - If +source+ responds to instance method +to_str+,
1261
+ # <tt>source.to_str</tt> becomes the source.
1262
+ # - If +source+ responds to instance method +to_io+,
1263
+ # <tt>source.to_io.read</tt> becomes the source.
1264
+ # - If +source+ responds to instance method +read+,
1265
+ # <tt>source.read</tt> becomes the source.
1266
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
1267
+ # - Option +allow_blank+ specifies a truthy value.
1268
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
1269
+ # - Otherwise, +source+ remains the source.
1270
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
1271
+ # It will be called recursively with each result (depth-first order).
1272
+ # See details below.
1273
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
1274
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1275
+ # The default options can be changed via method JSON.load_default_options=.
1276
+ #
1277
+ # ---
1278
+ #
1279
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
1280
+ # <tt>parse(source, opts)</tt>; see #parse.
1281
+ #
1282
+ # Source for following examples:
1283
+ # source = <<~JSON
1284
+ # {
1285
+ # "name": "Dave",
1286
+ # "age" :40,
1287
+ # "hats": [
1288
+ # "Cattleman's",
1289
+ # "Panama",
1290
+ # "Tophat"
1291
+ # ]
1292
+ # }
1293
+ # JSON
1294
+ #
1295
+ # Load a \String:
1296
+ # ruby = JSON.load(source)
1297
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1298
+ #
1299
+ # Load an \IO object:
1300
+ # require 'stringio'
1301
+ # object = JSON.load(StringIO.new(source))
1302
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1303
+ #
1304
+ # Load a \File object:
1305
+ # path = 't.json'
1306
+ # File.write(path, source)
1307
+ # File.open(path) do |file|
1308
+ # JSON.load(file)
1309
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1310
+ #
1311
+ # ---
1312
+ #
1313
+ # When +proc+ is given:
1314
+ # - Modifies +source+ as above.
1315
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
1316
+ # - Recursively calls <tt>proc(result)</tt>.
1317
+ # - Returns the final result.
1318
+ #
1319
+ # Example:
1320
+ # require 'json'
1321
+ #
1322
+ # # Some classes for the example.
1323
+ # class Base
1324
+ # def initialize(attributes)
1325
+ # @attributes = attributes
1326
+ # end
1327
+ # end
1328
+ # class User < Base; end
1329
+ # class Account < Base; end
1330
+ # class Admin < Base; end
1331
+ # # The JSON source.
1332
+ # json = <<-EOF
1333
+ # {
1334
+ # "users": [
1335
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
1336
+ # {"type": "User", "username": "john", "email": "john@example.com"}
1337
+ # ],
1338
+ # "accounts": [
1339
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
1340
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
1341
+ # ],
1342
+ # "admins": {"type": "Admin", "password": "0wn3d"}
1343
+ # }
1344
+ # EOF
1345
+ # # Deserializer method.
1346
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
1347
+ # type = obj.is_a?(Hash) && obj["type"]
1348
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
1349
+ # end
1350
+ # # Call to JSON.load
1351
+ # ruby = JSON.load(json, proc {|obj|
1352
+ # case obj
1353
+ # when Hash
1354
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
1355
+ # when Array
1356
+ # obj.map! {|v| deserialize_obj v }
1357
+ # end
1358
+ # })
1359
+ # pp ruby
1360
+ # Output:
1361
+ # {"users"=>
1362
+ # [#<User:0x00000000064c4c98
1363
+ # @attributes=
1364
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
1365
+ # #<User:0x00000000064c4bd0
1366
+ # @attributes=
1367
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
1368
+ # "accounts"=>
1369
+ # [{"account"=>
1370
+ # #<Account:0x00000000064c4928
1371
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
1372
+ # {"account"=>
1373
+ # #<Account:0x00000000064c4680
1374
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
1375
+ # "admins"=>
1376
+ # #<Admin:0x00000000064c41f8
1377
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
1378
+ #
1379
+ # source://json//lib/json/common.rb#826
1380
+ def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1381
+
1382
+ # :call-seq:
1383
+ # JSON.load_file(path, opts={}) -> object
1384
+ #
1385
+ # Calls:
1386
+ # parse(File.read(path), opts)
1387
+ #
1388
+ # See method #parse.
1389
+ #
1390
+ # source://json//lib/json/common.rb#373
1391
+ def load_file(filespec, opts = T.unsafe(nil)); end
1392
+
1393
+ # :call-seq:
1394
+ # JSON.load_file!(path, opts = {})
1395
+ #
1396
+ # Calls:
1397
+ # JSON.parse!(File.read(path, opts))
1398
+ #
1399
+ # See method #parse!
1400
+ #
1401
+ # source://json//lib/json/common.rb#384
1402
+ def load_file!(filespec, opts = T.unsafe(nil)); end
1403
+
1404
+ # :call-seq:
1405
+ # JSON.parse(source, opts) -> object
1406
+ #
1407
+ # Returns the Ruby objects created by parsing the given +source+.
1408
+ #
1409
+ # Argument +source+ contains the \String to be parsed.
1410
+ #
1411
+ # Argument +opts+, if given, contains a \Hash of options for the parsing.
1412
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1413
+ #
1414
+ # ---
1415
+ #
1416
+ # When +source+ is a \JSON array, returns a Ruby \Array:
1417
+ # source = '["foo", 1.0, true, false, null]'
1418
+ # ruby = JSON.parse(source)
1419
+ # ruby # => ["foo", 1.0, true, false, nil]
1420
+ # ruby.class # => Array
1421
+ #
1422
+ # When +source+ is a \JSON object, returns a Ruby \Hash:
1423
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
1424
+ # ruby = JSON.parse(source)
1425
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
1426
+ # ruby.class # => Hash
1427
+ #
1428
+ # For examples of parsing for all \JSON data types, see
1429
+ # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
1430
+ #
1431
+ # Parses nested JSON objects:
1432
+ # source = <<~JSON
1433
+ # {
1434
+ # "name": "Dave",
1435
+ # "age" :40,
1436
+ # "hats": [
1437
+ # "Cattleman's",
1438
+ # "Panama",
1439
+ # "Tophat"
1440
+ # ]
1441
+ # }
1442
+ # JSON
1443
+ # ruby = JSON.parse(source)
1444
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1445
+ #
1446
+ # ---
1447
+ #
1448
+ # Raises an exception if +source+ is not valid JSON:
1449
+ # # Raises JSON::ParserError (783: unexpected token at ''):
1450
+ # JSON.parse('')
1451
+ #
1452
+ # source://json//lib/json/common.rb#336
1453
+ def parse(source, opts = T.unsafe(nil)); end
1454
+
1455
+ # :call-seq:
1456
+ # JSON.parse!(source, opts) -> object
1457
+ #
1458
+ # Calls
1459
+ # parse(source, opts)
1460
+ # with +source+ and possibly modified +opts+.
1461
+ #
1462
+ # Differences from JSON.parse:
1463
+ # - Option +max_nesting+, if not provided, defaults to +false+,
1464
+ # which disables checking for nesting depth.
1465
+ # - Option +allow_nan+, if not provided, defaults to +true+.
1466
+ #
1467
+ # source://json//lib/json/common.rb#358
1468
+ def parse!(source, opts = T.unsafe(nil)); end
1469
+
1470
+ # Returns the JSON parser class that is used by JSON.
1471
+ #
1472
+ # source://json//lib/json/common.rb#140
1473
+ def parser; end
1474
+
1475
+ # Set the JSON parser class _parser_ to be used by JSON.
1476
+ #
1477
+ # source://json//lib/json/common.rb#143
1478
+ def parser=(parser); end
1479
+
1480
+ # :call-seq:
1481
+ # JSON.pretty_generate(obj, opts = nil) -> new_string
1482
+ #
1483
+ # Arguments +obj+ and +opts+ here are the same as
1484
+ # arguments +obj+ and +opts+ in JSON.generate.
1485
+ #
1486
+ # Default options are:
1487
+ # {
1488
+ # indent: ' ', # Two spaces
1489
+ # space: ' ', # One space
1490
+ # array_nl: "\n", # Newline
1491
+ # object_nl: "\n" # Newline
1492
+ # }
1493
+ #
1494
+ # Example:
1495
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
1496
+ # json = JSON.pretty_generate(obj)
1497
+ # puts json
1498
+ # Output:
1499
+ # {
1500
+ # "foo": [
1501
+ # "bar",
1502
+ # "baz"
1503
+ # ],
1504
+ # "bat": {
1505
+ # "bam": 0,
1506
+ # "bad": 1
1507
+ # }
1508
+ # }
1509
+ #
1510
+ # source://json//lib/json/common.rb#492
1511
+ def pretty_generate(obj, opts = T.unsafe(nil)); end
1512
+
1513
+ # source://json//lib/json/common.rb#947
1514
+ def pretty_unparse(*_arg0, **_arg1, &_arg2); end
1515
+
1516
+ # source://json//lib/json/common.rb#957
1517
+ def restore(*_arg0, **_arg1, &_arg2); end
1518
+
1519
+ # Sets or Returns the JSON generator state class that is used by JSON.
1520
+ #
1521
+ # source://json//lib/json/common.rb#184
1522
+ def state; end
1523
+
1524
+ # Sets or Returns the JSON generator state class that is used by JSON.
1525
+ #
1526
+ # source://json//lib/json/common.rb#184
1527
+ def state=(_arg0); end
1528
+
1529
+ # :stopdoc:
1530
+ # All these were meant to be deprecated circa 2009, but were just set as undocumented
1531
+ # so usage still exist in the wild.
1532
+ #
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
1667
+
1668
+ private
1669
+
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
1675
+ end
1676
+ end
1677
+
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
1717
+
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
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
1915
+ class JSON::GenericObject < ::OpenStruct
1916
+ # source://json//lib/json/generic_object.rb#67
1917
+ def as_json(*_arg0); end
1918
+
1919
+ # source://json//lib/json/generic_object.rb#51
1920
+ def to_hash; end
1921
+
1922
+ # source://json//lib/json/generic_object.rb#71
1923
+ def to_json(*a); end
1924
+
1925
+ # source://json//lib/json/generic_object.rb#63
1926
+ def |(other); end
1927
+
1928
+ class << self
1929
+ # source://json//lib/json/generic_object.rb#45
1930
+ def dump(obj, *args); end
1931
+
1932
+ # source://json//lib/json/generic_object.rb#25
1933
+ def from_hash(object); end
1934
+
1935
+ # Sets the attribute json_creatable
1936
+ #
1937
+ # @param value the value to set the attribute json_creatable to.
1938
+ #
1939
+ # source://json//lib/json/generic_object.rb#17
1940
+ def json_creatable=(_arg0); end
1941
+
1942
+ # @return [Boolean]
1943
+ #
1944
+ # source://json//lib/json/generic_object.rb#13
1945
+ def json_creatable?; end
1946
+
1947
+ # source://json//lib/json/generic_object.rb#19
1948
+ def json_create(data); end
1949
+
1950
+ # source://json//lib/json/generic_object.rb#40
1951
+ def load(source, proc = T.unsafe(nil), opts = T.unsafe(nil)); end
1952
+ end
1953
+ end
1954
+
1955
+ # source://json//lib/json/common.rb#341
1956
+ JSON::PARSE_L_OPTIONS = T.let(T.unsafe(nil), Hash)
1957
+
1958
+ # source://json//lib/json/common.rb#454
1959
+ JSON::PRETTY_GENERATE_OPTIONS = T.let(T.unsafe(nil), Hash)
1960
+
1961
+ # source://json//lib/json/common.rb#146
1962
+ JSON::Parser = JSON::Ext::Parser
1963
+
1964
+ # This exception is raised if a parser error occurs.
1965
+ #
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
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
2007
+ module Kernel
2008
+ private
2009
+
2010
+ # If _object_ is string-like, parse the string and return the parsed result as
2011
+ # a Ruby data structure. Otherwise, generate a JSON text from the Ruby data
2012
+ # structure object and return it.
2013
+ #
2014
+ # The _opts_ argument is passed through to generate/parse respectively. See
2015
+ # generate and parse for their documentation.
2016
+ #
2017
+ # source://json//lib/json/common.rb#1101
2018
+ def JSON(object, opts = T.unsafe(nil)); end
2019
+
2020
+ # Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
2021
+ # one line.
2022
+ #
2023
+ # source://json//lib/json/common.rb#1067
2024
+ def j(*objs); end
2025
+
2026
+ # Outputs _objs_ to STDOUT as JSON strings in a pretty format, with
2027
+ # indentation and over many lines.
2028
+ #
2029
+ # source://json//lib/json/common.rb#1082
2030
+ def jj(*objs); end
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