active_cached_resource 0.0.1.pre → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/LICENSE +21 -0
  4. data/lib/active_cached_resource/caching.rb +104 -1
  5. data/lib/active_cached_resource/configuration.rb +22 -1
  6. data/lib/active_cached_resource/logger.rb +14 -0
  7. data/lib/active_cached_resource/model.rb +18 -0
  8. data/lib/active_cached_resource/version.rb +1 -8
  9. data/lib/activeresource/lib/active_resource/collection.rb +14 -1
  10. data/lib/activeresource/lib/active_resource/railtie.rb +2 -2
  11. data/lib/activeresource/lib/active_resource.rb +1 -1
  12. metadata +5 -401
  13. data/.rspec +0 -3
  14. data/.rubocop.yml +0 -22
  15. data/.standard.yml +0 -2
  16. data/Rakefile +0 -21
  17. data/example/consumer/.dockerignore +0 -41
  18. data/example/consumer/.gitattributes +0 -9
  19. data/example/consumer/.gitignore +0 -36
  20. data/example/consumer/.kamal/hooks/docker-setup.sample +0 -3
  21. data/example/consumer/.kamal/hooks/post-deploy.sample +0 -14
  22. data/example/consumer/.kamal/hooks/post-proxy-reboot.sample +0 -3
  23. data/example/consumer/.kamal/hooks/pre-build.sample +0 -51
  24. data/example/consumer/.kamal/hooks/pre-connect.sample +0 -47
  25. data/example/consumer/.kamal/hooks/pre-deploy.sample +0 -109
  26. data/example/consumer/.kamal/hooks/pre-proxy-reboot.sample +0 -3
  27. data/example/consumer/.kamal/secrets +0 -17
  28. data/example/consumer/Dockerfile +0 -65
  29. data/example/consumer/Gemfile +0 -17
  30. data/example/consumer/Rakefile +0 -6
  31. data/example/consumer/app/controllers/application_controller.rb +0 -2
  32. data/example/consumer/app/controllers/concerns/.keep +0 -0
  33. data/example/consumer/app/jobs/application_job.rb +0 -7
  34. data/example/consumer/app/mailers/application_mailer.rb +0 -4
  35. data/example/consumer/app/models/application_record.rb +0 -3
  36. data/example/consumer/app/models/concerns/.keep +0 -0
  37. data/example/consumer/app/models/person.rb +0 -9
  38. data/example/consumer/app/views/layouts/mailer.html.erb +0 -13
  39. data/example/consumer/app/views/layouts/mailer.text.erb +0 -1
  40. data/example/consumer/bin/brakeman +0 -7
  41. data/example/consumer/bin/bundle +0 -109
  42. data/example/consumer/bin/dev +0 -2
  43. data/example/consumer/bin/docker-entrypoint +0 -14
  44. data/example/consumer/bin/jobs +0 -6
  45. data/example/consumer/bin/kamal +0 -27
  46. data/example/consumer/bin/rails +0 -4
  47. data/example/consumer/bin/rake +0 -4
  48. data/example/consumer/bin/rubocop +0 -8
  49. data/example/consumer/bin/setup +0 -34
  50. data/example/consumer/bin/thrust +0 -5
  51. data/example/consumer/config/application.rb +0 -20
  52. data/example/consumer/config/boot.rb +0 -3
  53. data/example/consumer/config/cache.yml +0 -16
  54. data/example/consumer/config/credentials.yml.enc +0 -1
  55. data/example/consumer/config/database.yml +0 -14
  56. data/example/consumer/config/deploy.yml +0 -116
  57. data/example/consumer/config/environment.rb +0 -5
  58. data/example/consumer/config/environments/development.rb +0 -64
  59. data/example/consumer/config/environments/production.rb +0 -85
  60. data/example/consumer/config/environments/test.rb +0 -50
  61. data/example/consumer/config/initializers/cors.rb +0 -16
  62. data/example/consumer/config/initializers/filter_parameter_logging.rb +0 -8
  63. data/example/consumer/config/initializers/inflections.rb +0 -16
  64. data/example/consumer/config/locales/en.yml +0 -31
  65. data/example/consumer/config/puma.rb +0 -41
  66. data/example/consumer/config/queue.yml +0 -18
  67. data/example/consumer/config/recurring.yml +0 -10
  68. data/example/consumer/config/routes.rb +0 -10
  69. data/example/consumer/config.ru +0 -6
  70. data/example/consumer/db/cache_schema.rb +0 -14
  71. data/example/consumer/db/queue_schema.rb +0 -129
  72. data/example/consumer/db/seeds.rb +0 -0
  73. data/example/consumer/lib/tasks/.keep +0 -0
  74. data/example/consumer/log/.keep +0 -0
  75. data/example/consumer/public/robots.txt +0 -1
  76. data/example/consumer/script/.keep +0 -0
  77. data/example/consumer/storage/.keep +0 -0
  78. data/example/consumer/tmp/.keep +0 -0
  79. data/example/consumer/tmp/cache/.keep +0 -0
  80. data/example/consumer/tmp/pids/.keep +0 -0
  81. data/example/consumer/tmp/storage/.keep +0 -0
  82. data/example/consumer/vendor/.keep +0 -0
  83. data/example/provider/.dockerignore +0 -41
  84. data/example/provider/.gitattributes +0 -9
  85. data/example/provider/.gitignore +0 -32
  86. data/example/provider/.kamal/hooks/docker-setup.sample +0 -3
  87. data/example/provider/.kamal/hooks/post-deploy.sample +0 -14
  88. data/example/provider/.kamal/hooks/post-proxy-reboot.sample +0 -3
  89. data/example/provider/.kamal/hooks/pre-build.sample +0 -51
  90. data/example/provider/.kamal/hooks/pre-connect.sample +0 -47
  91. data/example/provider/.kamal/hooks/pre-deploy.sample +0 -109
  92. data/example/provider/.kamal/hooks/pre-proxy-reboot.sample +0 -3
  93. data/example/provider/.kamal/secrets +0 -17
  94. data/example/provider/Dockerfile +0 -65
  95. data/example/provider/Gemfile +0 -14
  96. data/example/provider/Rakefile +0 -6
  97. data/example/provider/app/controllers/application_controller.rb +0 -2
  98. data/example/provider/app/controllers/concerns/.keep +0 -0
  99. data/example/provider/app/controllers/people_controller.rb +0 -68
  100. data/example/provider/app/jobs/application_job.rb +0 -7
  101. data/example/provider/app/mailers/application_mailer.rb +0 -4
  102. data/example/provider/app/models/address.rb +0 -3
  103. data/example/provider/app/models/application_record.rb +0 -3
  104. data/example/provider/app/models/company.rb +0 -3
  105. data/example/provider/app/models/concerns/.keep +0 -0
  106. data/example/provider/app/models/person.rb +0 -6
  107. data/example/provider/app/views/layouts/mailer.html.erb +0 -13
  108. data/example/provider/app/views/layouts/mailer.text.erb +0 -1
  109. data/example/provider/bin/brakeman +0 -7
  110. data/example/provider/bin/bundle +0 -109
  111. data/example/provider/bin/dev +0 -2
  112. data/example/provider/bin/docker-entrypoint +0 -14
  113. data/example/provider/bin/jobs +0 -6
  114. data/example/provider/bin/kamal +0 -27
  115. data/example/provider/bin/rails +0 -4
  116. data/example/provider/bin/rake +0 -4
  117. data/example/provider/bin/rubocop +0 -8
  118. data/example/provider/bin/setup +0 -34
  119. data/example/provider/bin/thrust +0 -5
  120. data/example/provider/config/application.rb +0 -44
  121. data/example/provider/config/boot.rb +0 -3
  122. data/example/provider/config/cache.yml +0 -16
  123. data/example/provider/config/credentials.yml.enc +0 -1
  124. data/example/provider/config/database.yml +0 -20
  125. data/example/provider/config/deploy.yml +0 -116
  126. data/example/provider/config/environment.rb +0 -5
  127. data/example/provider/config/environments/development.rb +0 -64
  128. data/example/provider/config/environments/production.rb +0 -85
  129. data/example/provider/config/environments/test.rb +0 -50
  130. data/example/provider/config/initializers/cors.rb +0 -16
  131. data/example/provider/config/initializers/filter_parameter_logging.rb +0 -8
  132. data/example/provider/config/initializers/inflections.rb +0 -16
  133. data/example/provider/config/locales/en.yml +0 -31
  134. data/example/provider/config/puma.rb +0 -41
  135. data/example/provider/config/queue.yml +0 -18
  136. data/example/provider/config/recurring.yml +0 -10
  137. data/example/provider/config/routes.rb +0 -4
  138. data/example/provider/config.ru +0 -6
  139. data/example/provider/db/cache_schema.rb +0 -14
  140. data/example/provider/db/migrate/20241202183937_create_people.rb +0 -11
  141. data/example/provider/db/migrate/20241202183955_create_addresses.rb +0 -13
  142. data/example/provider/db/migrate/20241202184017_create_companies.rb +0 -14
  143. data/example/provider/db/queue_schema.rb +0 -129
  144. data/example/provider/db/schema.rb +0 -47
  145. data/example/provider/db/seeds.rb +0 -18
  146. data/example/provider/lib/tasks/.keep +0 -0
  147. data/example/provider/log/.keep +0 -0
  148. data/example/provider/public/robots.txt +0 -1
  149. data/example/provider/script/.keep +0 -0
  150. data/example/provider/storage/.keep +0 -0
  151. data/example/provider/tmp/.keep +0 -0
  152. data/example/provider/tmp/pids/.keep +0 -0
  153. data/example/provider/tmp/storage/.keep +0 -0
  154. data/example/provider/vendor/.keep +0 -0
  155. data/lib/activeresource/.gitignore +0 -15
  156. data/lib/activeresource/examples/performance.rb +0 -72
  157. data/lib/activeresource/test/abstract_unit.rb +0 -153
  158. data/lib/activeresource/test/cases/active_job_serializer_test.rb +0 -53
  159. data/lib/activeresource/test/cases/association_test.rb +0 -104
  160. data/lib/activeresource/test/cases/associations/builder/belongs_to_test.rb +0 -42
  161. data/lib/activeresource/test/cases/associations/builder/has_many_test.rb +0 -28
  162. data/lib/activeresource/test/cases/associations/builder/has_one_test.rb +0 -28
  163. data/lib/activeresource/test/cases/authorization_test.rb +0 -276
  164. data/lib/activeresource/test/cases/base/custom_methods_test.rb +0 -155
  165. data/lib/activeresource/test/cases/base/equality_test.rb +0 -53
  166. data/lib/activeresource/test/cases/base/load_test.rb +0 -249
  167. data/lib/activeresource/test/cases/base/schema_test.rb +0 -428
  168. data/lib/activeresource/test/cases/base_errors_test.rb +0 -129
  169. data/lib/activeresource/test/cases/base_test.rb +0 -1622
  170. data/lib/activeresource/test/cases/callbacks_test.rb +0 -155
  171. data/lib/activeresource/test/cases/collection_test.rb +0 -172
  172. data/lib/activeresource/test/cases/connection_test.rb +0 -357
  173. data/lib/activeresource/test/cases/finder_test.rb +0 -217
  174. data/lib/activeresource/test/cases/format_test.rb +0 -137
  175. data/lib/activeresource/test/cases/http_mock_test.rb +0 -213
  176. data/lib/activeresource/test/cases/inheritence_test.rb +0 -19
  177. data/lib/activeresource/test/cases/inheriting_hash_test.rb +0 -25
  178. data/lib/activeresource/test/cases/log_subscriber_test.rb +0 -63
  179. data/lib/activeresource/test/cases/reflection_test.rb +0 -65
  180. data/lib/activeresource/test/cases/validations_test.rb +0 -78
  181. data/lib/activeresource/test/fixtures/address.rb +0 -20
  182. data/lib/activeresource/test/fixtures/beast.rb +0 -16
  183. data/lib/activeresource/test/fixtures/comment.rb +0 -5
  184. data/lib/activeresource/test/fixtures/customer.rb +0 -5
  185. data/lib/activeresource/test/fixtures/inventory.rb +0 -14
  186. data/lib/activeresource/test/fixtures/person.rb +0 -15
  187. data/lib/activeresource/test/fixtures/pet.rb +0 -6
  188. data/lib/activeresource/test/fixtures/post.rb +0 -5
  189. data/lib/activeresource/test/fixtures/product.rb +0 -11
  190. data/lib/activeresource/test/fixtures/project.rb +0 -19
  191. data/lib/activeresource/test/fixtures/proxy.rb +0 -6
  192. data/lib/activeresource/test/fixtures/sound.rb +0 -11
  193. data/lib/activeresource/test/fixtures/street_address.rb +0 -6
  194. data/lib/activeresource/test/fixtures/subscription_plan.rb +0 -7
  195. data/lib/activeresource/test/fixtures/weather.rb +0 -21
  196. data/lib/activeresource/test/setter_trap.rb +0 -28
  197. data/lib/activeresource/test/singleton_test.rb +0 -138
  198. data/lib/activeresource/test/threadsafe_attributes_test.rb +0 -91
  199. data/sorbet/config +0 -4
  200. data/sorbet/rbi/annotations/.gitattributes +0 -1
  201. data/sorbet/rbi/annotations/activemodel.rbi +0 -89
  202. data/sorbet/rbi/annotations/activesupport.rbi +0 -457
  203. data/sorbet/rbi/annotations/minitest.rbi +0 -119
  204. data/sorbet/rbi/annotations/rainbow.rbi +0 -269
  205. data/sorbet/rbi/dsl/.gitattributes +0 -1
  206. data/sorbet/rbi/dsl/active_support/callbacks.rbi +0 -21
  207. data/sorbet/rbi/gems/.gitattributes +0 -1
  208. data/sorbet/rbi/gems/actioncable@8.0.0.rbi +0 -252
  209. data/sorbet/rbi/gems/actionmailbox@8.0.0.rbi +0 -9
  210. data/sorbet/rbi/gems/actionmailer@8.0.0.rbi +0 -9
  211. data/sorbet/rbi/gems/actionpack@8.0.0.rbi +0 -20909
  212. data/sorbet/rbi/gems/actiontext@8.0.0.rbi +0 -9
  213. data/sorbet/rbi/gems/actionview@8.0.0.rbi +0 -16207
  214. data/sorbet/rbi/gems/activejob@8.0.0.rbi +0 -9
  215. data/sorbet/rbi/gems/activemodel-serializers-xml@1.0.3.rbi +0 -166
  216. data/sorbet/rbi/gems/activemodel@8.0.0.rbi +0 -6857
  217. data/sorbet/rbi/gems/activerecord@8.0.0.rbi +0 -42896
  218. data/sorbet/rbi/gems/activeresource@6.1.4.rbi +0 -3944
  219. data/sorbet/rbi/gems/activestorage@8.0.0.rbi +0 -9
  220. data/sorbet/rbi/gems/activesupport@8.0.0.rbi +0 -21251
  221. data/sorbet/rbi/gems/ast@2.4.2.rbi +0 -585
  222. data/sorbet/rbi/gems/base64@0.2.0.rbi +0 -509
  223. data/sorbet/rbi/gems/benchmark@0.4.0.rbi +0 -618
  224. data/sorbet/rbi/gems/bigdecimal@3.1.8.rbi +0 -78
  225. data/sorbet/rbi/gems/builder@3.3.0.rbi +0 -9
  226. data/sorbet/rbi/gems/bump@0.10.0.rbi +0 -169
  227. data/sorbet/rbi/gems/byebug@11.1.3.rbi +0 -3607
  228. data/sorbet/rbi/gems/coderay@1.1.3.rbi +0 -3427
  229. data/sorbet/rbi/gems/concurrent-ruby@1.3.4.rbi +0 -11645
  230. data/sorbet/rbi/gems/connection_pool@2.4.1.rbi +0 -9
  231. data/sorbet/rbi/gems/crass@1.0.6.rbi +0 -623
  232. data/sorbet/rbi/gems/date@3.4.0.rbi +0 -75
  233. data/sorbet/rbi/gems/diff-lcs@1.5.1.rbi +0 -1131
  234. data/sorbet/rbi/gems/docile@1.4.1.rbi +0 -377
  235. data/sorbet/rbi/gems/drb@2.2.1.rbi +0 -1347
  236. data/sorbet/rbi/gems/erubi@1.13.0.rbi +0 -150
  237. data/sorbet/rbi/gems/globalid@1.2.1.rbi +0 -9
  238. data/sorbet/rbi/gems/i18n@1.14.6.rbi +0 -2359
  239. data/sorbet/rbi/gems/io-console@0.7.2.rbi +0 -9
  240. data/sorbet/rbi/gems/json@2.8.2.rbi +0 -1901
  241. data/sorbet/rbi/gems/language_server-protocol@3.17.0.3.rbi +0 -14238
  242. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +0 -240
  243. data/sorbet/rbi/gems/logger@1.6.1.rbi +0 -920
  244. data/sorbet/rbi/gems/loofah@2.23.1.rbi +0 -1081
  245. data/sorbet/rbi/gems/mail@2.8.1.rbi +0 -9
  246. data/sorbet/rbi/gems/marcel@1.0.4.rbi +0 -9
  247. data/sorbet/rbi/gems/method_source@1.1.0.rbi +0 -304
  248. data/sorbet/rbi/gems/mini_mime@1.1.5.rbi +0 -9
  249. data/sorbet/rbi/gems/minitest@5.25.2.rbi +0 -1547
  250. data/sorbet/rbi/gems/net-imap@0.5.1.rbi +0 -9
  251. data/sorbet/rbi/gems/net-pop@0.1.2.rbi +0 -9
  252. data/sorbet/rbi/gems/net-protocol@0.2.2.rbi +0 -292
  253. data/sorbet/rbi/gems/net-smtp@0.5.0.rbi +0 -9
  254. data/sorbet/rbi/gems/netrc@0.11.0.rbi +0 -159
  255. data/sorbet/rbi/gems/nio4r@2.7.4.rbi +0 -9
  256. data/sorbet/rbi/gems/nokogiri@1.16.7.rbi +0 -7311
  257. data/sorbet/rbi/gems/parallel@1.26.3.rbi +0 -291
  258. data/sorbet/rbi/gems/parser@3.3.6.0.rbi +0 -5519
  259. data/sorbet/rbi/gems/prism@1.2.0.rbi +0 -39085
  260. data/sorbet/rbi/gems/pry-byebug@3.10.1.rbi +0 -1151
  261. data/sorbet/rbi/gems/pry@0.14.2.rbi +0 -10076
  262. data/sorbet/rbi/gems/psych@5.2.0.rbi +0 -1785
  263. data/sorbet/rbi/gems/racc@1.8.1.rbi +0 -162
  264. data/sorbet/rbi/gems/rack-session@2.0.0.rbi +0 -727
  265. data/sorbet/rbi/gems/rack-test@2.1.0.rbi +0 -747
  266. data/sorbet/rbi/gems/rack@3.1.8.rbi +0 -4905
  267. data/sorbet/rbi/gems/rackup@2.2.1.rbi +0 -230
  268. data/sorbet/rbi/gems/rails-dom-testing@2.2.0.rbi +0 -758
  269. data/sorbet/rbi/gems/rails-html-sanitizer@1.6.0.rbi +0 -785
  270. data/sorbet/rbi/gems/rails@8.0.0.rbi +0 -9
  271. data/sorbet/rbi/gems/railties@8.0.0.rbi +0 -6287
  272. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +0 -403
  273. data/sorbet/rbi/gems/rake@13.2.1.rbi +0 -3091
  274. data/sorbet/rbi/gems/rbi@0.2.1.rbi +0 -4535
  275. data/sorbet/rbi/gems/rdoc@6.8.1.rbi +0 -12572
  276. data/sorbet/rbi/gems/regexp_parser@2.9.2.rbi +0 -3772
  277. data/sorbet/rbi/gems/reline@0.5.12.rbi +0 -2416
  278. data/sorbet/rbi/gems/rexml@3.3.9.rbi +0 -4858
  279. data/sorbet/rbi/gems/rspec-core@3.13.2.rbi +0 -11287
  280. data/sorbet/rbi/gems/rspec-expectations@3.13.3.rbi +0 -8183
  281. data/sorbet/rbi/gems/rspec-mocks@3.13.2.rbi +0 -5341
  282. data/sorbet/rbi/gems/rspec-support@3.13.1.rbi +0 -1630
  283. data/sorbet/rbi/gems/rspec@3.13.0.rbi +0 -83
  284. data/sorbet/rbi/gems/rubocop-ast@1.36.1.rbi +0 -7303
  285. data/sorbet/rbi/gems/rubocop-performance@1.21.1.rbi +0 -9
  286. data/sorbet/rbi/gems/rubocop@1.65.1.rbi +0 -58170
  287. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +0 -1318
  288. data/sorbet/rbi/gems/securerandom@0.3.2.rbi +0 -395
  289. data/sorbet/rbi/gems/simplecov-html@0.13.1.rbi +0 -225
  290. data/sorbet/rbi/gems/simplecov@0.22.0.rbi +0 -2149
  291. data/sorbet/rbi/gems/simplecov_json_formatter@0.1.4.rbi +0 -9
  292. data/sorbet/rbi/gems/spoom@1.5.0.rbi +0 -4932
  293. data/sorbet/rbi/gems/standard-custom@1.0.2.rbi +0 -9
  294. data/sorbet/rbi/gems/standard-performance@1.4.0.rbi +0 -9
  295. data/sorbet/rbi/gems/standard@1.40.0.rbi +0 -929
  296. data/sorbet/rbi/gems/stringio@3.1.2.rbi +0 -9
  297. data/sorbet/rbi/gems/tapioca@0.16.4.rbi +0 -3597
  298. data/sorbet/rbi/gems/thor@1.3.2.rbi +0 -4378
  299. data/sorbet/rbi/gems/timeout@0.4.2.rbi +0 -151
  300. data/sorbet/rbi/gems/tzinfo@2.0.6.rbi +0 -5918
  301. data/sorbet/rbi/gems/unicode-display_width@2.6.0.rbi +0 -66
  302. data/sorbet/rbi/gems/uri@1.0.2.rbi +0 -2377
  303. data/sorbet/rbi/gems/useragent@0.16.10.rbi +0 -9
  304. data/sorbet/rbi/gems/websocket-driver@0.7.6.rbi +0 -9
  305. data/sorbet/rbi/gems/websocket-extensions@0.1.5.rbi +0 -9
  306. data/sorbet/rbi/gems/yard-sorbet@0.9.0.rbi +0 -435
  307. data/sorbet/rbi/gems/yard@0.9.37.rbi +0 -18504
  308. data/sorbet/rbi/gems/zeitwerk@2.7.1.rbi +0 -9
  309. data/sorbet/tapioca/config.yml +0 -13
  310. data/sorbet/tapioca/require.rb +0 -12
@@ -1,1901 +0,0 @@
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
- # Extends any Class to include _json_creatable?_ method.
9
- #
10
- # source://json//lib/json/common.rb#868
11
- class Class < ::Module
12
- # Returns true if this class can be used to create an instance
13
- # from a serialised JSON string. The class has to implement a class
14
- # method _json_create_ that expects a hash as first parameter. The hash
15
- # should include the required data.
16
- #
17
- # @return [Boolean]
18
- #
19
- # source://json//lib/json/common.rb#873
20
- def json_creatable?; end
21
- end
22
-
23
- # = JavaScript \Object Notation (\JSON)
24
- #
25
- # \JSON is a lightweight data-interchange format.
26
- #
27
- # A \JSON value is one of the following:
28
- # - Double-quoted text: <tt>"foo"</tt>.
29
- # - Number: +1+, +1.0+, +2.0e2+.
30
- # - Boolean: +true+, +false+.
31
- # - Null: +null+.
32
- # - \Array: an ordered list of values, enclosed by square brackets:
33
- # ["foo", 1, 1.0, 2.0e2, true, false, null]
34
- #
35
- # - \Object: a collection of name/value pairs, enclosed by curly braces;
36
- # each name is double-quoted text;
37
- # the values may be any \JSON values:
38
- # {"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}
39
- #
40
- # A \JSON array or object may contain nested arrays, objects, and scalars
41
- # to any depth:
42
- # {"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}
43
- # [{"foo": 0, "bar": 1}, ["baz", 2]]
44
- #
45
- # == Using \Module \JSON
46
- #
47
- # To make module \JSON available in your code, begin with:
48
- # require 'json'
49
- #
50
- # All examples here assume that this has been done.
51
- #
52
- # === Parsing \JSON
53
- #
54
- # You can parse a \String containing \JSON data using
55
- # either of two methods:
56
- # - <tt>JSON.parse(source, opts)</tt>
57
- # - <tt>JSON.parse!(source, opts)</tt>
58
- #
59
- # where
60
- # - +source+ is a Ruby object.
61
- # - +opts+ is a \Hash object containing options
62
- # that control both input allowed and output formatting.
63
- #
64
- # The difference between the two methods
65
- # is that JSON.parse! omits some checks
66
- # and may not be safe for some +source+ data;
67
- # use it only for data from trusted sources.
68
- # Use the safer method JSON.parse for less trusted sources.
69
- #
70
- # ==== Parsing \JSON Arrays
71
- #
72
- # When +source+ is a \JSON array, JSON.parse by default returns a Ruby \Array:
73
- # json = '["foo", 1, 1.0, 2.0e2, true, false, null]'
74
- # ruby = JSON.parse(json)
75
- # ruby # => ["foo", 1, 1.0, 200.0, true, false, nil]
76
- # ruby.class # => Array
77
- #
78
- # The \JSON array may contain nested arrays, objects, and scalars
79
- # to any depth:
80
- # json = '[{"foo": 0, "bar": 1}, ["baz", 2]]'
81
- # JSON.parse(json) # => [{"foo"=>0, "bar"=>1}, ["baz", 2]]
82
- #
83
- # ==== Parsing \JSON \Objects
84
- #
85
- # When the source is a \JSON object, JSON.parse by default returns a Ruby \Hash:
86
- # json = '{"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}'
87
- # ruby = JSON.parse(json)
88
- # ruby # => {"a"=>"foo", "b"=>1, "c"=>1.0, "d"=>200.0, "e"=>true, "f"=>false, "g"=>nil}
89
- # ruby.class # => Hash
90
- #
91
- # The \JSON object may contain nested arrays, objects, and scalars
92
- # to any depth:
93
- # json = '{"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}'
94
- # JSON.parse(json) # => {"foo"=>{"bar"=>1, "baz"=>2}, "bat"=>[0, 1, 2]}
95
- #
96
- # ==== Parsing \JSON Scalars
97
- #
98
- # When the source is a \JSON scalar (not an array or object),
99
- # JSON.parse returns a Ruby scalar.
100
- #
101
- # \String:
102
- # ruby = JSON.parse('"foo"')
103
- # ruby # => 'foo'
104
- # ruby.class # => String
105
- # \Integer:
106
- # ruby = JSON.parse('1')
107
- # ruby # => 1
108
- # ruby.class # => Integer
109
- # \Float:
110
- # ruby = JSON.parse('1.0')
111
- # ruby # => 1.0
112
- # ruby.class # => Float
113
- # ruby = JSON.parse('2.0e2')
114
- # ruby # => 200
115
- # ruby.class # => Float
116
- # Boolean:
117
- # ruby = JSON.parse('true')
118
- # ruby # => true
119
- # ruby.class # => TrueClass
120
- # ruby = JSON.parse('false')
121
- # ruby # => false
122
- # ruby.class # => FalseClass
123
- # Null:
124
- # ruby = JSON.parse('null')
125
- # ruby # => nil
126
- # ruby.class # => NilClass
127
- #
128
- # ==== Parsing Options
129
- #
130
- # ====== Input Options
131
- #
132
- # Option +max_nesting+ (\Integer) specifies the maximum nesting depth allowed;
133
- # defaults to +100+; specify +false+ to disable depth checking.
134
- #
135
- # With the default, +false+:
136
- # source = '[0, [1, [2, [3]]]]'
137
- # ruby = JSON.parse(source)
138
- # ruby # => [0, [1, [2, [3]]]]
139
- # Too deep:
140
- # # Raises JSON::NestingError (nesting of 2 is too deep):
141
- # JSON.parse(source, {max_nesting: 1})
142
- # Bad value:
143
- # # Raises TypeError (wrong argument type Symbol (expected Fixnum)):
144
- # JSON.parse(source, {max_nesting: :foo})
145
- #
146
- # ---
147
- #
148
- # Option +allow_nan+ (boolean) specifies whether to allow
149
- # NaN, Infinity, and MinusInfinity in +source+;
150
- # defaults to +false+.
151
- #
152
- # With the default, +false+:
153
- # # Raises JSON::ParserError (225: unexpected token at '[NaN]'):
154
- # JSON.parse('[NaN]')
155
- # # Raises JSON::ParserError (232: unexpected token at '[Infinity]'):
156
- # JSON.parse('[Infinity]')
157
- # # Raises JSON::ParserError (248: unexpected token at '[-Infinity]'):
158
- # JSON.parse('[-Infinity]')
159
- # Allow:
160
- # source = '[NaN, Infinity, -Infinity]'
161
- # ruby = JSON.parse(source, {allow_nan: true})
162
- # ruby # => [NaN, Infinity, -Infinity]
163
- #
164
- # ====== Output Options
165
- #
166
- # Option +symbolize_names+ (boolean) specifies whether returned \Hash keys
167
- # should be Symbols;
168
- # defaults to +false+ (use Strings).
169
- #
170
- # With the default, +false+:
171
- # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
172
- # ruby = JSON.parse(source)
173
- # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
174
- # Use Symbols:
175
- # ruby = JSON.parse(source, {symbolize_names: true})
176
- # ruby # => {:a=>"foo", :b=>1.0, :c=>true, :d=>false, :e=>nil}
177
- #
178
- # ---
179
- #
180
- # Option +object_class+ (\Class) specifies the Ruby class to be used
181
- # for each \JSON object;
182
- # defaults to \Hash.
183
- #
184
- # With the default, \Hash:
185
- # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
186
- # ruby = JSON.parse(source)
187
- # ruby.class # => Hash
188
- # Use class \OpenStruct:
189
- # ruby = JSON.parse(source, {object_class: OpenStruct})
190
- # ruby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil>
191
- #
192
- # ---
193
- #
194
- # Option +array_class+ (\Class) specifies the Ruby class to be used
195
- # for each \JSON array;
196
- # defaults to \Array.
197
- #
198
- # With the default, \Array:
199
- # source = '["foo", 1.0, true, false, null]'
200
- # ruby = JSON.parse(source)
201
- # ruby.class # => Array
202
- # Use class \Set:
203
- # ruby = JSON.parse(source, {array_class: Set})
204
- # ruby # => #<Set: {"foo", 1.0, true, false, nil}>
205
- #
206
- # ---
207
- #
208
- # Option +create_additions+ (boolean) specifies whether to use \JSON additions in parsing.
209
- # See {\JSON Additions}[#module-JSON-label-JSON+Additions].
210
- #
211
- # === Generating \JSON
212
- #
213
- # To generate a Ruby \String containing \JSON data,
214
- # use method <tt>JSON.generate(source, opts)</tt>, where
215
- # - +source+ is a Ruby object.
216
- # - +opts+ is a \Hash object containing options
217
- # that control both input allowed and output formatting.
218
- #
219
- # ==== Generating \JSON from Arrays
220
- #
221
- # When the source is a Ruby \Array, JSON.generate returns
222
- # a \String containing a \JSON array:
223
- # ruby = [0, 's', :foo]
224
- # json = JSON.generate(ruby)
225
- # json # => '[0,"s","foo"]'
226
- #
227
- # The Ruby \Array array may contain nested arrays, hashes, and scalars
228
- # to any depth:
229
- # ruby = [0, [1, 2], {foo: 3, bar: 4}]
230
- # json = JSON.generate(ruby)
231
- # json # => '[0,[1,2],{"foo":3,"bar":4}]'
232
- #
233
- # ==== Generating \JSON from Hashes
234
- #
235
- # When the source is a Ruby \Hash, JSON.generate returns
236
- # a \String containing a \JSON object:
237
- # ruby = {foo: 0, bar: 's', baz: :bat}
238
- # json = JSON.generate(ruby)
239
- # json # => '{"foo":0,"bar":"s","baz":"bat"}'
240
- #
241
- # The Ruby \Hash array may contain nested arrays, hashes, and scalars
242
- # to any depth:
243
- # ruby = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
244
- # json = JSON.generate(ruby)
245
- # json # => '{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}'
246
- #
247
- # ==== Generating \JSON from Other Objects
248
- #
249
- # When the source is neither an \Array nor a \Hash,
250
- # the generated \JSON data depends on the class of the source.
251
- #
252
- # When the source is a Ruby \Integer or \Float, JSON.generate returns
253
- # a \String containing a \JSON number:
254
- # JSON.generate(42) # => '42'
255
- # JSON.generate(0.42) # => '0.42'
256
- #
257
- # When the source is a Ruby \String, JSON.generate returns
258
- # a \String containing a \JSON string (with double-quotes):
259
- # JSON.generate('A string') # => '"A string"'
260
- #
261
- # When the source is +true+, +false+ or +nil+, JSON.generate returns
262
- # a \String containing the corresponding \JSON token:
263
- # JSON.generate(true) # => 'true'
264
- # JSON.generate(false) # => 'false'
265
- # JSON.generate(nil) # => 'null'
266
- #
267
- # When the source is none of the above, JSON.generate returns
268
- # a \String containing a \JSON string representation of the source:
269
- # JSON.generate(:foo) # => '"foo"'
270
- # JSON.generate(Complex(0, 0)) # => '"0+0i"'
271
- # JSON.generate(Dir.new('.')) # => '"#<Dir>"'
272
- #
273
- # ==== Generating Options
274
- #
275
- # ====== Input Options
276
- #
277
- # Option +allow_nan+ (boolean) specifies whether
278
- # +NaN+, +Infinity+, and <tt>-Infinity</tt> may be generated;
279
- # defaults to +false+.
280
- #
281
- # With the default, +false+:
282
- # # Raises JSON::GeneratorError (920: NaN not allowed in JSON):
283
- # JSON.generate(JSON::NaN)
284
- # # Raises JSON::GeneratorError (917: Infinity not allowed in JSON):
285
- # JSON.generate(JSON::Infinity)
286
- # # Raises JSON::GeneratorError (917: -Infinity not allowed in JSON):
287
- # JSON.generate(JSON::MinusInfinity)
288
- #
289
- # Allow:
290
- # ruby = [Float::NaN, Float::Infinity, Float::MinusInfinity]
291
- # JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,-Infinity]'
292
- #
293
- # ---
294
- #
295
- # Option +max_nesting+ (\Integer) specifies the maximum nesting depth
296
- # in +obj+; defaults to +100+.
297
- #
298
- # With the default, +100+:
299
- # obj = [[[[[[0]]]]]]
300
- # JSON.generate(obj) # => '[[[[[[0]]]]]]'
301
- #
302
- # Too deep:
303
- # # Raises JSON::NestingError (nesting of 2 is too deep):
304
- # JSON.generate(obj, max_nesting: 2)
305
- #
306
- # ====== Escaping Options
307
- #
308
- # Options +script_safe+ (boolean) specifies wether <tt>'\u2028'</tt>, <tt>'\u2029'</tt>
309
- # and <tt>'/'</tt> should be escaped as to make the JSON object safe to interpolate in script
310
- # tags.
311
- #
312
- # Options +ascii_only+ (boolean) specifies wether all characters outside the ASCII range
313
- # should be escaped.
314
- #
315
- # ====== Output Options
316
- #
317
- # The default formatting options generate the most compact
318
- # \JSON data, all on one line and with no whitespace.
319
- #
320
- # You can use these formatting options to generate
321
- # \JSON data in a more open format, using whitespace.
322
- # See also JSON.pretty_generate.
323
- #
324
- # - Option +array_nl+ (\String) specifies a string (usually a newline)
325
- # to be inserted after each \JSON array; defaults to the empty \String, <tt>''</tt>.
326
- # - Option +object_nl+ (\String) specifies a string (usually a newline)
327
- # to be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>.
328
- # - Option +indent+ (\String) specifies the string (usually spaces) to be
329
- # used for indentation; defaults to the empty \String, <tt>''</tt>;
330
- # defaults to the empty \String, <tt>''</tt>;
331
- # has no effect unless options +array_nl+ or +object_nl+ specify newlines.
332
- # - Option +space+ (\String) specifies a string (usually a space) to be
333
- # inserted after the colon in each \JSON object's pair;
334
- # defaults to the empty \String, <tt>''</tt>.
335
- # - Option +space_before+ (\String) specifies a string (usually a space) to be
336
- # inserted before the colon in each \JSON object's pair;
337
- # defaults to the empty \String, <tt>''</tt>.
338
- #
339
- # In this example, +obj+ is used first to generate the shortest
340
- # \JSON data (no whitespace), then again with all formatting options
341
- # specified:
342
- #
343
- # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
344
- # json = JSON.generate(obj)
345
- # puts 'Compact:', json
346
- # opts = {
347
- # array_nl: "\n",
348
- # object_nl: "\n",
349
- # indent: ' ',
350
- # space_before: ' ',
351
- # space: ' '
352
- # }
353
- # puts 'Open:', JSON.generate(obj, opts)
354
- #
355
- # Output:
356
- # Compact:
357
- # {"foo":["bar","baz"],"bat":{"bam":0,"bad":1}}
358
- # Open:
359
- # {
360
- # "foo" : [
361
- # "bar",
362
- # "baz"
363
- # ],
364
- # "bat" : {
365
- # "bam" : 0,
366
- # "bad" : 1
367
- # }
368
- # }
369
- #
370
- # == \JSON Additions
371
- #
372
- # When you "round trip" a non-\String object from Ruby to \JSON and back,
373
- # you have a new \String, instead of the object you began with:
374
- # ruby0 = Range.new(0, 2)
375
- # json = JSON.generate(ruby0)
376
- # json # => '0..2"'
377
- # ruby1 = JSON.parse(json)
378
- # ruby1 # => '0..2'
379
- # ruby1.class # => String
380
- #
381
- # You can use \JSON _additions_ to preserve the original object.
382
- # The addition is an extension of a ruby class, so that:
383
- # - \JSON.generate stores more information in the \JSON string.
384
- # - \JSON.parse, called with option +create_additions+,
385
- # uses that information to create a proper Ruby object.
386
- #
387
- # This example shows a \Range being generated into \JSON
388
- # and parsed back into Ruby, both without and with
389
- # the addition for \Range:
390
- # ruby = Range.new(0, 2)
391
- # # This passage does not use the addition for Range.
392
- # json0 = JSON.generate(ruby)
393
- # ruby0 = JSON.parse(json0)
394
- # # This passage uses the addition for Range.
395
- # require 'json/add/range'
396
- # json1 = JSON.generate(ruby)
397
- # ruby1 = JSON.parse(json1, create_additions: true)
398
- # # Make a nice display.
399
- # display = <<~EOT
400
- # Generated JSON:
401
- # Without addition: #{json0} (#{json0.class})
402
- # With addition: #{json1} (#{json1.class})
403
- # Parsed JSON:
404
- # Without addition: #{ruby0.inspect} (#{ruby0.class})
405
- # With addition: #{ruby1.inspect} (#{ruby1.class})
406
- # EOT
407
- # puts display
408
- #
409
- # This output shows the different results:
410
- # Generated JSON:
411
- # Without addition: "0..2" (String)
412
- # With addition: {"json_class":"Range","a":[0,2,false]} (String)
413
- # Parsed JSON:
414
- # Without addition: "0..2" (String)
415
- # With addition: 0..2 (Range)
416
- #
417
- # The \JSON module includes additions for certain classes.
418
- # You can also craft custom additions.
419
- # See {Custom \JSON Additions}[#module-JSON-label-Custom+JSON+Additions].
420
- #
421
- # === Built-in Additions
422
- #
423
- # The \JSON module includes additions for certain classes.
424
- # To use an addition, +require+ its source:
425
- # - BigDecimal: <tt>require 'json/add/bigdecimal'</tt>
426
- # - Complex: <tt>require 'json/add/complex'</tt>
427
- # - Date: <tt>require 'json/add/date'</tt>
428
- # - DateTime: <tt>require 'json/add/date_time'</tt>
429
- # - Exception: <tt>require 'json/add/exception'</tt>
430
- # - OpenStruct: <tt>require 'json/add/ostruct'</tt>
431
- # - Range: <tt>require 'json/add/range'</tt>
432
- # - Rational: <tt>require 'json/add/rational'</tt>
433
- # - Regexp: <tt>require 'json/add/regexp'</tt>
434
- # - Set: <tt>require 'json/add/set'</tt>
435
- # - Struct: <tt>require 'json/add/struct'</tt>
436
- # - Symbol: <tt>require 'json/add/symbol'</tt>
437
- # - Time: <tt>require 'json/add/time'</tt>
438
- #
439
- # To reduce punctuation clutter, the examples below
440
- # show the generated \JSON via +puts+, rather than the usual +inspect+,
441
- #
442
- # \BigDecimal:
443
- # require 'json/add/bigdecimal'
444
- # ruby0 = BigDecimal(0) # 0.0
445
- # json = JSON.generate(ruby0) # {"json_class":"BigDecimal","b":"27:0.0"}
446
- # ruby1 = JSON.parse(json, create_additions: true) # 0.0
447
- # ruby1.class # => BigDecimal
448
- #
449
- # \Complex:
450
- # require 'json/add/complex'
451
- # ruby0 = Complex(1+0i) # 1+0i
452
- # json = JSON.generate(ruby0) # {"json_class":"Complex","r":1,"i":0}
453
- # ruby1 = JSON.parse(json, create_additions: true) # 1+0i
454
- # ruby1.class # Complex
455
- #
456
- # \Date:
457
- # require 'json/add/date'
458
- # ruby0 = Date.today # 2020-05-02
459
- # json = JSON.generate(ruby0) # {"json_class":"Date","y":2020,"m":5,"d":2,"sg":2299161.0}
460
- # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02
461
- # ruby1.class # Date
462
- #
463
- # \DateTime:
464
- # require 'json/add/date_time'
465
- # ruby0 = DateTime.now # 2020-05-02T10:38:13-05:00
466
- # 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}
467
- # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02T10:38:13-05:00
468
- # ruby1.class # DateTime
469
- #
470
- # \Exception (and its subclasses including \RuntimeError):
471
- # require 'json/add/exception'
472
- # ruby0 = Exception.new('A message') # A message
473
- # json = JSON.generate(ruby0) # {"json_class":"Exception","m":"A message","b":null}
474
- # ruby1 = JSON.parse(json, create_additions: true) # A message
475
- # ruby1.class # Exception
476
- # ruby0 = RuntimeError.new('Another message') # Another message
477
- # json = JSON.generate(ruby0) # {"json_class":"RuntimeError","m":"Another message","b":null}
478
- # ruby1 = JSON.parse(json, create_additions: true) # Another message
479
- # ruby1.class # RuntimeError
480
- #
481
- # \OpenStruct:
482
- # require 'json/add/ostruct'
483
- # ruby0 = OpenStruct.new(name: 'Matz', language: 'Ruby') # #<OpenStruct name="Matz", language="Ruby">
484
- # json = JSON.generate(ruby0) # {"json_class":"OpenStruct","t":{"name":"Matz","language":"Ruby"}}
485
- # ruby1 = JSON.parse(json, create_additions: true) # #<OpenStruct name="Matz", language="Ruby">
486
- # ruby1.class # OpenStruct
487
- #
488
- # \Range:
489
- # require 'json/add/range'
490
- # ruby0 = Range.new(0, 2) # 0..2
491
- # json = JSON.generate(ruby0) # {"json_class":"Range","a":[0,2,false]}
492
- # ruby1 = JSON.parse(json, create_additions: true) # 0..2
493
- # ruby1.class # Range
494
- #
495
- # \Rational:
496
- # require 'json/add/rational'
497
- # ruby0 = Rational(1, 3) # 1/3
498
- # json = JSON.generate(ruby0) # {"json_class":"Rational","n":1,"d":3}
499
- # ruby1 = JSON.parse(json, create_additions: true) # 1/3
500
- # ruby1.class # Rational
501
- #
502
- # \Regexp:
503
- # require 'json/add/regexp'
504
- # ruby0 = Regexp.new('foo') # (?-mix:foo)
505
- # json = JSON.generate(ruby0) # {"json_class":"Regexp","o":0,"s":"foo"}
506
- # ruby1 = JSON.parse(json, create_additions: true) # (?-mix:foo)
507
- # ruby1.class # Regexp
508
- #
509
- # \Set:
510
- # require 'json/add/set'
511
- # ruby0 = Set.new([0, 1, 2]) # #<Set: {0, 1, 2}>
512
- # json = JSON.generate(ruby0) # {"json_class":"Set","a":[0,1,2]}
513
- # ruby1 = JSON.parse(json, create_additions: true) # #<Set: {0, 1, 2}>
514
- # ruby1.class # Set
515
- #
516
- # \Struct:
517
- # require 'json/add/struct'
518
- # Customer = Struct.new(:name, :address) # Customer
519
- # ruby0 = Customer.new("Dave", "123 Main") # #<struct Customer name="Dave", address="123 Main">
520
- # json = JSON.generate(ruby0) # {"json_class":"Customer","v":["Dave","123 Main"]}
521
- # ruby1 = JSON.parse(json, create_additions: true) # #<struct Customer name="Dave", address="123 Main">
522
- # ruby1.class # Customer
523
- #
524
- # \Symbol:
525
- # require 'json/add/symbol'
526
- # ruby0 = :foo # foo
527
- # json = JSON.generate(ruby0) # {"json_class":"Symbol","s":"foo"}
528
- # ruby1 = JSON.parse(json, create_additions: true) # foo
529
- # ruby1.class # Symbol
530
- #
531
- # \Time:
532
- # require 'json/add/time'
533
- # ruby0 = Time.now # 2020-05-02 11:28:26 -0500
534
- # json = JSON.generate(ruby0) # {"json_class":"Time","s":1588436906,"n":840560000}
535
- # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02 11:28:26 -0500
536
- # ruby1.class # Time
537
- #
538
- #
539
- # === Custom \JSON Additions
540
- #
541
- # In addition to the \JSON additions provided,
542
- # you can craft \JSON additions of your own,
543
- # either for Ruby built-in classes or for user-defined classes.
544
- #
545
- # Here's a user-defined class +Foo+:
546
- # class Foo
547
- # attr_accessor :bar, :baz
548
- # def initialize(bar, baz)
549
- # self.bar = bar
550
- # self.baz = baz
551
- # end
552
- # end
553
- #
554
- # Here's the \JSON addition for it:
555
- # # Extend class Foo with JSON addition.
556
- # class Foo
557
- # # Serialize Foo object with its class name and arguments
558
- # def to_json(*args)
559
- # {
560
- # JSON.create_id => self.class.name,
561
- # 'a' => [ bar, baz ]
562
- # }.to_json(*args)
563
- # end
564
- # # Deserialize JSON string by constructing new Foo object with arguments.
565
- # def self.json_create(object)
566
- # new(*object['a'])
567
- # end
568
- # end
569
- #
570
- # Demonstration:
571
- # require 'json'
572
- # # This Foo object has no custom addition.
573
- # foo0 = Foo.new(0, 1)
574
- # json0 = JSON.generate(foo0)
575
- # obj0 = JSON.parse(json0)
576
- # # Lood the custom addition.
577
- # require_relative 'foo_addition'
578
- # # This foo has the custom addition.
579
- # foo1 = Foo.new(0, 1)
580
- # json1 = JSON.generate(foo1)
581
- # obj1 = JSON.parse(json1, create_additions: true)
582
- # # Make a nice display.
583
- # display = <<~EOT
584
- # Generated JSON:
585
- # Without custom addition: #{json0} (#{json0.class})
586
- # With custom addition: #{json1} (#{json1.class})
587
- # Parsed JSON:
588
- # Without custom addition: #{obj0.inspect} (#{obj0.class})
589
- # With custom addition: #{obj1.inspect} (#{obj1.class})
590
- # EOT
591
- # puts display
592
- #
593
- # Output:
594
- #
595
- # Generated JSON:
596
- # Without custom addition: "#<Foo:0x0000000006534e80>" (String)
597
- # With custom addition: {"json_class":"Foo","a":[0,1]} (String)
598
- # Parsed JSON:
599
- # Without custom addition: "#<Foo:0x0000000006534e80>" (String)
600
- # With custom addition: #<Foo:0x0000000006473bb8 @bar=0, @baz=1> (Foo)
601
- #
602
- # source://json//lib/json/version.rb#3
603
- module JSON
604
- private
605
-
606
- # :call-seq:
607
- # JSON.dump(obj, io = nil, limit = nil)
608
- #
609
- # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
610
- #
611
- # The default options can be changed via method JSON.dump_default_options.
612
- #
613
- # - Argument +io+, if given, should respond to method +write+;
614
- # the \JSON \String is written to +io+, and +io+ is returned.
615
- # If +io+ is not given, the \JSON \String is returned.
616
- # - Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
617
- #
618
- # ---
619
- #
620
- # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
621
- # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
622
- # json = JSON.dump(obj)
623
- # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
624
- #
625
- # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
626
- # path = 't.json'
627
- # File.open(path, 'w') do |file|
628
- # JSON.dump(obj, file)
629
- # end # => #<File:t.json (closed)>
630
- # puts File.read(path)
631
- # Output:
632
- # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
633
- #
634
- # source://json//lib/json/common.rb#772
635
- def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
636
-
637
- # :call-seq:
638
- # JSON.fast_generate(obj, opts) -> new_string
639
- #
640
- # Arguments +obj+ and +opts+ here are the same as
641
- # arguments +obj+ and +opts+ in JSON.generate.
642
- #
643
- # By default, generates \JSON data without checking
644
- # for circular references in +obj+ (option +max_nesting+ set to +false+, disabled).
645
- #
646
- # Raises an exception if +obj+ contains circular references:
647
- # a = []; b = []; a.push(b); b.push(a)
648
- # # Raises SystemStackError (stack level too deep):
649
- # JSON.fast_generate(a)
650
- #
651
- # source://json//lib/json/common.rb#313
652
- def fast_generate(obj, opts = T.unsafe(nil)); end
653
-
654
- # :stopdoc:
655
- # I want to deprecate these later, so I'll first be silent about them, and later delete them.
656
- #
657
- # source://json//lib/json/common.rb#313
658
- def fast_unparse(obj, opts = T.unsafe(nil)); end
659
-
660
- # :call-seq:
661
- # JSON.generate(obj, opts = nil) -> new_string
662
- #
663
- # Returns a \String containing the generated \JSON data.
664
- #
665
- # See also JSON.fast_generate, JSON.pretty_generate.
666
- #
667
- # Argument +obj+ is the Ruby object to be converted to \JSON.
668
- #
669
- # Argument +opts+, if given, contains a \Hash of options for the generation.
670
- # See {Generating Options}[#module-JSON-label-Generating+Options].
671
- #
672
- # ---
673
- #
674
- # When +obj+ is an \Array, returns a \String containing a \JSON array:
675
- # obj = ["foo", 1.0, true, false, nil]
676
- # json = JSON.generate(obj)
677
- # json # => '["foo",1.0,true,false,null]'
678
- #
679
- # When +obj+ is a \Hash, returns a \String containing a \JSON object:
680
- # obj = {foo: 0, bar: 's', baz: :bat}
681
- # json = JSON.generate(obj)
682
- # json # => '{"foo":0,"bar":"s","baz":"bat"}'
683
- #
684
- # For examples of generating from other Ruby objects, see
685
- # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
686
- #
687
- # ---
688
- #
689
- # Raises an exception if any formatting option is not a \String.
690
- #
691
- # Raises an exception if +obj+ contains circular references:
692
- # a = []; b = []; a.push(b); b.push(a)
693
- # # Raises JSON::NestingError (nesting of 100 is too deep):
694
- # JSON.generate(a)
695
- #
696
- # source://json//lib/json/common.rb#285
697
- def generate(obj, opts = T.unsafe(nil)); end
698
-
699
- # :call-seq:
700
- # JSON.load(source, proc = nil, options = {}) -> object
701
- #
702
- # Returns the Ruby objects created by parsing the given +source+.
703
- #
704
- # - Argument +source+ must be, or be convertible to, a \String:
705
- # - If +source+ responds to instance method +to_str+,
706
- # <tt>source.to_str</tt> becomes the source.
707
- # - If +source+ responds to instance method +to_io+,
708
- # <tt>source.to_io.read</tt> becomes the source.
709
- # - If +source+ responds to instance method +read+,
710
- # <tt>source.read</tt> becomes the source.
711
- # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
712
- # - Option +allow_blank+ specifies a truthy value.
713
- # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
714
- # - Otherwise, +source+ remains the source.
715
- # - Argument +proc+, if given, must be a \Proc that accepts one argument.
716
- # It will be called recursively with each result (depth-first order).
717
- # See details below.
718
- # BEWARE: This method is meant to serialise data from trusted user input,
719
- # like from your own database server or clients under your control, it could
720
- # be dangerous to allow untrusted users to pass JSON sources into it.
721
- # If you must use it, use JSON.unsafe_load instead to make it clear.
722
- # - Argument +opts+, if given, contains a \Hash of options for the parsing.
723
- # See {Parsing Options}[#module-JSON-label-Parsing+Options].
724
- # The default options can be changed via method JSON.load_default_options=.
725
- #
726
- # ---
727
- #
728
- # When no +proc+ is given, modifies +source+ as above and returns the result of
729
- # <tt>parse(source, opts)</tt>; see #parse.
730
- #
731
- # Source for following examples:
732
- # source = <<~JSON
733
- # {
734
- # "name": "Dave",
735
- # "age" :40,
736
- # "hats": [
737
- # "Cattleman's",
738
- # "Panama",
739
- # "Tophat"
740
- # ]
741
- # }
742
- # JSON
743
- #
744
- # Load a \String:
745
- # ruby = JSON.load(source)
746
- # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
747
- #
748
- # Load an \IO object:
749
- # require 'stringio'
750
- # object = JSON.load(StringIO.new(source))
751
- # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
752
- #
753
- # Load a \File object:
754
- # path = 't.json'
755
- # File.write(path, source)
756
- # File.open(path) do |file|
757
- # JSON.load(file)
758
- # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
759
- #
760
- # ---
761
- #
762
- # When +proc+ is given:
763
- # - Modifies +source+ as above.
764
- # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
765
- # - Recursively calls <tt>proc(result)</tt>.
766
- # - Returns the final result.
767
- #
768
- # Example:
769
- # require 'json'
770
- #
771
- # # Some classes for the example.
772
- # class Base
773
- # def initialize(attributes)
774
- # @attributes = attributes
775
- # end
776
- # end
777
- # class User < Base; end
778
- # class Account < Base; end
779
- # class Admin < Base; end
780
- # # The JSON source.
781
- # json = <<-EOF
782
- # {
783
- # "users": [
784
- # {"type": "User", "username": "jane", "email": "jane@example.com"},
785
- # {"type": "User", "username": "john", "email": "john@example.com"}
786
- # ],
787
- # "accounts": [
788
- # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
789
- # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
790
- # ],
791
- # "admins": {"type": "Admin", "password": "0wn3d"}
792
- # }
793
- # EOF
794
- # # Deserializer method.
795
- # def deserialize_obj(obj, safe_types = %w(User Account Admin))
796
- # type = obj.is_a?(Hash) && obj["type"]
797
- # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
798
- # end
799
- # # Call to JSON.load
800
- # ruby = JSON.load(json, proc {|obj|
801
- # case obj
802
- # when Hash
803
- # obj.each {|k, v| obj[k] = deserialize_obj v }
804
- # when Array
805
- # obj.map! {|v| deserialize_obj v }
806
- # end
807
- # })
808
- # pp ruby
809
- # Output:
810
- # {"users"=>
811
- # [#<User:0x00000000064c4c98
812
- # @attributes=
813
- # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
814
- # #<User:0x00000000064c4bd0
815
- # @attributes=
816
- # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
817
- # "accounts"=>
818
- # [{"account"=>
819
- # #<Account:0x00000000064c4928
820
- # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
821
- # {"account"=>
822
- # #<Account:0x00000000064c4680
823
- # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
824
- # "admins"=>
825
- # #<Admin:0x00000000064c41f8
826
- # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
827
- #
828
- # source://json//lib/json/common.rb#691
829
- def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
830
-
831
- # :call-seq:
832
- # JSON.load_file(path, opts={}) -> object
833
- #
834
- # Calls:
835
- # parse(File.read(path), opts)
836
- #
837
- # See method #parse.
838
- #
839
- # source://json//lib/json/common.rb#234
840
- def load_file(filespec, opts = T.unsafe(nil)); end
841
-
842
- # :call-seq:
843
- # JSON.load_file!(path, opts = {})
844
- #
845
- # Calls:
846
- # JSON.parse!(File.read(path, opts))
847
- #
848
- # See method #parse!
849
- #
850
- # source://json//lib/json/common.rb#245
851
- def load_file!(filespec, opts = T.unsafe(nil)); end
852
-
853
- # source://json//lib/json/common.rb#816
854
- def merge_dump_options(opts, strict: T.unsafe(nil)); end
855
-
856
- # :call-seq:
857
- # JSON.parse(source, opts) -> object
858
- #
859
- # Returns the Ruby objects created by parsing the given +source+.
860
- #
861
- # Argument +source+ contains the \String to be parsed.
862
- #
863
- # Argument +opts+, if given, contains a \Hash of options for the parsing.
864
- # See {Parsing Options}[#module-JSON-label-Parsing+Options].
865
- #
866
- # ---
867
- #
868
- # When +source+ is a \JSON array, returns a Ruby \Array:
869
- # source = '["foo", 1.0, true, false, null]'
870
- # ruby = JSON.parse(source)
871
- # ruby # => ["foo", 1.0, true, false, nil]
872
- # ruby.class # => Array
873
- #
874
- # When +source+ is a \JSON object, returns a Ruby \Hash:
875
- # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
876
- # ruby = JSON.parse(source)
877
- # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
878
- # ruby.class # => Hash
879
- #
880
- # For examples of parsing for all \JSON data types, see
881
- # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
882
- #
883
- # Parses nested JSON objects:
884
- # source = <<~JSON
885
- # {
886
- # "name": "Dave",
887
- # "age" :40,
888
- # "hats": [
889
- # "Cattleman's",
890
- # "Panama",
891
- # "Tophat"
892
- # ]
893
- # }
894
- # JSON
895
- # ruby = JSON.parse(source)
896
- # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
897
- #
898
- # ---
899
- #
900
- # Raises an exception if +source+ is not valid JSON:
901
- # # Raises JSON::ParserError (783: unexpected token at ''):
902
- # JSON.parse('')
903
- #
904
- # source://json//lib/json/common.rb#204
905
- def parse(source, opts = T.unsafe(nil)); end
906
-
907
- # :call-seq:
908
- # JSON.parse!(source, opts) -> object
909
- #
910
- # Calls
911
- # parse(source, opts)
912
- # with +source+ and possibly modified +opts+.
913
- #
914
- # Differences from JSON.parse:
915
- # - Option +max_nesting+, if not provided, defaults to +false+,
916
- # which disables checking for nesting depth.
917
- # - Option +allow_nan+, if not provided, defaults to +true+.
918
- #
919
- # source://json//lib/json/common.rb#219
920
- def parse!(source, opts = T.unsafe(nil)); end
921
-
922
- # :call-seq:
923
- # JSON.pretty_generate(obj, opts = nil) -> new_string
924
- #
925
- # Arguments +obj+ and +opts+ here are the same as
926
- # arguments +obj+ and +opts+ in JSON.generate.
927
- #
928
- # Default options are:
929
- # {
930
- # indent: ' ', # Two spaces
931
- # space: ' ', # One space
932
- # array_nl: "\n", # Newline
933
- # object_nl: "\n" # Newline
934
- # }
935
- #
936
- # Example:
937
- # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
938
- # json = JSON.pretty_generate(obj)
939
- # puts json
940
- # Output:
941
- # {
942
- # "foo": [
943
- # "bar",
944
- # "baz"
945
- # ],
946
- # "bat": {
947
- # "bam": 0,
948
- # "bad": 1
949
- # }
950
- # }
951
- #
952
- # source://json//lib/json/common.rb#358
953
- def pretty_generate(obj, opts = T.unsafe(nil)); end
954
-
955
- # :stopdoc:
956
- # I want to deprecate these later, so I'll first be silent about them, and later delete them.
957
- #
958
- # source://json//lib/json/common.rb#358
959
- def pretty_unparse(obj, opts = T.unsafe(nil)); end
960
-
961
- # Recursively calls passed _Proc_ if the parsed data structure is an _Array_ or _Hash_
962
- #
963
- # source://json//lib/json/common.rb#717
964
- def recurse_proc(result, &proc); end
965
-
966
- # source://json//lib/json/common.rb#691
967
- def restore(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
968
-
969
- # :stopdoc:
970
- # I want to deprecate these later, so I'll first be silent about them, and
971
- # later delete them.
972
- #
973
- # source://json//lib/json/common.rb#285
974
- def unparse(obj, opts = T.unsafe(nil)); end
975
-
976
- # :call-seq:
977
- # JSON.unsafe_load(source, proc = nil, options = {}) -> object
978
- #
979
- # Returns the Ruby objects created by parsing the given +source+.
980
- #
981
- # - Argument +source+ must be, or be convertible to, a \String:
982
- # - If +source+ responds to instance method +to_str+,
983
- # <tt>source.to_str</tt> becomes the source.
984
- # - If +source+ responds to instance method +to_io+,
985
- # <tt>source.to_io.read</tt> becomes the source.
986
- # - If +source+ responds to instance method +read+,
987
- # <tt>source.read</tt> becomes the source.
988
- # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
989
- # - Option +allow_blank+ specifies a truthy value.
990
- # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
991
- # - Otherwise, +source+ remains the source.
992
- # - Argument +proc+, if given, must be a \Proc that accepts one argument.
993
- # It will be called recursively with each result (depth-first order).
994
- # See details below.
995
- # BEWARE: This method is meant to serialise data from trusted user input,
996
- # like from your own database server or clients under your control, it could
997
- # be dangerous to allow untrusted users to pass JSON sources into it.
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#537
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#23
1121
- def [](object, opts = T.unsafe(nil)); end
1122
-
1123
- # source://json//lib/json/common.rb#80
1124
- def create_fast_state; end
1125
-
1126
- # Returns the current create identifier.
1127
- # See also JSON.create_id=.
1128
- #
1129
- # source://json//lib/json/common.rb#115
1130
- def create_id; end
1131
-
1132
- # Sets create identifier, which is used to decide if the _json_create_
1133
- # hook of a class should be called; initial value is +json_class+:
1134
- # JSON.create_id # => 'json_class'
1135
- #
1136
- # source://json//lib/json/common.rb#109
1137
- def create_id=(new_value); end
1138
-
1139
- # source://json//lib/json/common.rb#90
1140
- def create_pretty_state; end
1141
-
1142
- # Return the constant located at _path_. The format of _path_ has to be
1143
- # either ::A::B::C or A::B::C. In any case, A has to be located at the top
1144
- # level (absolute namespace path?). If there doesn't exist a constant at
1145
- # the given path, an ArgumentError is raised.
1146
- #
1147
- # source://json//lib/json/common.rb#50
1148
- def deep_const_get(path); end
1149
-
1150
- # :call-seq:
1151
- # JSON.dump(obj, io = nil, limit = nil)
1152
- #
1153
- # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
1154
- #
1155
- # The default options can be changed via method JSON.dump_default_options.
1156
- #
1157
- # - Argument +io+, if given, should respond to method +write+;
1158
- # the \JSON \String is written to +io+, and +io+ is returned.
1159
- # If +io+ is not given, the \JSON \String is returned.
1160
- # - Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
1161
- #
1162
- # ---
1163
- #
1164
- # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
1165
- # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
1166
- # json = JSON.dump(obj)
1167
- # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
1168
- #
1169
- # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
1170
- # path = 't.json'
1171
- # File.open(path, 'w') do |file|
1172
- # JSON.dump(obj, file)
1173
- # end # => #<File:t.json (closed)>
1174
- # puts File.read(path)
1175
- # Output:
1176
- # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
1177
- #
1178
- # source://json//lib/json/common.rb#772
1179
- def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
1180
-
1181
- # Sets or returns the default options for the JSON.dump method.
1182
- # Initially:
1183
- # opts = JSON.dump_default_options
1184
- # opts # => {:max_nesting=>false, :allow_nan=>true}
1185
- #
1186
- # source://json//lib/json/common.rb#738
1187
- def dump_default_options; end
1188
-
1189
- # Sets or returns the default options for the JSON.dump method.
1190
- # Initially:
1191
- # opts = JSON.dump_default_options
1192
- # opts # => {:max_nesting=>false, :allow_nan=>true}
1193
- #
1194
- # source://json//lib/json/common.rb#738
1195
- def dump_default_options=(_arg0); end
1196
-
1197
- # :call-seq:
1198
- # JSON.fast_generate(obj, opts) -> new_string
1199
- #
1200
- # Arguments +obj+ and +opts+ here are the same as
1201
- # arguments +obj+ and +opts+ in JSON.generate.
1202
- #
1203
- # By default, generates \JSON data without checking
1204
- # for circular references in +obj+ (option +max_nesting+ set to +false+, disabled).
1205
- #
1206
- # Raises an exception if +obj+ contains circular references:
1207
- # a = []; b = []; a.push(b); b.push(a)
1208
- # # Raises SystemStackError (stack level too deep):
1209
- # JSON.fast_generate(a)
1210
- #
1211
- # source://json//lib/json/common.rb#313
1212
- def fast_generate(obj, opts = T.unsafe(nil)); end
1213
-
1214
- # :stopdoc:
1215
- # I want to deprecate these later, so I'll first be silent about them, and later delete them.
1216
- #
1217
- # source://json//lib/json/common.rb#313
1218
- def fast_unparse(obj, opts = T.unsafe(nil)); end
1219
-
1220
- # :call-seq:
1221
- # JSON.generate(obj, opts = nil) -> new_string
1222
- #
1223
- # Returns a \String containing the generated \JSON data.
1224
- #
1225
- # See also JSON.fast_generate, JSON.pretty_generate.
1226
- #
1227
- # Argument +obj+ is the Ruby object to be converted to \JSON.
1228
- #
1229
- # Argument +opts+, if given, contains a \Hash of options for the generation.
1230
- # See {Generating Options}[#module-JSON-label-Generating+Options].
1231
- #
1232
- # ---
1233
- #
1234
- # When +obj+ is an \Array, returns a \String containing a \JSON array:
1235
- # obj = ["foo", 1.0, true, false, nil]
1236
- # json = JSON.generate(obj)
1237
- # json # => '["foo",1.0,true,false,null]'
1238
- #
1239
- # When +obj+ is a \Hash, returns a \String containing a \JSON object:
1240
- # obj = {foo: 0, bar: 's', baz: :bat}
1241
- # json = JSON.generate(obj)
1242
- # json # => '{"foo":0,"bar":"s","baz":"bat"}'
1243
- #
1244
- # For examples of generating from other Ruby objects, see
1245
- # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
1246
- #
1247
- # ---
1248
- #
1249
- # Raises an exception if any formatting option is not a \String.
1250
- #
1251
- # Raises an exception if +obj+ contains circular references:
1252
- # a = []; b = []; a.push(b); b.push(a)
1253
- # # Raises JSON::NestingError (nesting of 100 is too deep):
1254
- # JSON.generate(a)
1255
- #
1256
- # source://json//lib/json/common.rb#285
1257
- def generate(obj, opts = T.unsafe(nil)); end
1258
-
1259
- # Returns the JSON generator module that is used by JSON.
1260
- #
1261
- # source://json//lib/json/common.rb#100
1262
- def generator; end
1263
-
1264
- # Set the module _generator_ to be used by JSON.
1265
- #
1266
- # source://json//lib/json/common.rb#57
1267
- def generator=(generator); end
1268
-
1269
- # Encodes string using String.encode.
1270
- #
1271
- # source://json//lib/json/common.rb#812
1272
- def iconv(to, from, string); end
1273
-
1274
- # :call-seq:
1275
- # JSON.load(source, proc = nil, options = {}) -> object
1276
- #
1277
- # Returns the Ruby objects created by parsing the given +source+.
1278
- #
1279
- # - Argument +source+ must be, or be convertible to, a \String:
1280
- # - If +source+ responds to instance method +to_str+,
1281
- # <tt>source.to_str</tt> becomes the source.
1282
- # - If +source+ responds to instance method +to_io+,
1283
- # <tt>source.to_io.read</tt> becomes the source.
1284
- # - If +source+ responds to instance method +read+,
1285
- # <tt>source.read</tt> becomes the source.
1286
- # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
1287
- # - Option +allow_blank+ specifies a truthy value.
1288
- # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
1289
- # - Otherwise, +source+ remains the source.
1290
- # - Argument +proc+, if given, must be a \Proc that accepts one argument.
1291
- # It will be called recursively with each result (depth-first order).
1292
- # See details below.
1293
- # BEWARE: This method is meant to serialise data from trusted user input,
1294
- # like from your own database server or clients under your control, it could
1295
- # be dangerous to allow untrusted users to pass JSON sources into it.
1296
- # If you must use it, use JSON.unsafe_load instead to make it clear.
1297
- # - Argument +opts+, if given, contains a \Hash of options for the parsing.
1298
- # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1299
- # The default options can be changed via method JSON.load_default_options=.
1300
- #
1301
- # ---
1302
- #
1303
- # When no +proc+ is given, modifies +source+ as above and returns the result of
1304
- # <tt>parse(source, opts)</tt>; see #parse.
1305
- #
1306
- # Source for following examples:
1307
- # source = <<~JSON
1308
- # {
1309
- # "name": "Dave",
1310
- # "age" :40,
1311
- # "hats": [
1312
- # "Cattleman's",
1313
- # "Panama",
1314
- # "Tophat"
1315
- # ]
1316
- # }
1317
- # JSON
1318
- #
1319
- # Load a \String:
1320
- # ruby = JSON.load(source)
1321
- # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1322
- #
1323
- # Load an \IO object:
1324
- # require 'stringio'
1325
- # object = JSON.load(StringIO.new(source))
1326
- # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1327
- #
1328
- # Load a \File object:
1329
- # path = 't.json'
1330
- # File.write(path, source)
1331
- # File.open(path) do |file|
1332
- # JSON.load(file)
1333
- # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1334
- #
1335
- # ---
1336
- #
1337
- # When +proc+ is given:
1338
- # - Modifies +source+ as above.
1339
- # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
1340
- # - Recursively calls <tt>proc(result)</tt>.
1341
- # - Returns the final result.
1342
- #
1343
- # Example:
1344
- # require 'json'
1345
- #
1346
- # # Some classes for the example.
1347
- # class Base
1348
- # def initialize(attributes)
1349
- # @attributes = attributes
1350
- # end
1351
- # end
1352
- # class User < Base; end
1353
- # class Account < Base; end
1354
- # class Admin < Base; end
1355
- # # The JSON source.
1356
- # json = <<-EOF
1357
- # {
1358
- # "users": [
1359
- # {"type": "User", "username": "jane", "email": "jane@example.com"},
1360
- # {"type": "User", "username": "john", "email": "john@example.com"}
1361
- # ],
1362
- # "accounts": [
1363
- # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
1364
- # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
1365
- # ],
1366
- # "admins": {"type": "Admin", "password": "0wn3d"}
1367
- # }
1368
- # EOF
1369
- # # Deserializer method.
1370
- # def deserialize_obj(obj, safe_types = %w(User Account Admin))
1371
- # type = obj.is_a?(Hash) && obj["type"]
1372
- # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
1373
- # end
1374
- # # Call to JSON.load
1375
- # ruby = JSON.load(json, proc {|obj|
1376
- # case obj
1377
- # when Hash
1378
- # obj.each {|k, v| obj[k] = deserialize_obj v }
1379
- # when Array
1380
- # obj.map! {|v| deserialize_obj v }
1381
- # end
1382
- # })
1383
- # pp ruby
1384
- # Output:
1385
- # {"users"=>
1386
- # [#<User:0x00000000064c4c98
1387
- # @attributes=
1388
- # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
1389
- # #<User:0x00000000064c4bd0
1390
- # @attributes=
1391
- # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
1392
- # "accounts"=>
1393
- # [{"account"=>
1394
- # #<Account:0x00000000064c4928
1395
- # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
1396
- # {"account"=>
1397
- # #<Account:0x00000000064c4680
1398
- # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
1399
- # "admins"=>
1400
- # #<Admin:0x00000000064c41f8
1401
- # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
1402
- #
1403
- # source://json//lib/json/common.rb#691
1404
- def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1405
-
1406
- # Sets or returns default options for the JSON.load method.
1407
- # Initially:
1408
- # opts = JSON.load_default_options
1409
- # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
1410
- #
1411
- # source://json//lib/json/common.rb#402
1412
- def load_default_options; end
1413
-
1414
- # Sets or returns default options for the JSON.load method.
1415
- # Initially:
1416
- # opts = JSON.load_default_options
1417
- # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
1418
- #
1419
- # source://json//lib/json/common.rb#402
1420
- def load_default_options=(_arg0); end
1421
-
1422
- # :call-seq:
1423
- # JSON.load_file(path, opts={}) -> object
1424
- #
1425
- # Calls:
1426
- # parse(File.read(path), opts)
1427
- #
1428
- # See method #parse.
1429
- #
1430
- # source://json//lib/json/common.rb#234
1431
- def load_file(filespec, opts = T.unsafe(nil)); end
1432
-
1433
- # :call-seq:
1434
- # JSON.load_file!(path, opts = {})
1435
- #
1436
- # Calls:
1437
- # JSON.parse!(File.read(path, opts))
1438
- #
1439
- # See method #parse!
1440
- #
1441
- # source://json//lib/json/common.rb#245
1442
- def load_file!(filespec, opts = T.unsafe(nil)); end
1443
-
1444
- # :call-seq:
1445
- # JSON.parse(source, opts) -> object
1446
- #
1447
- # Returns the Ruby objects created by parsing the given +source+.
1448
- #
1449
- # Argument +source+ contains the \String to be parsed.
1450
- #
1451
- # Argument +opts+, if given, contains a \Hash of options for the parsing.
1452
- # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1453
- #
1454
- # ---
1455
- #
1456
- # When +source+ is a \JSON array, returns a Ruby \Array:
1457
- # source = '["foo", 1.0, true, false, null]'
1458
- # ruby = JSON.parse(source)
1459
- # ruby # => ["foo", 1.0, true, false, nil]
1460
- # ruby.class # => Array
1461
- #
1462
- # When +source+ is a \JSON object, returns a Ruby \Hash:
1463
- # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
1464
- # ruby = JSON.parse(source)
1465
- # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
1466
- # ruby.class # => Hash
1467
- #
1468
- # For examples of parsing for all \JSON data types, see
1469
- # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
1470
- #
1471
- # Parses nested JSON objects:
1472
- # source = <<~JSON
1473
- # {
1474
- # "name": "Dave",
1475
- # "age" :40,
1476
- # "hats": [
1477
- # "Cattleman's",
1478
- # "Panama",
1479
- # "Tophat"
1480
- # ]
1481
- # }
1482
- # JSON
1483
- # ruby = JSON.parse(source)
1484
- # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1485
- #
1486
- # ---
1487
- #
1488
- # Raises an exception if +source+ is not valid JSON:
1489
- # # Raises JSON::ParserError (783: unexpected token at ''):
1490
- # JSON.parse('')
1491
- #
1492
- # source://json//lib/json/common.rb#204
1493
- def parse(source, opts = T.unsafe(nil)); end
1494
-
1495
- # :call-seq:
1496
- # JSON.parse!(source, opts) -> object
1497
- #
1498
- # Calls
1499
- # parse(source, opts)
1500
- # with +source+ and possibly modified +opts+.
1501
- #
1502
- # Differences from JSON.parse:
1503
- # - Option +max_nesting+, if not provided, defaults to +false+,
1504
- # which disables checking for nesting depth.
1505
- # - Option +allow_nan+, if not provided, defaults to +true+.
1506
- #
1507
- # source://json//lib/json/common.rb#219
1508
- def parse!(source, opts = T.unsafe(nil)); end
1509
-
1510
- # Returns the JSON parser class that is used by JSON.
1511
- #
1512
- # source://json//lib/json/common.rb#37
1513
- def parser; end
1514
-
1515
- # Set the JSON parser class _parser_ to be used by JSON.
1516
- #
1517
- # source://json//lib/json/common.rb#40
1518
- def parser=(parser); end
1519
-
1520
- # :call-seq:
1521
- # JSON.pretty_generate(obj, opts = nil) -> new_string
1522
- #
1523
- # Arguments +obj+ and +opts+ here are the same as
1524
- # arguments +obj+ and +opts+ in JSON.generate.
1525
- #
1526
- # Default options are:
1527
- # {
1528
- # indent: ' ', # Two spaces
1529
- # space: ' ', # One space
1530
- # array_nl: "\n", # Newline
1531
- # object_nl: "\n" # Newline
1532
- # }
1533
- #
1534
- # Example:
1535
- # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
1536
- # json = JSON.pretty_generate(obj)
1537
- # puts json
1538
- # Output:
1539
- # {
1540
- # "foo": [
1541
- # "bar",
1542
- # "baz"
1543
- # ],
1544
- # "bat": {
1545
- # "bam": 0,
1546
- # "bad": 1
1547
- # }
1548
- # }
1549
- #
1550
- # source://json//lib/json/common.rb#358
1551
- def pretty_generate(obj, opts = T.unsafe(nil)); end
1552
-
1553
- # :stopdoc:
1554
- # I want to deprecate these later, so I'll first be silent about them, and later delete them.
1555
- #
1556
- # source://json//lib/json/common.rb#358
1557
- def pretty_unparse(obj, opts = T.unsafe(nil)); end
1558
-
1559
- # Recursively calls passed _Proc_ if the parsed data structure is an _Array_ or _Hash_
1560
- #
1561
- # source://json//lib/json/common.rb#717
1562
- def recurse_proc(result, &proc); end
1563
-
1564
- # source://json//lib/json/common.rb#691
1565
- def restore(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1566
-
1567
- # Sets or Returns the JSON generator state class that is used by JSON.
1568
- #
1569
- # source://json//lib/json/common.rb#103
1570
- def state; end
1571
-
1572
- # Sets or Returns the JSON generator state class that is used by JSON.
1573
- #
1574
- # source://json//lib/json/common.rb#103
1575
- def state=(_arg0); end
1576
-
1577
- # :stopdoc:
1578
- # I want to deprecate these later, so I'll first be silent about them, and
1579
- # later delete them.
1580
- #
1581
- # source://json//lib/json/common.rb#285
1582
- def unparse(obj, opts = T.unsafe(nil)); end
1583
-
1584
- # :call-seq:
1585
- # JSON.unsafe_load(source, proc = nil, options = {}) -> object
1586
- #
1587
- # Returns the Ruby objects created by parsing the given +source+.
1588
- #
1589
- # - Argument +source+ must be, or be convertible to, a \String:
1590
- # - If +source+ responds to instance method +to_str+,
1591
- # <tt>source.to_str</tt> becomes the source.
1592
- # - If +source+ responds to instance method +to_io+,
1593
- # <tt>source.to_io.read</tt> becomes the source.
1594
- # - If +source+ responds to instance method +read+,
1595
- # <tt>source.read</tt> becomes the source.
1596
- # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
1597
- # - Option +allow_blank+ specifies a truthy value.
1598
- # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
1599
- # - Otherwise, +source+ remains the source.
1600
- # - Argument +proc+, if given, must be a \Proc that accepts one argument.
1601
- # It will be called recursively with each result (depth-first order).
1602
- # See details below.
1603
- # BEWARE: This method is meant to serialise data from trusted user input,
1604
- # like from your own database server or clients under your control, it could
1605
- # be dangerous to allow untrusted users to pass JSON sources into it.
1606
- # - Argument +opts+, if given, contains a \Hash of options for the parsing.
1607
- # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1608
- # The default options can be changed via method JSON.unsafe_load_default_options=.
1609
- #
1610
- # ---
1611
- #
1612
- # When no +proc+ is given, modifies +source+ as above and returns the result of
1613
- # <tt>parse(source, opts)</tt>; see #parse.
1614
- #
1615
- # Source for following examples:
1616
- # source = <<~JSON
1617
- # {
1618
- # "name": "Dave",
1619
- # "age" :40,
1620
- # "hats": [
1621
- # "Cattleman's",
1622
- # "Panama",
1623
- # "Tophat"
1624
- # ]
1625
- # }
1626
- # JSON
1627
- #
1628
- # Load a \String:
1629
- # ruby = JSON.unsafe_load(source)
1630
- # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1631
- #
1632
- # Load an \IO object:
1633
- # require 'stringio'
1634
- # object = JSON.unsafe_load(StringIO.new(source))
1635
- # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1636
- #
1637
- # Load a \File object:
1638
- # path = 't.json'
1639
- # File.write(path, source)
1640
- # File.open(path) do |file|
1641
- # JSON.unsafe_load(file)
1642
- # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1643
- #
1644
- # ---
1645
- #
1646
- # When +proc+ is given:
1647
- # - Modifies +source+ as above.
1648
- # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
1649
- # - Recursively calls <tt>proc(result)</tt>.
1650
- # - Returns the final result.
1651
- #
1652
- # Example:
1653
- # require 'json'
1654
- #
1655
- # # Some classes for the example.
1656
- # class Base
1657
- # def initialize(attributes)
1658
- # @attributes = attributes
1659
- # end
1660
- # end
1661
- # class User < Base; end
1662
- # class Account < Base; end
1663
- # class Admin < Base; end
1664
- # # The JSON source.
1665
- # json = <<-EOF
1666
- # {
1667
- # "users": [
1668
- # {"type": "User", "username": "jane", "email": "jane@example.com"},
1669
- # {"type": "User", "username": "john", "email": "john@example.com"}
1670
- # ],
1671
- # "accounts": [
1672
- # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
1673
- # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
1674
- # ],
1675
- # "admins": {"type": "Admin", "password": "0wn3d"}
1676
- # }
1677
- # EOF
1678
- # # Deserializer method.
1679
- # def deserialize_obj(obj, safe_types = %w(User Account Admin))
1680
- # type = obj.is_a?(Hash) && obj["type"]
1681
- # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
1682
- # end
1683
- # # Call to JSON.unsafe_load
1684
- # ruby = JSON.unsafe_load(json, proc {|obj|
1685
- # case obj
1686
- # when Hash
1687
- # obj.each {|k, v| obj[k] = deserialize_obj v }
1688
- # when Array
1689
- # obj.map! {|v| deserialize_obj v }
1690
- # end
1691
- # })
1692
- # pp ruby
1693
- # Output:
1694
- # {"users"=>
1695
- # [#<User:0x00000000064c4c98
1696
- # @attributes=
1697
- # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
1698
- # #<User:0x00000000064c4bd0
1699
- # @attributes=
1700
- # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
1701
- # "accounts"=>
1702
- # [{"account"=>
1703
- # #<Account:0x00000000064c4928
1704
- # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
1705
- # {"account"=>
1706
- # #<Account:0x00000000064c4680
1707
- # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
1708
- # "admins"=>
1709
- # #<Admin:0x00000000064c41f8
1710
- # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
1711
- #
1712
- # source://json//lib/json/common.rb#537
1713
- def unsafe_load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1714
-
1715
- # Sets or returns default options for the JSON.unsafe_load method.
1716
- # Initially:
1717
- # opts = JSON.load_default_options
1718
- # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
1719
- #
1720
- # source://json//lib/json/common.rb#388
1721
- def unsafe_load_default_options; end
1722
-
1723
- # Sets or returns default options for the JSON.unsafe_load method.
1724
- # Initially:
1725
- # opts = JSON.load_default_options
1726
- # opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
1727
- #
1728
- # source://json//lib/json/common.rb#388
1729
- def unsafe_load_default_options=(_arg0); end
1730
-
1731
- private
1732
-
1733
- # source://json//lib/json/common.rb#816
1734
- def merge_dump_options(opts, strict: T.unsafe(nil)); end
1735
- end
1736
- end
1737
-
1738
- # source://json//lib/json/ext/generator/state.rb#6
1739
- class JSON::Ext::Generator::State
1740
- # call-seq: new(opts = {})
1741
- #
1742
- # Instantiates a new State object, configured by _opts_.
1743
- #
1744
- # _opts_ can have the following keys:
1745
- #
1746
- # * *indent*: a string used to indent levels (default: ''),
1747
- # * *space*: a string that is put after, a : or , delimiter (default: ''),
1748
- # * *space_before*: a string that is put before a : pair delimiter (default: ''),
1749
- # * *object_nl*: a string that is put at the end of a JSON object (default: ''),
1750
- # * *array_nl*: a string that is put at the end of a JSON array (default: ''),
1751
- # * *allow_nan*: true if NaN, Infinity, and -Infinity should be
1752
- # generated, otherwise an exception is thrown, if these values are
1753
- # encountered. This options defaults to false.
1754
- # * *ascii_only*: true if only ASCII characters should be generated. This
1755
- # option defaults to false.
1756
- # * *buffer_initial_length*: sets the initial length of the generator's
1757
- # internal buffer.
1758
- #
1759
- # @return [State] a new instance of State
1760
- #
1761
- # source://json//lib/json/ext/generator/state.rb#25
1762
- def initialize(opts = T.unsafe(nil)); end
1763
-
1764
- # call-seq: [](name)
1765
- #
1766
- # Returns the value returned by method +name+.
1767
- #
1768
- # source://json//lib/json/ext/generator/state.rb#83
1769
- def [](name); end
1770
-
1771
- # call-seq: []=(name, value)
1772
- #
1773
- # Sets the attribute name to value.
1774
- #
1775
- # source://json//lib/json/ext/generator/state.rb#95
1776
- def []=(name, value); end
1777
-
1778
- # call-seq: configure(opts)
1779
- #
1780
- # Configure this State instance with the Hash _opts_, and return
1781
- # itself.
1782
- #
1783
- # source://json//lib/json/ext/generator/state.rb#35
1784
- def configure(opts); end
1785
-
1786
- # call-seq: configure(opts)
1787
- #
1788
- # Configure this State instance with the Hash _opts_, and return
1789
- # itself.
1790
- #
1791
- # source://json//lib/json/ext/generator/state.rb#35
1792
- def merge(opts); end
1793
-
1794
- # call-seq: to_h
1795
- #
1796
- # Returns the configuration instance variables as a hash, that can be
1797
- # passed to the configure method.
1798
- #
1799
- # source://json//lib/json/ext/generator/state.rb#54
1800
- def to_h; end
1801
-
1802
- # call-seq: to_h
1803
- #
1804
- # Returns the configuration instance variables as a hash, that can be
1805
- # passed to the configure method.
1806
- #
1807
- # source://json//lib/json/ext/generator/state.rb#54
1808
- def to_hash; end
1809
- end
1810
-
1811
- # source://json//lib/json/generic_object.rb#9
1812
- class JSON::GenericObject < ::OpenStruct
1813
- # source://json//lib/json/generic_object.rb#67
1814
- def as_json(*_arg0); end
1815
-
1816
- # source://json//lib/json/generic_object.rb#51
1817
- def to_hash; end
1818
-
1819
- # source://json//lib/json/generic_object.rb#71
1820
- def to_json(*a); end
1821
-
1822
- # source://json//lib/json/generic_object.rb#63
1823
- def |(other); end
1824
-
1825
- class << self
1826
- # source://json//lib/json/generic_object.rb#45
1827
- def dump(obj, *args); end
1828
-
1829
- # source://json//lib/json/generic_object.rb#25
1830
- def from_hash(object); end
1831
-
1832
- # Sets the attribute json_creatable
1833
- #
1834
- # @param value the value to set the attribute json_creatable to.
1835
- #
1836
- # source://json//lib/json/generic_object.rb#17
1837
- def json_creatable=(_arg0); end
1838
-
1839
- # @return [Boolean]
1840
- #
1841
- # source://json//lib/json/generic_object.rb#13
1842
- def json_creatable?; end
1843
-
1844
- # source://json//lib/json/generic_object.rb#19
1845
- def json_create(data); end
1846
-
1847
- # source://json//lib/json/generic_object.rb#40
1848
- def load(source, proc = T.unsafe(nil), opts = T.unsafe(nil)); end
1849
- end
1850
- end
1851
-
1852
- # The base exception for JSON errors.
1853
- #
1854
- # source://json//lib/json/common.rb#126
1855
- class JSON::JSONError < ::StandardError
1856
- class << self
1857
- # source://json//lib/json/common.rb#127
1858
- def wrap(exception); end
1859
- end
1860
- end
1861
-
1862
- # source://json//lib/json/common.rb#8
1863
- JSON::NOT_SET = T.let(T.unsafe(nil), Object)
1864
-
1865
- # source://json//lib/json/common.rb#43
1866
- JSON::Parser = JSON::Ext::Parser
1867
-
1868
- # source://json//lib/json/common.rb#72
1869
- JSON::State = JSON::Ext::Generator::State
1870
-
1871
- # For backwards compatibility
1872
- #
1873
- # source://json//lib/json/common.rb#148
1874
- JSON::UnparserError = JSON::GeneratorError
1875
-
1876
- # source://json//lib/json/common.rb#826
1877
- module Kernel
1878
- private
1879
-
1880
- # If _object_ is string-like, parse the string and return the parsed result as
1881
- # a Ruby data structure. Otherwise, generate a JSON text from the Ruby data
1882
- # structure object and return it.
1883
- #
1884
- # The _opts_ argument is passed through to generate/parse respectively. See
1885
- # generate and parse for their documentation.
1886
- #
1887
- # source://json//lib/json/common.rb#853
1888
- def JSON(object, *args); end
1889
-
1890
- # Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
1891
- # one line.
1892
- #
1893
- # source://json//lib/json/common.rb#831
1894
- def j(*objs); end
1895
-
1896
- # Outputs _objs_ to STDOUT as JSON strings in a pretty format, with
1897
- # indentation and over many lines.
1898
- #
1899
- # source://json//lib/json/common.rb#840
1900
- def jj(*objs); end
1901
- end