es_cli 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 (485) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/config +2 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +39 -0
  5. data/Rakefile +12 -0
  6. data/exe/es +8 -0
  7. data/lib/es_cli/cli.rb +247 -0
  8. data/lib/es_cli/version.rb +5 -0
  9. data/lib/es_cli.rb +11 -0
  10. data/readme.org +78 -0
  11. data/sig/es_cli.rbs +4 -0
  12. data/vendor/bundle/ruby/3.1.0/bin/rake +29 -0
  13. data/vendor/bundle/ruby/3.1.0/bin/thor +29 -0
  14. data/vendor/bundle/ruby/3.1.0/cache/event_stream_parser-1.0.0.gem +0 -0
  15. data/vendor/bundle/ruby/3.1.0/cache/faraday-2.12.2.gem +0 -0
  16. data/vendor/bundle/ruby/3.1.0/cache/faraday-multipart-1.1.0.gem +0 -0
  17. data/vendor/bundle/ruby/3.1.0/cache/faraday-net_http-3.4.0.gem +0 -0
  18. data/vendor/bundle/ruby/3.1.0/cache/json-2.9.1.gem +0 -0
  19. data/vendor/bundle/ruby/3.1.0/cache/logger-1.6.5.gem +0 -0
  20. data/vendor/bundle/ruby/3.1.0/cache/multipart-post-2.4.1.gem +0 -0
  21. data/vendor/bundle/ruby/3.1.0/cache/net-http-0.6.0.gem +0 -0
  22. data/vendor/bundle/ruby/3.1.0/cache/power_assert-2.0.5.gem +0 -0
  23. data/vendor/bundle/ruby/3.1.0/cache/rake-13.2.1.gem +0 -0
  24. data/vendor/bundle/ruby/3.1.0/cache/ruby-openai-7.3.1.gem +0 -0
  25. data/vendor/bundle/ruby/3.1.0/cache/test-unit-3.6.7.gem +0 -0
  26. data/vendor/bundle/ruby/3.1.0/cache/thor-1.3.2.gem +0 -0
  27. data/vendor/bundle/ruby/3.1.0/cache/uri-1.0.2.gem +0 -0
  28. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/gem.build_complete +0 -0
  29. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/gem_make.out +22 -0
  30. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/json/ext/generator.bundle +0 -0
  31. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/json/ext/parser.bundle +0 -0
  32. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/mkmf.log +208 -0
  33. data/vendor/bundle/ruby/3.1.0/gems/event_stream_parser-1.0.0/LICENSE.md +21 -0
  34. data/vendor/bundle/ruby/3.1.0/gems/event_stream_parser-1.0.0/README.md +99 -0
  35. data/vendor/bundle/ruby/3.1.0/gems/event_stream_parser-1.0.0/lib/event_stream_parser/version.rb +5 -0
  36. data/vendor/bundle/ruby/3.1.0/gems/event_stream_parser-1.0.0/lib/event_stream_parser.rb +222 -0
  37. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/CHANGELOG.md +574 -0
  38. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/LICENSE.md +20 -0
  39. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/README.md +67 -0
  40. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/Rakefile +12 -0
  41. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/examples/client_spec.rb +119 -0
  42. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/examples/client_test.rb +144 -0
  43. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/adapter/test.rb +311 -0
  44. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/adapter.rb +101 -0
  45. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/adapter_registry.rb +30 -0
  46. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/connection.rb +564 -0
  47. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/encoders/flat_params_encoder.rb +105 -0
  48. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/encoders/nested_params_encoder.rb +183 -0
  49. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/error.rb +165 -0
  50. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/logging/formatter.rb +118 -0
  51. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/methods.rb +6 -0
  52. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/middleware.rb +72 -0
  53. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/middleware_registry.rb +83 -0
  54. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/connection_options.rb +23 -0
  55. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/env.rb +204 -0
  56. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/proxy_options.rb +36 -0
  57. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/request_options.rb +23 -0
  58. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/ssl_options.rb +73 -0
  59. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options.rb +219 -0
  60. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/parameters.rb +5 -0
  61. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/rack_builder.rb +251 -0
  62. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request/authorization.rb +54 -0
  63. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request/instrumentation.rb +58 -0
  64. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request/json.rb +70 -0
  65. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request/url_encoded.rb +60 -0
  66. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request.rb +139 -0
  67. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/response/json.rb +74 -0
  68. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/response/logger.rb +37 -0
  69. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/response/raise_error.rb +83 -0
  70. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/response.rb +91 -0
  71. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/utils/headers.rb +150 -0
  72. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/utils/params_hash.rb +61 -0
  73. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/utils.rb +121 -0
  74. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/version.rb +5 -0
  75. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday.rb +157 -0
  76. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/external_adapters/faraday_specs_setup.rb +14 -0
  77. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/adapter/test_spec.rb +442 -0
  78. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/adapter_registry_spec.rb +28 -0
  79. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/adapter_spec.rb +55 -0
  80. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/connection_spec.rb +808 -0
  81. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/error_spec.rb +93 -0
  82. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/middleware_registry_spec.rb +31 -0
  83. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/middleware_spec.rb +213 -0
  84. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/options/env_spec.rb +76 -0
  85. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/options/options_spec.rb +297 -0
  86. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/options/proxy_options_spec.rb +52 -0
  87. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/options/request_options_spec.rb +19 -0
  88. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/params_encoders/flat_spec.rb +42 -0
  89. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/params_encoders/nested_spec.rb +151 -0
  90. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/rack_builder_spec.rb +317 -0
  91. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request/authorization_spec.rb +118 -0
  92. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request/instrumentation_spec.rb +74 -0
  93. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request/json_spec.rb +199 -0
  94. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request/url_encoded_spec.rb +93 -0
  95. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request_spec.rb +110 -0
  96. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/response/json_spec.rb +206 -0
  97. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/response/logger_spec.rb +278 -0
  98. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/response/raise_error_spec.rb +275 -0
  99. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/response_spec.rb +77 -0
  100. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/utils/headers_spec.rb +109 -0
  101. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/utils_spec.rb +119 -0
  102. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday_spec.rb +43 -0
  103. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/spec_helper.rb +133 -0
  104. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/disabling_stub.rb +14 -0
  105. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/fake_safe_buffer.rb +15 -0
  106. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/faraday_middleware_subclasses.rb +18 -0
  107. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/helper_methods.rb +96 -0
  108. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/shared_examples/adapter.rb +105 -0
  109. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/shared_examples/params_encoder.rb +18 -0
  110. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/shared_examples/request_method.rb +263 -0
  111. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/streaming_response_checker.rb +35 -0
  112. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/CHANGELOG.md +54 -0
  113. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/LICENSE.md +21 -0
  114. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/README.md +170 -0
  115. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart/file_part.rb +130 -0
  116. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart/middleware.rb +134 -0
  117. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart/param_part.rb +55 -0
  118. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart/version.rb +16 -0
  119. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart.rb +26 -0
  120. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/LICENSE.md +21 -0
  121. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/README.md +57 -0
  122. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/lib/faraday/adapter/net_http.rb +206 -0
  123. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/lib/faraday/net_http/version.rb +7 -0
  124. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/lib/faraday/net_http.rb +10 -0
  125. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/BSDL +22 -0
  126. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/CHANGES.md +572 -0
  127. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/COPYING +56 -0
  128. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/LEGAL +60 -0
  129. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/README.md +195 -0
  130. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/fbuffer/fbuffer.h +214 -0
  131. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/.sitearchdir.-.json.-.ext.time +0 -0
  132. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/Makefile +269 -0
  133. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/extconf.rb +10 -0
  134. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/generator.bundle +0 -0
  135. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/generator.c +1691 -0
  136. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/generator.o +0 -0
  137. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/.sitearchdir.-.json.-.ext.time +0 -0
  138. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/Makefile +269 -0
  139. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/extconf.rb +12 -0
  140. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/parser.bundle +0 -0
  141. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/parser.c +3238 -0
  142. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/parser.o +0 -0
  143. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/parser.rl +1465 -0
  144. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/json.gemspec +64 -0
  145. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/bigdecimal.rb +58 -0
  146. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/complex.rb +51 -0
  147. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/core.rb +12 -0
  148. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/date.rb +54 -0
  149. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/date_time.rb +67 -0
  150. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/exception.rb +49 -0
  151. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/ostruct.rb +54 -0
  152. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/range.rb +54 -0
  153. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/rational.rb +49 -0
  154. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/regexp.rb +48 -0
  155. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/set.rb +48 -0
  156. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/struct.rb +52 -0
  157. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/symbol.rb +47 -0
  158. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/time.rb +52 -0
  159. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/common.rb +896 -0
  160. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/ext/generator/state.rb +116 -0
  161. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/ext/generator.bundle +0 -0
  162. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/ext/parser.bundle +0 -0
  163. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/ext.rb +23 -0
  164. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/generic_object.rb +75 -0
  165. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/truffle_ruby/generator.rb +629 -0
  166. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/version.rb +5 -0
  167. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json.rb +587 -0
  168. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/.github/dependabot.yml +6 -0
  169. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/.github/workflows/push_gem.yml +46 -0
  170. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/.github/workflows/test.yml +32 -0
  171. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/.gitignore +11 -0
  172. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/BSDL +22 -0
  173. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/COPYING +56 -0
  174. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/Gemfile +10 -0
  175. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/README.md +104 -0
  176. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/Rakefile +30 -0
  177. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/bin/console +14 -0
  178. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/bin/setup +8 -0
  179. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/errors.rb +9 -0
  180. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/formatter.rb +36 -0
  181. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/log_device.rb +241 -0
  182. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/period.rb +47 -0
  183. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/severity.rb +38 -0
  184. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/version.rb +5 -0
  185. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger.rb +761 -0
  186. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/logger.gemspec +28 -0
  187. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/changelog.md +14 -0
  188. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/composite_io.rb +17 -0
  189. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/composite_read_io.rb +91 -0
  190. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/multipartable.rb +70 -0
  191. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/parts.rb +148 -0
  192. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/upload_io.rb +64 -0
  193. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/version.rb +11 -0
  194. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post.rb +8 -0
  195. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart_post.rb +11 -0
  196. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipartable.rb +19 -0
  197. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/net/http/post/multipart.rb +28 -0
  198. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/parts.rb +25 -0
  199. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/license.md +58 -0
  200. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/readme.md +170 -0
  201. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/BSDL +22 -0
  202. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/COPYING +56 -0
  203. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/Gemfile +8 -0
  204. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/README.md +93 -0
  205. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/Rakefile +10 -0
  206. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/bin/console +14 -0
  207. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/bin/setup +8 -0
  208. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/doc/net-http/examples.rdoc +31 -0
  209. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/doc/net-http/included_getters.rdoc +3 -0
  210. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/exceptions.rb +34 -0
  211. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/generic_request.rb +414 -0
  212. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/header.rb +981 -0
  213. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/proxy_delta.rb +17 -0
  214. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/request.rb +88 -0
  215. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/requests.rb +430 -0
  216. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/response.rb +738 -0
  217. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/responses.rb +1174 -0
  218. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/status.rb +84 -0
  219. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http.rb +2580 -0
  220. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/https.rb +23 -0
  221. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/net-http.gemspec +39 -0
  222. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/.github/dependabot.yml +6 -0
  223. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/.github/workflows/ci.yml +46 -0
  224. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/.gitignore +9 -0
  225. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/BSDL +22 -0
  226. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/COPYING +57 -0
  227. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/Gemfile +19 -0
  228. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/LEGAL +4 -0
  229. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/README.md +98 -0
  230. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/Rakefile +59 -0
  231. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/colorize.rb +7 -0
  232. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/configuration.rb +46 -0
  233. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/context.rb +233 -0
  234. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/enable_tracepoint_events.rb +62 -0
  235. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/inspector.rb +66 -0
  236. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/parser.rb +251 -0
  237. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/version.rb +3 -0
  238. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert.rb +93 -0
  239. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/power_assert.gemspec +24 -0
  240. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/History.rdoc +2403 -0
  241. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/MIT-LICENSE +21 -0
  242. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/README.rdoc +155 -0
  243. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/command_line_usage.rdoc +158 -0
  244. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/Rakefile1 +38 -0
  245. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/Rakefile2 +35 -0
  246. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/a.c +6 -0
  247. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/b.c +6 -0
  248. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/main.c +11 -0
  249. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/glossary.rdoc +42 -0
  250. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/jamis.rb +592 -0
  251. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/proto_rake.rdoc +127 -0
  252. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/rake.1 +156 -0
  253. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/rakefile.rdoc +622 -0
  254. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/rational.rdoc +151 -0
  255. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/exe/rake +27 -0
  256. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/application.rb +861 -0
  257. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/backtrace.rb +25 -0
  258. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/clean.rb +78 -0
  259. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/cloneable.rb +17 -0
  260. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/cpu_counter.rb +107 -0
  261. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/default_loader.rb +15 -0
  262. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/dsl_definition.rb +196 -0
  263. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/early_time.rb +22 -0
  264. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/ext/core.rb +26 -0
  265. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/ext/string.rb +176 -0
  266. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_creation_task.rb +25 -0
  267. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_list.rb +435 -0
  268. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_task.rb +58 -0
  269. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_utils.rb +132 -0
  270. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_utils_ext.rb +134 -0
  271. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/invocation_chain.rb +57 -0
  272. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/invocation_exception_mixin.rb +17 -0
  273. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/late_time.rb +18 -0
  274. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/linked_list.rb +112 -0
  275. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/loaders/makefile.rb +54 -0
  276. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/multi_task.rb +14 -0
  277. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/name_space.rb +38 -0
  278. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/packagetask.rb +222 -0
  279. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/phony.rb +16 -0
  280. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/private_reader.rb +21 -0
  281. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/promise.rb +100 -0
  282. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/pseudo_status.rb +30 -0
  283. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/rake_module.rb +67 -0
  284. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb +27 -0
  285. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/rule_recursion_overflow_error.rb +20 -0
  286. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/scope.rb +43 -0
  287. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/task.rb +434 -0
  288. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/task_argument_error.rb +8 -0
  289. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/task_arguments.rb +109 -0
  290. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/task_manager.rb +331 -0
  291. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/tasklib.rb +12 -0
  292. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/testtask.rb +189 -0
  293. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/thread_history_display.rb +49 -0
  294. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/thread_pool.rb +163 -0
  295. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/trace_output.rb +23 -0
  296. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/version.rb +10 -0
  297. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/win32.rb +51 -0
  298. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake.rb +70 -0
  299. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/rake.gemspec +101 -0
  300. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.circleci/config.yml +46 -0
  301. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.devcontainer/Dockerfile +16 -0
  302. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.devcontainer/devcontainer.json +36 -0
  303. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.devcontainer/docker-compose.yml +19 -0
  304. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.github/FUNDING.yml +13 -0
  305. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  306. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  307. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.github/dependabot.yml +15 -0
  308. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.gitignore +69 -0
  309. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.rspec +3 -0
  310. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.rubocop.yml +31 -0
  311. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/CHANGELOG.md +467 -0
  312. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/CODE_OF_CONDUCT.md +74 -0
  313. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/CONTRIBUTING.md +3 -0
  314. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/Gemfile +12 -0
  315. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/Gemfile.lock +92 -0
  316. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/LICENSE.txt +21 -0
  317. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/README.md +1381 -0
  318. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/Rakefile +19 -0
  319. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/bin/console +14 -0
  320. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/bin/setup +8 -0
  321. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/assistants.rb +29 -0
  322. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/audio.rb +19 -0
  323. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/batches.rb +23 -0
  324. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/client.rb +122 -0
  325. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/compatibility.rb +10 -0
  326. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/files.rb +75 -0
  327. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/finetunes.rb +27 -0
  328. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/http.rb +134 -0
  329. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/http_headers.rb +36 -0
  330. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/images.rb +27 -0
  331. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/messages.rb +27 -0
  332. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/models.rb +15 -0
  333. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/run_steps.rb +15 -0
  334. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/runs.rb +37 -0
  335. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/threads.rb +23 -0
  336. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/vector_store_file_batches.rb +29 -0
  337. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/vector_store_files.rb +23 -0
  338. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/vector_stores.rb +27 -0
  339. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/version.rb +3 -0
  340. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai.rb +92 -0
  341. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/ruby/openai.rb +2 -0
  342. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/pull_request_template.md +5 -0
  343. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/ruby-openai.gemspec +32 -0
  344. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/BSDL +24 -0
  345. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/COPYING +64 -0
  346. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/PSFL +271 -0
  347. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/README.md +108 -0
  348. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/Rakefile +74 -0
  349. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/doc/text/getting-started.md +246 -0
  350. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/doc/text/how-to.md +90 -0
  351. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/doc/text/news.md +1853 -0
  352. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/assertion-failed-error.rb +60 -0
  353. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/assertions.rb +2541 -0
  354. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/attribute-matcher.rb +26 -0
  355. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/attribute.rb +228 -0
  356. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/auto-runner-loader.rb +17 -0
  357. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/autorunner.rb +629 -0
  358. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/code-snippet-fetcher.rb +58 -0
  359. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/descendant.rb +20 -0
  360. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/dir.rb +110 -0
  361. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/load.rb +201 -0
  362. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/objectspace.rb +35 -0
  363. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/xml.rb +249 -0
  364. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector.rb +104 -0
  365. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/color-scheme.rb +225 -0
  366. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/color.rb +134 -0
  367. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/data-sets.rb +127 -0
  368. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/data.rb +371 -0
  369. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/diff.rb +745 -0
  370. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/error.rb +158 -0
  371. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/exception-handler.rb +82 -0
  372. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/failure.rb +169 -0
  373. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/fault-location-detector.rb +104 -0
  374. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/fixture.rb +304 -0
  375. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/notification.rb +138 -0
  376. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/omission.rb +198 -0
  377. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/pending.rb +155 -0
  378. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/priority.rb +194 -0
  379. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/runner/console.rb +86 -0
  380. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/runner/emacs.rb +8 -0
  381. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/runner/xml.rb +15 -0
  382. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/sub-test-result.rb +59 -0
  383. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/test-suite-creator.rb +103 -0
  384. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/test-suite-runner.rb +128 -0
  385. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/test-suite-thread-runner.rb +69 -0
  386. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/testcase.rb +963 -0
  387. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/testresult.rb +132 -0
  388. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/testsuite.rb +108 -0
  389. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/console/outputlevel.rb +15 -0
  390. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/console/testrunner.rb +891 -0
  391. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  392. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/testrunner.rb +53 -0
  393. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/testrunnermediator.rb +119 -0
  394. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  395. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/xml/testrunner.rb +224 -0
  396. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/backtracefilter.rb +59 -0
  397. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/memory-usage.rb +47 -0
  398. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/method-owner-finder.rb +28 -0
  399. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/observable.rb +86 -0
  400. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/output.rb +32 -0
  401. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/procwrapper.rb +48 -0
  402. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/version.rb +5 -0
  403. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/warning.rb +3 -0
  404. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit.rb +521 -0
  405. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test-unit.rb +19 -0
  406. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/adder.rb +13 -0
  407. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/subtracter.rb +12 -0
  408. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/test_adder.rb +20 -0
  409. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/test_subtracter.rb +20 -0
  410. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/test_user.rb +23 -0
  411. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/.document +5 -0
  412. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/CONTRIBUTING.md +15 -0
  413. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/LICENSE.md +20 -0
  414. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/README.md +45 -0
  415. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/bin/thor +6 -0
  416. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/create_file.rb +105 -0
  417. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/create_link.rb +61 -0
  418. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/directory.rb +108 -0
  419. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/empty_directory.rb +143 -0
  420. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/file_manipulation.rb +371 -0
  421. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/inject_into_file.rb +130 -0
  422. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions.rb +340 -0
  423. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/base.rb +825 -0
  424. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/command.rb +151 -0
  425. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/core_ext/hash_with_indifferent_access.rb +107 -0
  426. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/error.rb +106 -0
  427. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/group.rb +292 -0
  428. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/invocation.rb +178 -0
  429. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/line_editor/basic.rb +37 -0
  430. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/line_editor/readline.rb +88 -0
  431. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/line_editor.rb +17 -0
  432. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/nested_context.rb +29 -0
  433. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser/argument.rb +86 -0
  434. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser/arguments.rb +195 -0
  435. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser/option.rb +178 -0
  436. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser/options.rb +294 -0
  437. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser.rb +4 -0
  438. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/rake_compat.rb +72 -0
  439. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/runner.rb +335 -0
  440. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/basic.rb +388 -0
  441. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/color.rb +115 -0
  442. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/column_printer.rb +29 -0
  443. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/html.rb +84 -0
  444. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/lcs_diff.rb +49 -0
  445. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/table_printer.rb +118 -0
  446. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/terminal.rb +42 -0
  447. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/wrapped_printer.rb +38 -0
  448. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell.rb +81 -0
  449. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/util.rb +285 -0
  450. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/version.rb +3 -0
  451. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor.rb +674 -0
  452. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/thor.gemspec +33 -0
  453. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/BSDL +22 -0
  454. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/COPYING +56 -0
  455. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/README.md +55 -0
  456. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/common.rb +876 -0
  457. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/file.rb +100 -0
  458. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/ftp.rb +267 -0
  459. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/generic.rb +1578 -0
  460. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/http.rb +125 -0
  461. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/https.rb +23 -0
  462. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/ldap.rb +261 -0
  463. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/ldaps.rb +22 -0
  464. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/mailto.rb +293 -0
  465. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/rfc2396_parser.rb +546 -0
  466. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/rfc3986_parser.rb +206 -0
  467. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/version.rb +6 -0
  468. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/ws.rb +83 -0
  469. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/wss.rb +23 -0
  470. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri.rb +104 -0
  471. data/vendor/bundle/ruby/3.1.0/specifications/event_stream_parser-1.0.0.gemspec +23 -0
  472. data/vendor/bundle/ruby/3.1.0/specifications/faraday-2.12.2.gemspec +0 -0
  473. data/vendor/bundle/ruby/3.1.0/specifications/faraday-multipart-1.1.0.gemspec +32 -0
  474. data/vendor/bundle/ruby/3.1.0/specifications/faraday-net_http-3.4.0.gemspec +32 -0
  475. data/vendor/bundle/ruby/3.1.0/specifications/json-2.9.1.gemspec +0 -0
  476. data/vendor/bundle/ruby/3.1.0/specifications/logger-1.6.5.gemspec +22 -0
  477. data/vendor/bundle/ruby/3.1.0/specifications/multipart-post-2.4.1.gemspec +21 -0
  478. data/vendor/bundle/ruby/3.1.0/specifications/net-http-0.6.0.gemspec +33 -0
  479. data/vendor/bundle/ruby/3.1.0/specifications/power_assert-2.0.5.gemspec +24 -0
  480. data/vendor/bundle/ruby/3.1.0/specifications/rake-13.2.1.gemspec +26 -0
  481. data/vendor/bundle/ruby/3.1.0/specifications/ruby-openai-7.3.1.gemspec +36 -0
  482. data/vendor/bundle/ruby/3.1.0/specifications/test-unit-3.6.7.gemspec +31 -0
  483. data/vendor/bundle/ruby/3.1.0/specifications/thor-1.3.2.gemspec +34 -0
  484. data/vendor/bundle/ruby/3.1.0/specifications/uri-1.0.2.gemspec +23 -0
  485. metadata +560 -0
@@ -0,0 +1,1691 @@
1
+ #include "ruby.h"
2
+ #include "../fbuffer/fbuffer.h"
3
+
4
+ #include <math.h>
5
+ #include <ctype.h>
6
+
7
+ /* ruby api and some helpers */
8
+
9
+ typedef struct JSON_Generator_StateStruct {
10
+ VALUE indent;
11
+ VALUE space;
12
+ VALUE space_before;
13
+ VALUE object_nl;
14
+ VALUE array_nl;
15
+
16
+ long max_nesting;
17
+ long depth;
18
+ long buffer_initial_length;
19
+
20
+ bool allow_nan;
21
+ bool ascii_only;
22
+ bool script_safe;
23
+ bool strict;
24
+ } JSON_Generator_State;
25
+
26
+ #ifndef RB_UNLIKELY
27
+ #define RB_UNLIKELY(cond) (cond)
28
+ #endif
29
+
30
+ static VALUE mJSON, cState, mString_Extend, eGeneratorError, eNestingError, Encoding_UTF_8;
31
+
32
+ static ID i_to_s, i_to_json, i_new, i_pack, i_unpack, i_create_id, i_extend, i_encode;
33
+ static ID sym_indent, sym_space, sym_space_before, sym_object_nl, sym_array_nl, sym_max_nesting, sym_allow_nan,
34
+ sym_ascii_only, sym_depth, sym_buffer_initial_length, sym_script_safe, sym_escape_slash, sym_strict;
35
+
36
+
37
+ #define GET_STATE_TO(self, state) \
38
+ TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
39
+
40
+ #define GET_STATE(self) \
41
+ JSON_Generator_State *state; \
42
+ GET_STATE_TO(self, state)
43
+
44
+ struct generate_json_data;
45
+
46
+ typedef void (*generator_func)(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
47
+
48
+ struct generate_json_data {
49
+ FBuffer *buffer;
50
+ VALUE vstate;
51
+ JSON_Generator_State *state;
52
+ VALUE obj;
53
+ generator_func func;
54
+ };
55
+
56
+ static VALUE cState_from_state_s(VALUE self, VALUE opts);
57
+ static VALUE cState_partial_generate(VALUE self, VALUE obj, generator_func, VALUE io);
58
+ static void generate_json(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
59
+ static void generate_json_object(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
60
+ static void generate_json_array(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
61
+ static void generate_json_string(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
62
+ static void generate_json_null(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
63
+ static void generate_json_false(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
64
+ static void generate_json_true(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
65
+ #ifdef RUBY_INTEGER_UNIFICATION
66
+ static void generate_json_integer(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
67
+ #endif
68
+ static void generate_json_fixnum(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
69
+ static void generate_json_bignum(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
70
+ static void generate_json_float(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj);
71
+
72
+ static int usascii_encindex, utf8_encindex, binary_encindex;
73
+
74
+ #ifdef RBIMPL_ATTR_NORETURN
75
+ RBIMPL_ATTR_NORETURN()
76
+ #endif
77
+ static void raise_generator_error_str(VALUE invalid_object, VALUE str)
78
+ {
79
+ VALUE exc = rb_exc_new_str(eGeneratorError, str);
80
+ rb_ivar_set(exc, rb_intern("@invalid_object"), invalid_object);
81
+ rb_exc_raise(exc);
82
+ }
83
+
84
+ #ifdef RBIMPL_ATTR_NORETURN
85
+ RBIMPL_ATTR_NORETURN()
86
+ #endif
87
+ #ifdef RBIMPL_ATTR_FORMAT
88
+ RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
89
+ #endif
90
+ static void raise_generator_error(VALUE invalid_object, const char *fmt, ...)
91
+ {
92
+ va_list args;
93
+ va_start(args, fmt);
94
+ VALUE str = rb_vsprintf(fmt, args);
95
+ va_end(args);
96
+ raise_generator_error_str(invalid_object, str);
97
+ }
98
+
99
+ /* Converts in_string to a JSON string (without the wrapping '"'
100
+ * characters) in FBuffer out_buffer.
101
+ *
102
+ * Character are JSON-escaped according to:
103
+ *
104
+ * - Always: ASCII control characters (0x00-0x1F), dquote, and
105
+ * backslash.
106
+ *
107
+ * - If out_ascii_only: non-ASCII characters (>0x7F)
108
+ *
109
+ * - If out_script_safe: forwardslash, line separator (U+2028), and
110
+ * paragraph separator (U+2029)
111
+ *
112
+ * Everything else (should be UTF-8) is just passed through and
113
+ * appended to the result.
114
+ */
115
+ static void convert_UTF8_to_JSON(FBuffer *out_buffer, VALUE str, const char escape_table[256], bool out_script_safe)
116
+ {
117
+ const char *hexdig = "0123456789abcdef";
118
+ char scratch[12] = { '\\', 'u', 0, 0, 0, 0, '\\', 'u' };
119
+
120
+ const char *ptr = RSTRING_PTR(str);
121
+ unsigned long len = RSTRING_LEN(str);
122
+
123
+ unsigned long beg = 0, pos = 0;
124
+
125
+ #define FLUSH_POS(bytes) if (pos > beg) { fbuffer_append(out_buffer, &ptr[beg], pos - beg); } pos += bytes; beg = pos;
126
+
127
+ while (pos < len) {
128
+ unsigned char ch = ptr[pos];
129
+ unsigned char ch_len = escape_table[ch];
130
+ /* JSON encoding */
131
+
132
+ if (RB_UNLIKELY(ch_len)) {
133
+ switch (ch_len) {
134
+ case 1: {
135
+ FLUSH_POS(1);
136
+ switch (ch) {
137
+ case '"': fbuffer_append(out_buffer, "\\\"", 2); break;
138
+ case '\\': fbuffer_append(out_buffer, "\\\\", 2); break;
139
+ case '/': fbuffer_append(out_buffer, "\\/", 2); break;
140
+ case '\b': fbuffer_append(out_buffer, "\\b", 2); break;
141
+ case '\f': fbuffer_append(out_buffer, "\\f", 2); break;
142
+ case '\n': fbuffer_append(out_buffer, "\\n", 2); break;
143
+ case '\r': fbuffer_append(out_buffer, "\\r", 2); break;
144
+ case '\t': fbuffer_append(out_buffer, "\\t", 2); break;
145
+ default: {
146
+ scratch[2] = '0';
147
+ scratch[3] = '0';
148
+ scratch[4] = hexdig[(ch >> 4) & 0xf];
149
+ scratch[5] = hexdig[ch & 0xf];
150
+ fbuffer_append(out_buffer, scratch, 6);
151
+ break;
152
+ }
153
+ }
154
+ break;
155
+ }
156
+ case 3: {
157
+ unsigned char b2 = ptr[pos + 1];
158
+ if (RB_UNLIKELY(out_script_safe && ch == 0xE2 && b2 == 0x80)) {
159
+ unsigned char b3 = ptr[pos + 2];
160
+ if (b3 == 0xA8) {
161
+ FLUSH_POS(3);
162
+ fbuffer_append(out_buffer, "\\u2028", 6);
163
+ break;
164
+ } else if (b3 == 0xA9) {
165
+ FLUSH_POS(3);
166
+ fbuffer_append(out_buffer, "\\u2029", 6);
167
+ break;
168
+ }
169
+ }
170
+ // fallthrough
171
+ }
172
+ default:
173
+ pos += ch_len;
174
+ break;
175
+ }
176
+ } else {
177
+ pos++;
178
+ }
179
+ }
180
+ #undef FLUSH_POS
181
+
182
+ if (beg < len) {
183
+ fbuffer_append(out_buffer, &ptr[beg], len - beg);
184
+ }
185
+
186
+ RB_GC_GUARD(str);
187
+ }
188
+
189
+ static const char escape_table[256] = {
190
+ // ASCII Control Characters
191
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
192
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
193
+ // ASCII Characters
194
+ 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, // '"'
195
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
196
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
197
+ 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, // '\\'
198
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
199
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
200
+ // Continuation byte
201
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
202
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
203
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
204
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
205
+ // First byte of a 2-byte code point
206
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
207
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
208
+ // First byte of a 4-byte code point
209
+ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
210
+ //First byte of a 4+byte code point
211
+ 4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1,
212
+ };
213
+
214
+ static const char script_safe_escape_table[256] = {
215
+ // ASCII Control Characters
216
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
217
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
218
+ // ASCII Characters
219
+ 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1, // '"' and '/'
220
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
221
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
222
+ 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, // '\\'
223
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
224
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
225
+ // Continuation byte
226
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
227
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
228
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
229
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
230
+ // First byte of a 2-byte code point
231
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
232
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
233
+ // First byte of a 4-byte code point
234
+ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
235
+ //First byte of a 4+byte code point
236
+ 4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1,
237
+ };
238
+
239
+ static void convert_ASCII_to_JSON(FBuffer *out_buffer, VALUE str, const char escape_table[256])
240
+ {
241
+ const char *hexdig = "0123456789abcdef";
242
+ char scratch[12] = { '\\', 'u', 0, 0, 0, 0, '\\', 'u' };
243
+
244
+ const char *ptr = RSTRING_PTR(str);
245
+ unsigned long len = RSTRING_LEN(str);
246
+
247
+ unsigned long beg = 0, pos;
248
+
249
+ for (pos = 0; pos < len;) {
250
+ unsigned char ch = ptr[pos];
251
+ /* JSON encoding */
252
+ if (escape_table[ch]) {
253
+ if (pos > beg) {
254
+ fbuffer_append(out_buffer, &ptr[beg], pos - beg);
255
+ }
256
+
257
+ beg = pos + 1;
258
+ switch (ch) {
259
+ case '"': fbuffer_append(out_buffer, "\\\"", 2); break;
260
+ case '\\': fbuffer_append(out_buffer, "\\\\", 2); break;
261
+ case '/': fbuffer_append(out_buffer, "\\/", 2); break;
262
+ case '\b': fbuffer_append(out_buffer, "\\b", 2); break;
263
+ case '\f': fbuffer_append(out_buffer, "\\f", 2); break;
264
+ case '\n': fbuffer_append(out_buffer, "\\n", 2); break;
265
+ case '\r': fbuffer_append(out_buffer, "\\r", 2); break;
266
+ case '\t': fbuffer_append(out_buffer, "\\t", 2); break;
267
+ default:
268
+ scratch[2] = '0';
269
+ scratch[3] = '0';
270
+ scratch[4] = hexdig[(ch >> 4) & 0xf];
271
+ scratch[5] = hexdig[ch & 0xf];
272
+ fbuffer_append(out_buffer, scratch, 6);
273
+ }
274
+ }
275
+
276
+ pos++;
277
+ }
278
+
279
+ if (beg < len) {
280
+ fbuffer_append(out_buffer, &ptr[beg], len - beg);
281
+ }
282
+
283
+ RB_GC_GUARD(str);
284
+ }
285
+
286
+ static void convert_UTF8_to_ASCII_only_JSON(FBuffer *out_buffer, VALUE str, const char escape_table[256], bool out_script_safe)
287
+ {
288
+ const char *hexdig = "0123456789abcdef";
289
+ char scratch[12] = { '\\', 'u', 0, 0, 0, 0, '\\', 'u' };
290
+
291
+ const char *ptr = RSTRING_PTR(str);
292
+ unsigned long len = RSTRING_LEN(str);
293
+
294
+ unsigned long beg = 0, pos = 0;
295
+
296
+ #define FLUSH_POS(bytes) if (pos > beg) { fbuffer_append(out_buffer, &ptr[beg], pos - beg); } pos += bytes; beg = pos;
297
+
298
+ while (pos < len) {
299
+ unsigned char ch = ptr[pos];
300
+ unsigned char ch_len = escape_table[ch];
301
+
302
+ if (RB_UNLIKELY(ch_len)) {
303
+ switch (ch_len) {
304
+ case 1: {
305
+ FLUSH_POS(1);
306
+ switch (ch) {
307
+ case '"': fbuffer_append(out_buffer, "\\\"", 2); break;
308
+ case '\\': fbuffer_append(out_buffer, "\\\\", 2); break;
309
+ case '/': fbuffer_append(out_buffer, "\\/", 2); break;
310
+ case '\b': fbuffer_append(out_buffer, "\\b", 2); break;
311
+ case '\f': fbuffer_append(out_buffer, "\\f", 2); break;
312
+ case '\n': fbuffer_append(out_buffer, "\\n", 2); break;
313
+ case '\r': fbuffer_append(out_buffer, "\\r", 2); break;
314
+ case '\t': fbuffer_append(out_buffer, "\\t", 2); break;
315
+ default: {
316
+ scratch[2] = '0';
317
+ scratch[3] = '0';
318
+ scratch[4] = hexdig[(ch >> 4) & 0xf];
319
+ scratch[5] = hexdig[ch & 0xf];
320
+ fbuffer_append(out_buffer, scratch, 6);
321
+ break;
322
+ }
323
+ }
324
+ break;
325
+ }
326
+ default: {
327
+ uint32_t wchar = 0;
328
+ switch(ch_len) {
329
+ case 2:
330
+ wchar = ptr[pos] & 0x1F;
331
+ break;
332
+ case 3:
333
+ wchar = ptr[pos] & 0x0F;
334
+ break;
335
+ case 4:
336
+ wchar = ptr[pos] & 0x07;
337
+ break;
338
+ }
339
+
340
+ for (short i = 1; i < ch_len; i++) {
341
+ wchar = (wchar << 6) | (ptr[pos+i] & 0x3F);
342
+ }
343
+
344
+ FLUSH_POS(ch_len);
345
+
346
+ if (wchar <= 0xFFFF) {
347
+ scratch[2] = hexdig[wchar >> 12];
348
+ scratch[3] = hexdig[(wchar >> 8) & 0xf];
349
+ scratch[4] = hexdig[(wchar >> 4) & 0xf];
350
+ scratch[5] = hexdig[wchar & 0xf];
351
+ fbuffer_append(out_buffer, scratch, 6);
352
+ } else {
353
+ uint16_t hi, lo;
354
+ wchar -= 0x10000;
355
+ hi = 0xD800 + (uint16_t)(wchar >> 10);
356
+ lo = 0xDC00 + (uint16_t)(wchar & 0x3FF);
357
+
358
+ scratch[2] = hexdig[hi >> 12];
359
+ scratch[3] = hexdig[(hi >> 8) & 0xf];
360
+ scratch[4] = hexdig[(hi >> 4) & 0xf];
361
+ scratch[5] = hexdig[hi & 0xf];
362
+
363
+ scratch[8] = hexdig[lo >> 12];
364
+ scratch[9] = hexdig[(lo >> 8) & 0xf];
365
+ scratch[10] = hexdig[(lo >> 4) & 0xf];
366
+ scratch[11] = hexdig[lo & 0xf];
367
+
368
+ fbuffer_append(out_buffer, scratch, 12);
369
+ }
370
+
371
+ break;
372
+ }
373
+ }
374
+ } else {
375
+ pos++;
376
+ }
377
+ }
378
+ #undef FLUSH_POS
379
+
380
+ if (beg < len) {
381
+ fbuffer_append(out_buffer, &ptr[beg], len - beg);
382
+ }
383
+
384
+ RB_GC_GUARD(str);
385
+ }
386
+
387
+ /*
388
+ * Document-module: JSON::Ext::Generator
389
+ *
390
+ * This is the JSON generator implemented as a C extension. It can be
391
+ * configured to be used by setting
392
+ *
393
+ * JSON.generator = JSON::Ext::Generator
394
+ *
395
+ * with the method generator= in JSON.
396
+ *
397
+ */
398
+
399
+ /* Explanation of the following: that's the only way to not pollute
400
+ * standard library's docs with GeneratorMethods::<ClassName> which
401
+ * are uninformative and take a large place in a list of classes
402
+ */
403
+
404
+ /*
405
+ * Document-module: JSON::Ext::Generator::GeneratorMethods
406
+ * :nodoc:
407
+ */
408
+
409
+ /*
410
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::Array
411
+ * :nodoc:
412
+ */
413
+
414
+ /*
415
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::Bignum
416
+ * :nodoc:
417
+ */
418
+
419
+ /*
420
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::FalseClass
421
+ * :nodoc:
422
+ */
423
+
424
+ /*
425
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::Fixnum
426
+ * :nodoc:
427
+ */
428
+
429
+ /*
430
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::Float
431
+ * :nodoc:
432
+ */
433
+
434
+ /*
435
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::Hash
436
+ * :nodoc:
437
+ */
438
+
439
+ /*
440
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::Integer
441
+ * :nodoc:
442
+ */
443
+
444
+ /*
445
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::NilClass
446
+ * :nodoc:
447
+ */
448
+
449
+ /*
450
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::Object
451
+ * :nodoc:
452
+ */
453
+
454
+ /*
455
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::String
456
+ * :nodoc:
457
+ */
458
+
459
+ /*
460
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::String::Extend
461
+ * :nodoc:
462
+ */
463
+
464
+ /*
465
+ * Document-module: JSON::Ext::Generator::GeneratorMethods::TrueClass
466
+ * :nodoc:
467
+ */
468
+
469
+ /*
470
+ * call-seq: to_json(state = nil)
471
+ *
472
+ * Returns a JSON string containing a JSON object, that is generated from
473
+ * this Hash instance.
474
+ * _state_ is a JSON::State object, that can also be used to configure the
475
+ * produced JSON string output further.
476
+ */
477
+ static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self)
478
+ {
479
+ rb_check_arity(argc, 0, 1);
480
+ VALUE Vstate = cState_from_state_s(cState, argc == 1 ? argv[0] : Qnil);
481
+ return cState_partial_generate(Vstate, self, generate_json_object, Qfalse);
482
+ }
483
+
484
+ /*
485
+ * call-seq: to_json(state = nil)
486
+ *
487
+ * Returns a JSON string containing a JSON array, that is generated from
488
+ * this Array instance.
489
+ * _state_ is a JSON::State object, that can also be used to configure the
490
+ * produced JSON string output further.
491
+ */
492
+ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) {
493
+ rb_check_arity(argc, 0, 1);
494
+ VALUE Vstate = cState_from_state_s(cState, argc == 1 ? argv[0] : Qnil);
495
+ return cState_partial_generate(Vstate, self, generate_json_array, Qfalse);
496
+ }
497
+
498
+ #ifdef RUBY_INTEGER_UNIFICATION
499
+ /*
500
+ * call-seq: to_json(*)
501
+ *
502
+ * Returns a JSON string representation for this Integer number.
503
+ */
504
+ static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self)
505
+ {
506
+ rb_check_arity(argc, 0, 1);
507
+ VALUE Vstate = cState_from_state_s(cState, argc == 1 ? argv[0] : Qnil);
508
+ return cState_partial_generate(Vstate, self, generate_json_integer, Qfalse);
509
+ }
510
+
511
+ #else
512
+ /*
513
+ * call-seq: to_json(*)
514
+ *
515
+ * Returns a JSON string representation for this Integer number.
516
+ */
517
+ static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self)
518
+ {
519
+ rb_check_arity(argc, 0, 1);
520
+ VALUE Vstate = cState_from_state_s(cState, argc == 1 ? argv[0] : Qnil);
521
+ return cState_partial_generate(Vstate, self, generate_json_fixnum, Qfalse);
522
+ }
523
+
524
+ /*
525
+ * call-seq: to_json(*)
526
+ *
527
+ * Returns a JSON string representation for this Integer number.
528
+ */
529
+ static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self)
530
+ {
531
+ rb_check_arity(argc, 0, 1);
532
+ VALUE Vstate = cState_from_state_s(cState, argc == 1 ? argv[0] : Qnil);
533
+ return cState_partial_generate(Vstate, self, generate_json_bignum, Qfalse);
534
+ }
535
+ #endif
536
+
537
+ /*
538
+ * call-seq: to_json(*)
539
+ *
540
+ * Returns a JSON string representation for this Float number.
541
+ */
542
+ static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self)
543
+ {
544
+ rb_check_arity(argc, 0, 1);
545
+ VALUE Vstate = cState_from_state_s(cState, argc == 1 ? argv[0] : Qnil);
546
+ return cState_partial_generate(Vstate, self, generate_json_float, Qfalse);
547
+ }
548
+
549
+ /*
550
+ * call-seq: String.included(modul)
551
+ *
552
+ * Extends _modul_ with the String::Extend module.
553
+ */
554
+ static VALUE mString_included_s(VALUE self, VALUE modul) {
555
+ VALUE result = rb_funcall(modul, i_extend, 1, mString_Extend);
556
+ rb_call_super(1, &modul);
557
+ return result;
558
+ }
559
+
560
+ /*
561
+ * call-seq: to_json(*)
562
+ *
563
+ * This string should be encoded with UTF-8 A call to this method
564
+ * returns a JSON string encoded with UTF16 big endian characters as
565
+ * \u????.
566
+ */
567
+ static VALUE mString_to_json(int argc, VALUE *argv, VALUE self)
568
+ {
569
+ rb_check_arity(argc, 0, 1);
570
+ VALUE Vstate = cState_from_state_s(cState, argc == 1 ? argv[0] : Qnil);
571
+ return cState_partial_generate(Vstate, self, generate_json_string, Qfalse);
572
+ }
573
+
574
+ /*
575
+ * call-seq: to_json_raw_object()
576
+ *
577
+ * This method creates a raw object hash, that can be nested into
578
+ * other data structures and will be generated as a raw string. This
579
+ * method should be used, if you want to convert raw strings to JSON
580
+ * instead of UTF-8 strings, e. g. binary data.
581
+ */
582
+ static VALUE mString_to_json_raw_object(VALUE self)
583
+ {
584
+ VALUE ary;
585
+ VALUE result = rb_hash_new();
586
+ rb_hash_aset(result, rb_funcall(mJSON, i_create_id, 0), rb_class_name(rb_obj_class(self)));
587
+ ary = rb_funcall(self, i_unpack, 1, rb_str_new2("C*"));
588
+ rb_hash_aset(result, rb_utf8_str_new_lit("raw"), ary);
589
+ return result;
590
+ }
591
+
592
+ /*
593
+ * call-seq: to_json_raw(*args)
594
+ *
595
+ * This method creates a JSON text from the result of a call to
596
+ * to_json_raw_object of this String.
597
+ */
598
+ static VALUE mString_to_json_raw(int argc, VALUE *argv, VALUE self)
599
+ {
600
+ VALUE obj = mString_to_json_raw_object(self);
601
+ Check_Type(obj, T_HASH);
602
+ return mHash_to_json(argc, argv, obj);
603
+ }
604
+
605
+ /*
606
+ * call-seq: json_create(o)
607
+ *
608
+ * Raw Strings are JSON Objects (the raw bytes are stored in an array for the
609
+ * key "raw"). The Ruby String can be created by this module method.
610
+ */
611
+ static VALUE mString_Extend_json_create(VALUE self, VALUE o)
612
+ {
613
+ VALUE ary;
614
+ Check_Type(o, T_HASH);
615
+ ary = rb_hash_aref(o, rb_str_new2("raw"));
616
+ return rb_funcall(ary, i_pack, 1, rb_str_new2("C*"));
617
+ }
618
+
619
+ /*
620
+ * call-seq: to_json(*)
621
+ *
622
+ * Returns a JSON string for true: 'true'.
623
+ */
624
+ static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self)
625
+ {
626
+ rb_check_arity(argc, 0, 1);
627
+ return rb_utf8_str_new("true", 4);
628
+ }
629
+
630
+ /*
631
+ * call-seq: to_json(*)
632
+ *
633
+ * Returns a JSON string for false: 'false'.
634
+ */
635
+ static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self)
636
+ {
637
+ rb_check_arity(argc, 0, 1);
638
+ return rb_utf8_str_new("false", 5);
639
+ }
640
+
641
+ /*
642
+ * call-seq: to_json(*)
643
+ *
644
+ * Returns a JSON string for nil: 'null'.
645
+ */
646
+ static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self)
647
+ {
648
+ rb_check_arity(argc, 0, 1);
649
+ return rb_utf8_str_new("null", 4);
650
+ }
651
+
652
+ /*
653
+ * call-seq: to_json(*)
654
+ *
655
+ * Converts this object to a string (calling #to_s), converts
656
+ * it to a JSON string, and returns the result. This is a fallback, if no
657
+ * special method #to_json was defined for some object.
658
+ */
659
+ static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self)
660
+ {
661
+ VALUE state;
662
+ VALUE string = rb_funcall(self, i_to_s, 0);
663
+ rb_scan_args(argc, argv, "01", &state);
664
+ Check_Type(string, T_STRING);
665
+ state = cState_from_state_s(cState, state);
666
+ return cState_partial_generate(state, string, generate_json_string, Qfalse);
667
+ }
668
+
669
+ static void State_mark(void *ptr)
670
+ {
671
+ JSON_Generator_State *state = ptr;
672
+ rb_gc_mark_movable(state->indent);
673
+ rb_gc_mark_movable(state->space);
674
+ rb_gc_mark_movable(state->space_before);
675
+ rb_gc_mark_movable(state->object_nl);
676
+ rb_gc_mark_movable(state->array_nl);
677
+ }
678
+
679
+ static void State_compact(void *ptr)
680
+ {
681
+ JSON_Generator_State *state = ptr;
682
+ state->indent = rb_gc_location(state->indent);
683
+ state->space = rb_gc_location(state->space);
684
+ state->space_before = rb_gc_location(state->space_before);
685
+ state->object_nl = rb_gc_location(state->object_nl);
686
+ state->array_nl = rb_gc_location(state->array_nl);
687
+ }
688
+
689
+ static void State_free(void *ptr)
690
+ {
691
+ JSON_Generator_State *state = ptr;
692
+ ruby_xfree(state);
693
+ }
694
+
695
+ static size_t State_memsize(const void *ptr)
696
+ {
697
+ return sizeof(JSON_Generator_State);
698
+ }
699
+
700
+ #ifndef HAVE_RB_EXT_RACTOR_SAFE
701
+ # undef RUBY_TYPED_FROZEN_SHAREABLE
702
+ # define RUBY_TYPED_FROZEN_SHAREABLE 0
703
+ #endif
704
+
705
+ static const rb_data_type_t JSON_Generator_State_type = {
706
+ "JSON/Generator/State",
707
+ {
708
+ .dmark = State_mark,
709
+ .dfree = State_free,
710
+ .dsize = State_memsize,
711
+ .dcompact = State_compact,
712
+ },
713
+ 0, 0,
714
+ RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE,
715
+ };
716
+
717
+ static void state_init(JSON_Generator_State *state)
718
+ {
719
+ state->max_nesting = 100;
720
+ state->buffer_initial_length = FBUFFER_INITIAL_LENGTH_DEFAULT;
721
+ }
722
+
723
+ static VALUE cState_s_allocate(VALUE klass)
724
+ {
725
+ JSON_Generator_State *state;
726
+ VALUE obj = TypedData_Make_Struct(klass, JSON_Generator_State, &JSON_Generator_State_type, state);
727
+ state_init(state);
728
+ return obj;
729
+ }
730
+
731
+ static void vstate_spill(struct generate_json_data *data)
732
+ {
733
+ VALUE vstate = cState_s_allocate(cState);
734
+ GET_STATE(vstate);
735
+ MEMCPY(state, data->state, JSON_Generator_State, 1);
736
+ data->state = state;
737
+ data->vstate = vstate;
738
+ RB_OBJ_WRITTEN(vstate, Qundef, state->indent);
739
+ RB_OBJ_WRITTEN(vstate, Qundef, state->space);
740
+ RB_OBJ_WRITTEN(vstate, Qundef, state->space_before);
741
+ RB_OBJ_WRITTEN(vstate, Qundef, state->object_nl);
742
+ RB_OBJ_WRITTEN(vstate, Qundef, state->array_nl);
743
+ }
744
+
745
+ static inline VALUE vstate_get(struct generate_json_data *data)
746
+ {
747
+ if (RB_UNLIKELY(!data->vstate)) {
748
+ vstate_spill(data);
749
+ }
750
+ return data->vstate;
751
+ }
752
+
753
+ struct hash_foreach_arg {
754
+ struct generate_json_data *data;
755
+ int iter;
756
+ };
757
+
758
+ static int
759
+ json_object_i(VALUE key, VALUE val, VALUE _arg)
760
+ {
761
+ struct hash_foreach_arg *arg = (struct hash_foreach_arg *)_arg;
762
+ struct generate_json_data *data = arg->data;
763
+
764
+ FBuffer *buffer = data->buffer;
765
+ JSON_Generator_State *state = data->state;
766
+
767
+ long depth = state->depth;
768
+ int j;
769
+
770
+ if (arg->iter > 0) fbuffer_append_char(buffer, ',');
771
+ if (RB_UNLIKELY(state->object_nl)) {
772
+ fbuffer_append_str(buffer, state->object_nl);
773
+ }
774
+ if (RB_UNLIKELY(state->indent)) {
775
+ for (j = 0; j < depth; j++) {
776
+ fbuffer_append_str(buffer, state->indent);
777
+ }
778
+ }
779
+
780
+ VALUE key_to_s;
781
+ switch(rb_type(key)) {
782
+ case T_STRING:
783
+ if (RB_LIKELY(RBASIC_CLASS(key) == rb_cString)) {
784
+ key_to_s = key;
785
+ } else {
786
+ key_to_s = rb_funcall(key, i_to_s, 0);
787
+ }
788
+ break;
789
+ case T_SYMBOL:
790
+ key_to_s = rb_sym2str(key);
791
+ break;
792
+ default:
793
+ key_to_s = rb_convert_type(key, T_STRING, "String", "to_s");
794
+ break;
795
+ }
796
+
797
+ if (RB_LIKELY(RBASIC_CLASS(key_to_s) == rb_cString)) {
798
+ generate_json_string(buffer, data, state, key_to_s);
799
+ } else {
800
+ generate_json(buffer, data, state, key_to_s);
801
+ }
802
+ if (RB_UNLIKELY(state->space_before)) fbuffer_append_str(buffer, state->space_before);
803
+ fbuffer_append_char(buffer, ':');
804
+ if (RB_UNLIKELY(state->space)) fbuffer_append_str(buffer, state->space);
805
+ generate_json(buffer, data, state, val);
806
+
807
+ arg->iter++;
808
+ return ST_CONTINUE;
809
+ }
810
+
811
+ static void generate_json_object(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
812
+ {
813
+ long max_nesting = state->max_nesting;
814
+ long depth = ++state->depth;
815
+ int j;
816
+
817
+ if (max_nesting != 0 && depth > max_nesting) {
818
+ rb_raise(eNestingError, "nesting of %ld is too deep", --state->depth);
819
+ }
820
+
821
+ if (RHASH_SIZE(obj) == 0) {
822
+ fbuffer_append(buffer, "{}", 2);
823
+ --state->depth;
824
+ return;
825
+ }
826
+
827
+ fbuffer_append_char(buffer, '{');
828
+
829
+ struct hash_foreach_arg arg = {
830
+ .data = data,
831
+ .iter = 0,
832
+ };
833
+ rb_hash_foreach(obj, json_object_i, (VALUE)&arg);
834
+
835
+ depth = --state->depth;
836
+ if (RB_UNLIKELY(state->object_nl)) {
837
+ fbuffer_append_str(buffer, state->object_nl);
838
+ if (RB_UNLIKELY(state->indent)) {
839
+ for (j = 0; j < depth; j++) {
840
+ fbuffer_append_str(buffer, state->indent);
841
+ }
842
+ }
843
+ }
844
+ fbuffer_append_char(buffer, '}');
845
+ }
846
+
847
+ static void generate_json_array(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
848
+ {
849
+ long max_nesting = state->max_nesting;
850
+ long depth = ++state->depth;
851
+ int i, j;
852
+ if (max_nesting != 0 && depth > max_nesting) {
853
+ rb_raise(eNestingError, "nesting of %ld is too deep", --state->depth);
854
+ }
855
+
856
+ if (RARRAY_LEN(obj) == 0) {
857
+ fbuffer_append(buffer, "[]", 2);
858
+ --state->depth;
859
+ return;
860
+ }
861
+
862
+ fbuffer_append_char(buffer, '[');
863
+ if (RB_UNLIKELY(state->array_nl)) fbuffer_append_str(buffer, state->array_nl);
864
+ for(i = 0; i < RARRAY_LEN(obj); i++) {
865
+ if (i > 0) {
866
+ fbuffer_append_char(buffer, ',');
867
+ if (RB_UNLIKELY(state->array_nl)) fbuffer_append_str(buffer, state->array_nl);
868
+ }
869
+ if (RB_UNLIKELY(state->indent)) {
870
+ for (j = 0; j < depth; j++) {
871
+ fbuffer_append_str(buffer, state->indent);
872
+ }
873
+ }
874
+ generate_json(buffer, data, state, RARRAY_AREF(obj, i));
875
+ }
876
+ state->depth = --depth;
877
+ if (RB_UNLIKELY(state->array_nl)) {
878
+ fbuffer_append_str(buffer, state->array_nl);
879
+ if (RB_UNLIKELY(state->indent)) {
880
+ for (j = 0; j < depth; j++) {
881
+ fbuffer_append_str(buffer, state->indent);
882
+ }
883
+ }
884
+ }
885
+ fbuffer_append_char(buffer, ']');
886
+ }
887
+
888
+ static inline int enc_utf8_compatible_p(int enc_idx)
889
+ {
890
+ if (enc_idx == usascii_encindex) return 1;
891
+ if (enc_idx == utf8_encindex) return 1;
892
+ return 0;
893
+ }
894
+
895
+ static VALUE encode_json_string_try(VALUE str)
896
+ {
897
+ return rb_funcall(str, i_encode, 1, Encoding_UTF_8);
898
+ }
899
+
900
+ static VALUE encode_json_string_rescue(VALUE str, VALUE exception)
901
+ {
902
+ raise_generator_error_str(str, rb_funcall(exception, rb_intern("message"), 0));
903
+ return Qundef;
904
+ }
905
+
906
+ static inline VALUE ensure_valid_encoding(VALUE str)
907
+ {
908
+ int encindex = RB_ENCODING_GET(str);
909
+ VALUE utf8_string;
910
+ if (RB_UNLIKELY(!enc_utf8_compatible_p(encindex))) {
911
+ if (encindex == binary_encindex) {
912
+ utf8_string = rb_enc_associate_index(rb_str_dup(str), utf8_encindex);
913
+ switch (rb_enc_str_coderange(utf8_string)) {
914
+ case ENC_CODERANGE_7BIT:
915
+ return utf8_string;
916
+ case ENC_CODERANGE_VALID:
917
+ // For historical reason, we silently reinterpret binary strings as UTF-8 if it would work.
918
+ // TODO: Raise in 3.0.0
919
+ rb_warn("JSON.generate: UTF-8 string passed as BINARY, this will raise an encoding error in json 3.0");
920
+ return utf8_string;
921
+ break;
922
+ }
923
+ }
924
+
925
+ str = rb_rescue(encode_json_string_try, str, encode_json_string_rescue, str);
926
+ }
927
+ return str;
928
+ }
929
+
930
+ static void generate_json_string(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
931
+ {
932
+ obj = ensure_valid_encoding(obj);
933
+
934
+ fbuffer_append_char(buffer, '"');
935
+
936
+ switch(rb_enc_str_coderange(obj)) {
937
+ case ENC_CODERANGE_7BIT:
938
+ convert_ASCII_to_JSON(buffer, obj, state->script_safe ? script_safe_escape_table : escape_table);
939
+ break;
940
+ case ENC_CODERANGE_VALID:
941
+ if (RB_UNLIKELY(state->ascii_only)) {
942
+ convert_UTF8_to_ASCII_only_JSON(buffer, obj, state->script_safe ? script_safe_escape_table : escape_table, state->script_safe);
943
+ } else {
944
+ convert_UTF8_to_JSON(buffer, obj, state->script_safe ? script_safe_escape_table : escape_table, state->script_safe);
945
+ }
946
+ break;
947
+ default:
948
+ raise_generator_error(obj, "source sequence is illegal/malformed utf-8");
949
+ break;
950
+ }
951
+ fbuffer_append_char(buffer, '"');
952
+ }
953
+
954
+ static void generate_json_null(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
955
+ {
956
+ fbuffer_append(buffer, "null", 4);
957
+ }
958
+
959
+ static void generate_json_false(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
960
+ {
961
+ fbuffer_append(buffer, "false", 5);
962
+ }
963
+
964
+ static void generate_json_true(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
965
+ {
966
+ fbuffer_append(buffer, "true", 4);
967
+ }
968
+
969
+ static void generate_json_fixnum(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
970
+ {
971
+ fbuffer_append_long(buffer, FIX2LONG(obj));
972
+ }
973
+
974
+ static void generate_json_bignum(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
975
+ {
976
+ VALUE tmp = rb_funcall(obj, i_to_s, 0);
977
+ fbuffer_append_str(buffer, tmp);
978
+ }
979
+
980
+ #ifdef RUBY_INTEGER_UNIFICATION
981
+ static void generate_json_integer(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
982
+ {
983
+ if (FIXNUM_P(obj))
984
+ generate_json_fixnum(buffer, data, state, obj);
985
+ else
986
+ generate_json_bignum(buffer, data, state, obj);
987
+ }
988
+ #endif
989
+
990
+ static void generate_json_float(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
991
+ {
992
+ double value = RFLOAT_VALUE(obj);
993
+ char allow_nan = state->allow_nan;
994
+ VALUE tmp = rb_funcall(obj, i_to_s, 0);
995
+ if (!allow_nan) {
996
+ if (isinf(value) || isnan(value)) {
997
+ raise_generator_error(obj, "%"PRIsVALUE" not allowed in JSON", tmp);
998
+ }
999
+ }
1000
+ fbuffer_append_str(buffer, tmp);
1001
+ }
1002
+
1003
+ static void generate_json(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
1004
+ {
1005
+ VALUE tmp;
1006
+ if (obj == Qnil) {
1007
+ generate_json_null(buffer, data, state, obj);
1008
+ } else if (obj == Qfalse) {
1009
+ generate_json_false(buffer, data, state, obj);
1010
+ } else if (obj == Qtrue) {
1011
+ generate_json_true(buffer, data, state, obj);
1012
+ } else if (RB_SPECIAL_CONST_P(obj)) {
1013
+ if (RB_FIXNUM_P(obj)) {
1014
+ generate_json_fixnum(buffer, data, state, obj);
1015
+ } else if (RB_FLONUM_P(obj)) {
1016
+ generate_json_float(buffer, data, state, obj);
1017
+ } else {
1018
+ goto general;
1019
+ }
1020
+ } else {
1021
+ VALUE klass = RBASIC_CLASS(obj);
1022
+ switch (RB_BUILTIN_TYPE(obj)) {
1023
+ case T_BIGNUM:
1024
+ generate_json_bignum(buffer, data, state, obj);
1025
+ break;
1026
+ case T_HASH:
1027
+ if (klass != rb_cHash) goto general;
1028
+ generate_json_object(buffer, data, state, obj);
1029
+ break;
1030
+ case T_ARRAY:
1031
+ if (klass != rb_cArray) goto general;
1032
+ generate_json_array(buffer, data, state, obj);
1033
+ break;
1034
+ case T_STRING:
1035
+ if (klass != rb_cString) goto general;
1036
+ generate_json_string(buffer, data, state, obj);
1037
+ break;
1038
+ case T_FLOAT:
1039
+ if (klass != rb_cFloat) goto general;
1040
+ generate_json_float(buffer, data, state, obj);
1041
+ break;
1042
+ default:
1043
+ general:
1044
+ if (state->strict) {
1045
+ raise_generator_error(obj, "%"PRIsVALUE" not allowed in JSON", CLASS_OF(obj));
1046
+ } else if (rb_respond_to(obj, i_to_json)) {
1047
+ tmp = rb_funcall(obj, i_to_json, 1, vstate_get(data));
1048
+ Check_Type(tmp, T_STRING);
1049
+ fbuffer_append_str(buffer, tmp);
1050
+ } else {
1051
+ tmp = rb_funcall(obj, i_to_s, 0);
1052
+ Check_Type(tmp, T_STRING);
1053
+ generate_json_string(buffer, data, state, tmp);
1054
+ }
1055
+ }
1056
+ }
1057
+ }
1058
+
1059
+ static VALUE generate_json_try(VALUE d)
1060
+ {
1061
+ struct generate_json_data *data = (struct generate_json_data *)d;
1062
+
1063
+ data->func(data->buffer, data, data->state, data->obj);
1064
+
1065
+ return Qnil;
1066
+ }
1067
+
1068
+ static VALUE generate_json_rescue(VALUE d, VALUE exc)
1069
+ {
1070
+ struct generate_json_data *data = (struct generate_json_data *)d;
1071
+ fbuffer_free(data->buffer);
1072
+
1073
+ rb_exc_raise(exc);
1074
+
1075
+ return Qundef;
1076
+ }
1077
+
1078
+ static VALUE cState_partial_generate(VALUE self, VALUE obj, generator_func func, VALUE io)
1079
+ {
1080
+ GET_STATE(self);
1081
+
1082
+ char stack_buffer[FBUFFER_STACK_SIZE];
1083
+ FBuffer buffer = {
1084
+ .io = RTEST(io) ? io : Qfalse,
1085
+ };
1086
+ fbuffer_stack_init(&buffer, state->buffer_initial_length, stack_buffer, FBUFFER_STACK_SIZE);
1087
+
1088
+ struct generate_json_data data = {
1089
+ .buffer = &buffer,
1090
+ .vstate = self,
1091
+ .state = state,
1092
+ .obj = obj,
1093
+ .func = func
1094
+ };
1095
+ rb_rescue(generate_json_try, (VALUE)&data, generate_json_rescue, (VALUE)&data);
1096
+
1097
+ return fbuffer_finalize(&buffer);
1098
+ }
1099
+
1100
+ static VALUE cState_generate(VALUE self, VALUE obj, VALUE io)
1101
+ {
1102
+ VALUE result = cState_partial_generate(self, obj, generate_json, io);
1103
+ GET_STATE(self);
1104
+ (void)state;
1105
+ return result;
1106
+ }
1107
+
1108
+ static VALUE cState_initialize(int argc, VALUE *argv, VALUE self)
1109
+ {
1110
+ rb_warn("The json gem extension was loaded with the stdlib ruby code. You should upgrade rubygems with `gem update --system`");
1111
+ return self;
1112
+ }
1113
+
1114
+ /*
1115
+ * call-seq: initialize_copy(orig)
1116
+ *
1117
+ * Initializes this object from orig if it can be duplicated/cloned and returns
1118
+ * it.
1119
+ */
1120
+ static VALUE cState_init_copy(VALUE obj, VALUE orig)
1121
+ {
1122
+ JSON_Generator_State *objState, *origState;
1123
+
1124
+ if (obj == orig) return obj;
1125
+ GET_STATE_TO(obj, objState);
1126
+ GET_STATE_TO(orig, origState);
1127
+ if (!objState) rb_raise(rb_eArgError, "unallocated JSON::State");
1128
+
1129
+ MEMCPY(objState, origState, JSON_Generator_State, 1);
1130
+ objState->indent = origState->indent;
1131
+ objState->space = origState->space;
1132
+ objState->space_before = origState->space_before;
1133
+ objState->object_nl = origState->object_nl;
1134
+ objState->array_nl = origState->array_nl;
1135
+ return obj;
1136
+ }
1137
+
1138
+ /*
1139
+ * call-seq: from_state(opts)
1140
+ *
1141
+ * Creates a State object from _opts_, which ought to be Hash to create a
1142
+ * new State instance configured by _opts_, something else to create an
1143
+ * unconfigured instance. If _opts_ is a State object, it is just returned.
1144
+ */
1145
+ static VALUE cState_from_state_s(VALUE self, VALUE opts)
1146
+ {
1147
+ if (rb_obj_is_kind_of(opts, self)) {
1148
+ return opts;
1149
+ } else if (rb_obj_is_kind_of(opts, rb_cHash)) {
1150
+ return rb_funcall(self, i_new, 1, opts);
1151
+ } else {
1152
+ return rb_class_new_instance(0, NULL, cState);
1153
+ }
1154
+ }
1155
+
1156
+ /*
1157
+ * call-seq: indent()
1158
+ *
1159
+ * Returns the string that is used to indent levels in the JSON text.
1160
+ */
1161
+ static VALUE cState_indent(VALUE self)
1162
+ {
1163
+ GET_STATE(self);
1164
+ return state->indent ? state->indent : rb_str_freeze(rb_utf8_str_new("", 0));
1165
+ }
1166
+
1167
+ static VALUE string_config(VALUE config)
1168
+ {
1169
+ if (RTEST(config)) {
1170
+ Check_Type(config, T_STRING);
1171
+ if (RSTRING_LEN(config)) {
1172
+ return rb_str_new_frozen(config);
1173
+ }
1174
+ }
1175
+ return Qfalse;
1176
+ }
1177
+
1178
+ /*
1179
+ * call-seq: indent=(indent)
1180
+ *
1181
+ * Sets the string that is used to indent levels in the JSON text.
1182
+ */
1183
+ static VALUE cState_indent_set(VALUE self, VALUE indent)
1184
+ {
1185
+ GET_STATE(self);
1186
+ RB_OBJ_WRITE(self, &state->indent, string_config(indent));
1187
+ return Qnil;
1188
+ }
1189
+
1190
+ /*
1191
+ * call-seq: space()
1192
+ *
1193
+ * Returns the string that is used to insert a space between the tokens in a JSON
1194
+ * string.
1195
+ */
1196
+ static VALUE cState_space(VALUE self)
1197
+ {
1198
+ GET_STATE(self);
1199
+ return state->space ? state->space : rb_str_freeze(rb_utf8_str_new("", 0));
1200
+ }
1201
+
1202
+ /*
1203
+ * call-seq: space=(space)
1204
+ *
1205
+ * Sets _space_ to the string that is used to insert a space between the tokens in a JSON
1206
+ * string.
1207
+ */
1208
+ static VALUE cState_space_set(VALUE self, VALUE space)
1209
+ {
1210
+ GET_STATE(self);
1211
+ RB_OBJ_WRITE(self, &state->space, string_config(space));
1212
+ return Qnil;
1213
+ }
1214
+
1215
+ /*
1216
+ * call-seq: space_before()
1217
+ *
1218
+ * Returns the string that is used to insert a space before the ':' in JSON objects.
1219
+ */
1220
+ static VALUE cState_space_before(VALUE self)
1221
+ {
1222
+ GET_STATE(self);
1223
+ return state->space_before ? state->space_before : rb_str_freeze(rb_utf8_str_new("", 0));
1224
+ }
1225
+
1226
+ /*
1227
+ * call-seq: space_before=(space_before)
1228
+ *
1229
+ * Sets the string that is used to insert a space before the ':' in JSON objects.
1230
+ */
1231
+ static VALUE cState_space_before_set(VALUE self, VALUE space_before)
1232
+ {
1233
+ GET_STATE(self);
1234
+ RB_OBJ_WRITE(self, &state->space_before, string_config(space_before));
1235
+ return Qnil;
1236
+ }
1237
+
1238
+ /*
1239
+ * call-seq: object_nl()
1240
+ *
1241
+ * This string is put at the end of a line that holds a JSON object (or
1242
+ * Hash).
1243
+ */
1244
+ static VALUE cState_object_nl(VALUE self)
1245
+ {
1246
+ GET_STATE(self);
1247
+ return state->object_nl ? state->object_nl : rb_str_freeze(rb_utf8_str_new("", 0));
1248
+ }
1249
+
1250
+ /*
1251
+ * call-seq: object_nl=(object_nl)
1252
+ *
1253
+ * This string is put at the end of a line that holds a JSON object (or
1254
+ * Hash).
1255
+ */
1256
+ static VALUE cState_object_nl_set(VALUE self, VALUE object_nl)
1257
+ {
1258
+ GET_STATE(self);
1259
+ RB_OBJ_WRITE(self, &state->object_nl, string_config(object_nl));
1260
+ return Qnil;
1261
+ }
1262
+
1263
+ /*
1264
+ * call-seq: array_nl()
1265
+ *
1266
+ * This string is put at the end of a line that holds a JSON array.
1267
+ */
1268
+ static VALUE cState_array_nl(VALUE self)
1269
+ {
1270
+ GET_STATE(self);
1271
+ return state->array_nl ? state->array_nl : rb_str_freeze(rb_utf8_str_new("", 0));
1272
+ }
1273
+
1274
+ /*
1275
+ * call-seq: array_nl=(array_nl)
1276
+ *
1277
+ * This string is put at the end of a line that holds a JSON array.
1278
+ */
1279
+ static VALUE cState_array_nl_set(VALUE self, VALUE array_nl)
1280
+ {
1281
+ GET_STATE(self);
1282
+ RB_OBJ_WRITE(self, &state->array_nl, string_config(array_nl));
1283
+ return Qnil;
1284
+ }
1285
+
1286
+
1287
+ /*
1288
+ * call-seq: check_circular?
1289
+ *
1290
+ * Returns true, if circular data structures should be checked,
1291
+ * otherwise returns false.
1292
+ */
1293
+ static VALUE cState_check_circular_p(VALUE self)
1294
+ {
1295
+ GET_STATE(self);
1296
+ return state->max_nesting ? Qtrue : Qfalse;
1297
+ }
1298
+
1299
+ /*
1300
+ * call-seq: max_nesting
1301
+ *
1302
+ * This integer returns the maximum level of data structure nesting in
1303
+ * the generated JSON, max_nesting = 0 if no maximum is checked.
1304
+ */
1305
+ static VALUE cState_max_nesting(VALUE self)
1306
+ {
1307
+ GET_STATE(self);
1308
+ return LONG2FIX(state->max_nesting);
1309
+ }
1310
+
1311
+ static long long_config(VALUE num)
1312
+ {
1313
+ return RTEST(num) ? FIX2LONG(num) : 0;
1314
+ }
1315
+
1316
+ /*
1317
+ * call-seq: max_nesting=(depth)
1318
+ *
1319
+ * This sets the maximum level of data structure nesting in the generated JSON
1320
+ * to the integer depth, max_nesting = 0 if no maximum should be checked.
1321
+ */
1322
+ static VALUE cState_max_nesting_set(VALUE self, VALUE depth)
1323
+ {
1324
+ GET_STATE(self);
1325
+ state->max_nesting = long_config(depth);
1326
+ return Qnil;
1327
+ }
1328
+
1329
+ /*
1330
+ * call-seq: script_safe
1331
+ *
1332
+ * If this boolean is true, the forward slashes will be escaped in
1333
+ * the json output.
1334
+ */
1335
+ static VALUE cState_script_safe(VALUE self)
1336
+ {
1337
+ GET_STATE(self);
1338
+ return state->script_safe ? Qtrue : Qfalse;
1339
+ }
1340
+
1341
+ /*
1342
+ * call-seq: script_safe=(enable)
1343
+ *
1344
+ * This sets whether or not the forward slashes will be escaped in
1345
+ * the json output.
1346
+ */
1347
+ static VALUE cState_script_safe_set(VALUE self, VALUE enable)
1348
+ {
1349
+ GET_STATE(self);
1350
+ state->script_safe = RTEST(enable);
1351
+ return Qnil;
1352
+ }
1353
+
1354
+ /*
1355
+ * call-seq: strict
1356
+ *
1357
+ * If this boolean is false, types unsupported by the JSON format will
1358
+ * be serialized as strings.
1359
+ * If this boolean is true, types unsupported by the JSON format will
1360
+ * raise a JSON::GeneratorError.
1361
+ */
1362
+ static VALUE cState_strict(VALUE self)
1363
+ {
1364
+ GET_STATE(self);
1365
+ return state->strict ? Qtrue : Qfalse;
1366
+ }
1367
+
1368
+ /*
1369
+ * call-seq: strict=(enable)
1370
+ *
1371
+ * This sets whether or not to serialize types unsupported by the
1372
+ * JSON format as strings.
1373
+ * If this boolean is false, types unsupported by the JSON format will
1374
+ * be serialized as strings.
1375
+ * If this boolean is true, types unsupported by the JSON format will
1376
+ * raise a JSON::GeneratorError.
1377
+ */
1378
+ static VALUE cState_strict_set(VALUE self, VALUE enable)
1379
+ {
1380
+ GET_STATE(self);
1381
+ state->strict = RTEST(enable);
1382
+ return Qnil;
1383
+ }
1384
+
1385
+ /*
1386
+ * call-seq: allow_nan?
1387
+ *
1388
+ * Returns true, if NaN, Infinity, and -Infinity should be generated, otherwise
1389
+ * returns false.
1390
+ */
1391
+ static VALUE cState_allow_nan_p(VALUE self)
1392
+ {
1393
+ GET_STATE(self);
1394
+ return state->allow_nan ? Qtrue : Qfalse;
1395
+ }
1396
+
1397
+ /*
1398
+ * call-seq: allow_nan=(enable)
1399
+ *
1400
+ * This sets whether or not to serialize NaN, Infinity, and -Infinity
1401
+ */
1402
+ static VALUE cState_allow_nan_set(VALUE self, VALUE enable)
1403
+ {
1404
+ GET_STATE(self);
1405
+ state->allow_nan = RTEST(enable);
1406
+ return Qnil;
1407
+ }
1408
+
1409
+ /*
1410
+ * call-seq: ascii_only?
1411
+ *
1412
+ * Returns true, if only ASCII characters should be generated. Otherwise
1413
+ * returns false.
1414
+ */
1415
+ static VALUE cState_ascii_only_p(VALUE self)
1416
+ {
1417
+ GET_STATE(self);
1418
+ return state->ascii_only ? Qtrue : Qfalse;
1419
+ }
1420
+
1421
+ /*
1422
+ * call-seq: ascii_only=(enable)
1423
+ *
1424
+ * This sets whether only ASCII characters should be generated.
1425
+ */
1426
+ static VALUE cState_ascii_only_set(VALUE self, VALUE enable)
1427
+ {
1428
+ GET_STATE(self);
1429
+ state->ascii_only = RTEST(enable);
1430
+ return Qnil;
1431
+ }
1432
+
1433
+ /*
1434
+ * call-seq: depth
1435
+ *
1436
+ * This integer returns the current depth of data structure nesting.
1437
+ */
1438
+ static VALUE cState_depth(VALUE self)
1439
+ {
1440
+ GET_STATE(self);
1441
+ return LONG2FIX(state->depth);
1442
+ }
1443
+
1444
+ /*
1445
+ * call-seq: depth=(depth)
1446
+ *
1447
+ * This sets the maximum level of data structure nesting in the generated JSON
1448
+ * to the integer depth, max_nesting = 0 if no maximum should be checked.
1449
+ */
1450
+ static VALUE cState_depth_set(VALUE self, VALUE depth)
1451
+ {
1452
+ GET_STATE(self);
1453
+ state->depth = long_config(depth);
1454
+ return Qnil;
1455
+ }
1456
+
1457
+ /*
1458
+ * call-seq: buffer_initial_length
1459
+ *
1460
+ * This integer returns the current initial length of the buffer.
1461
+ */
1462
+ static VALUE cState_buffer_initial_length(VALUE self)
1463
+ {
1464
+ GET_STATE(self);
1465
+ return LONG2FIX(state->buffer_initial_length);
1466
+ }
1467
+
1468
+ static void buffer_initial_length_set(JSON_Generator_State *state, VALUE buffer_initial_length)
1469
+ {
1470
+ Check_Type(buffer_initial_length, T_FIXNUM);
1471
+ long initial_length = FIX2LONG(buffer_initial_length);
1472
+ if (initial_length > 0) {
1473
+ state->buffer_initial_length = initial_length;
1474
+ }
1475
+ }
1476
+
1477
+ /*
1478
+ * call-seq: buffer_initial_length=(length)
1479
+ *
1480
+ * This sets the initial length of the buffer to +length+, if +length+ > 0,
1481
+ * otherwise its value isn't changed.
1482
+ */
1483
+ static VALUE cState_buffer_initial_length_set(VALUE self, VALUE buffer_initial_length)
1484
+ {
1485
+ GET_STATE(self);
1486
+ buffer_initial_length_set(state, buffer_initial_length);
1487
+ return Qnil;
1488
+ }
1489
+
1490
+ static int configure_state_i(VALUE key, VALUE val, VALUE _arg)
1491
+ {
1492
+ JSON_Generator_State *state = (JSON_Generator_State *)_arg;
1493
+
1494
+ if (key == sym_indent) { state->indent = string_config(val); }
1495
+ else if (key == sym_space) { state->space = string_config(val); }
1496
+ else if (key == sym_space_before) { state->space_before = string_config(val); }
1497
+ else if (key == sym_object_nl) { state->object_nl = string_config(val); }
1498
+ else if (key == sym_array_nl) { state->array_nl = string_config(val); }
1499
+ else if (key == sym_max_nesting) { state->max_nesting = long_config(val); }
1500
+ else if (key == sym_allow_nan) { state->allow_nan = RTEST(val); }
1501
+ else if (key == sym_ascii_only) { state->ascii_only = RTEST(val); }
1502
+ else if (key == sym_depth) { state->depth = long_config(val); }
1503
+ else if (key == sym_buffer_initial_length) { buffer_initial_length_set(state, val); }
1504
+ else if (key == sym_script_safe) { state->script_safe = RTEST(val); }
1505
+ else if (key == sym_escape_slash) { state->script_safe = RTEST(val); }
1506
+ else if (key == sym_strict) { state->strict = RTEST(val); }
1507
+ return ST_CONTINUE;
1508
+ }
1509
+
1510
+ static void configure_state(JSON_Generator_State *state, VALUE config)
1511
+ {
1512
+ if (!RTEST(config)) return;
1513
+
1514
+ Check_Type(config, T_HASH);
1515
+
1516
+ if (!RHASH_SIZE(config)) return;
1517
+
1518
+ // We assume in most cases few keys are set so it's faster to go over
1519
+ // the provided keys than to check all possible keys.
1520
+ rb_hash_foreach(config, configure_state_i, (VALUE)state);
1521
+ }
1522
+
1523
+ static VALUE cState_configure(VALUE self, VALUE opts)
1524
+ {
1525
+ GET_STATE(self);
1526
+ configure_state(state, opts);
1527
+ return self;
1528
+ }
1529
+
1530
+ static VALUE cState_m_generate(VALUE klass, VALUE obj, VALUE opts, VALUE io)
1531
+ {
1532
+ JSON_Generator_State state = {0};
1533
+ state_init(&state);
1534
+ configure_state(&state, opts);
1535
+
1536
+ char stack_buffer[FBUFFER_STACK_SIZE];
1537
+ FBuffer buffer = {
1538
+ .io = RTEST(io) ? io : Qfalse,
1539
+ };
1540
+ fbuffer_stack_init(&buffer, state.buffer_initial_length, stack_buffer, FBUFFER_STACK_SIZE);
1541
+
1542
+ struct generate_json_data data = {
1543
+ .buffer = &buffer,
1544
+ .vstate = Qfalse,
1545
+ .state = &state,
1546
+ .obj = obj,
1547
+ .func = generate_json,
1548
+ };
1549
+ rb_rescue(generate_json_try, (VALUE)&data, generate_json_rescue, (VALUE)&data);
1550
+
1551
+ return fbuffer_finalize(&buffer);
1552
+ }
1553
+
1554
+ /*
1555
+ *
1556
+ */
1557
+ void Init_generator(void)
1558
+ {
1559
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
1560
+ rb_ext_ractor_safe(true);
1561
+ #endif
1562
+
1563
+ #undef rb_intern
1564
+ rb_require("json/common");
1565
+
1566
+ mJSON = rb_define_module("JSON");
1567
+ VALUE mExt = rb_define_module_under(mJSON, "Ext");
1568
+ VALUE mGenerator = rb_define_module_under(mExt, "Generator");
1569
+
1570
+ rb_global_variable(&eGeneratorError);
1571
+ eGeneratorError = rb_path2class("JSON::GeneratorError");
1572
+
1573
+ rb_global_variable(&eNestingError);
1574
+ eNestingError = rb_path2class("JSON::NestingError");
1575
+
1576
+ cState = rb_define_class_under(mGenerator, "State", rb_cObject);
1577
+ rb_define_alloc_func(cState, cState_s_allocate);
1578
+ rb_define_singleton_method(cState, "from_state", cState_from_state_s, 1);
1579
+ rb_define_method(cState, "initialize", cState_initialize, -1);
1580
+ rb_define_alias(cState, "initialize", "initialize"); // avoid method redefinition warnings
1581
+ rb_define_private_method(cState, "_configure", cState_configure, 1);
1582
+
1583
+ rb_define_method(cState, "initialize_copy", cState_init_copy, 1);
1584
+ rb_define_method(cState, "indent", cState_indent, 0);
1585
+ rb_define_method(cState, "indent=", cState_indent_set, 1);
1586
+ rb_define_method(cState, "space", cState_space, 0);
1587
+ rb_define_method(cState, "space=", cState_space_set, 1);
1588
+ rb_define_method(cState, "space_before", cState_space_before, 0);
1589
+ rb_define_method(cState, "space_before=", cState_space_before_set, 1);
1590
+ rb_define_method(cState, "object_nl", cState_object_nl, 0);
1591
+ rb_define_method(cState, "object_nl=", cState_object_nl_set, 1);
1592
+ rb_define_method(cState, "array_nl", cState_array_nl, 0);
1593
+ rb_define_method(cState, "array_nl=", cState_array_nl_set, 1);
1594
+ rb_define_method(cState, "max_nesting", cState_max_nesting, 0);
1595
+ rb_define_method(cState, "max_nesting=", cState_max_nesting_set, 1);
1596
+ rb_define_method(cState, "script_safe", cState_script_safe, 0);
1597
+ rb_define_method(cState, "script_safe?", cState_script_safe, 0);
1598
+ rb_define_method(cState, "script_safe=", cState_script_safe_set, 1);
1599
+ rb_define_alias(cState, "escape_slash", "script_safe");
1600
+ rb_define_alias(cState, "escape_slash?", "script_safe?");
1601
+ rb_define_alias(cState, "escape_slash=", "script_safe=");
1602
+ rb_define_method(cState, "strict", cState_strict, 0);
1603
+ rb_define_method(cState, "strict?", cState_strict, 0);
1604
+ rb_define_method(cState, "strict=", cState_strict_set, 1);
1605
+ rb_define_method(cState, "check_circular?", cState_check_circular_p, 0);
1606
+ rb_define_method(cState, "allow_nan?", cState_allow_nan_p, 0);
1607
+ rb_define_method(cState, "allow_nan=", cState_allow_nan_set, 1);
1608
+ rb_define_method(cState, "ascii_only?", cState_ascii_only_p, 0);
1609
+ rb_define_method(cState, "ascii_only=", cState_ascii_only_set, 1);
1610
+ rb_define_method(cState, "depth", cState_depth, 0);
1611
+ rb_define_method(cState, "depth=", cState_depth_set, 1);
1612
+ rb_define_method(cState, "buffer_initial_length", cState_buffer_initial_length, 0);
1613
+ rb_define_method(cState, "buffer_initial_length=", cState_buffer_initial_length_set, 1);
1614
+ rb_define_private_method(cState, "_generate", cState_generate, 2);
1615
+
1616
+ rb_define_singleton_method(cState, "generate", cState_m_generate, 3);
1617
+
1618
+ VALUE mGeneratorMethods = rb_define_module_under(mGenerator, "GeneratorMethods");
1619
+
1620
+ VALUE mObject = rb_define_module_under(mGeneratorMethods, "Object");
1621
+ rb_define_method(mObject, "to_json", mObject_to_json, -1);
1622
+
1623
+ VALUE mHash = rb_define_module_under(mGeneratorMethods, "Hash");
1624
+ rb_define_method(mHash, "to_json", mHash_to_json, -1);
1625
+
1626
+ VALUE mArray = rb_define_module_under(mGeneratorMethods, "Array");
1627
+ rb_define_method(mArray, "to_json", mArray_to_json, -1);
1628
+
1629
+ #ifdef RUBY_INTEGER_UNIFICATION
1630
+ VALUE mInteger = rb_define_module_under(mGeneratorMethods, "Integer");
1631
+ rb_define_method(mInteger, "to_json", mInteger_to_json, -1);
1632
+ #else
1633
+ VALUE mFixnum = rb_define_module_under(mGeneratorMethods, "Fixnum");
1634
+ rb_define_method(mFixnum, "to_json", mFixnum_to_json, -1);
1635
+
1636
+ VALUE mBignum = rb_define_module_under(mGeneratorMethods, "Bignum");
1637
+ rb_define_method(mBignum, "to_json", mBignum_to_json, -1);
1638
+ #endif
1639
+ VALUE mFloat = rb_define_module_under(mGeneratorMethods, "Float");
1640
+ rb_define_method(mFloat, "to_json", mFloat_to_json, -1);
1641
+
1642
+ VALUE mString = rb_define_module_under(mGeneratorMethods, "String");
1643
+ rb_define_singleton_method(mString, "included", mString_included_s, 1);
1644
+ rb_define_method(mString, "to_json", mString_to_json, -1);
1645
+ rb_define_method(mString, "to_json_raw", mString_to_json_raw, -1);
1646
+ rb_define_method(mString, "to_json_raw_object", mString_to_json_raw_object, 0);
1647
+
1648
+ mString_Extend = rb_define_module_under(mString, "Extend");
1649
+ rb_define_method(mString_Extend, "json_create", mString_Extend_json_create, 1);
1650
+
1651
+ VALUE mTrueClass = rb_define_module_under(mGeneratorMethods, "TrueClass");
1652
+ rb_define_method(mTrueClass, "to_json", mTrueClass_to_json, -1);
1653
+
1654
+ VALUE mFalseClass = rb_define_module_under(mGeneratorMethods, "FalseClass");
1655
+ rb_define_method(mFalseClass, "to_json", mFalseClass_to_json, -1);
1656
+
1657
+ VALUE mNilClass = rb_define_module_under(mGeneratorMethods, "NilClass");
1658
+ rb_define_method(mNilClass, "to_json", mNilClass_to_json, -1);
1659
+
1660
+ rb_global_variable(&Encoding_UTF_8);
1661
+ Encoding_UTF_8 = rb_const_get(rb_path2class("Encoding"), rb_intern("UTF_8"));
1662
+
1663
+ i_to_s = rb_intern("to_s");
1664
+ i_to_json = rb_intern("to_json");
1665
+ i_new = rb_intern("new");
1666
+ i_pack = rb_intern("pack");
1667
+ i_unpack = rb_intern("unpack");
1668
+ i_create_id = rb_intern("create_id");
1669
+ i_extend = rb_intern("extend");
1670
+ i_encode = rb_intern("encode");
1671
+
1672
+ sym_indent = ID2SYM(rb_intern("indent"));
1673
+ sym_space = ID2SYM(rb_intern("space"));
1674
+ sym_space_before = ID2SYM(rb_intern("space_before"));
1675
+ sym_object_nl = ID2SYM(rb_intern("object_nl"));
1676
+ sym_array_nl = ID2SYM(rb_intern("array_nl"));
1677
+ sym_max_nesting = ID2SYM(rb_intern("max_nesting"));
1678
+ sym_allow_nan = ID2SYM(rb_intern("allow_nan"));
1679
+ sym_ascii_only = ID2SYM(rb_intern("ascii_only"));
1680
+ sym_depth = ID2SYM(rb_intern("depth"));
1681
+ sym_buffer_initial_length = ID2SYM(rb_intern("buffer_initial_length"));
1682
+ sym_script_safe = ID2SYM(rb_intern("script_safe"));
1683
+ sym_escape_slash = ID2SYM(rb_intern("escape_slash"));
1684
+ sym_strict = ID2SYM(rb_intern("strict"));
1685
+
1686
+ usascii_encindex = rb_usascii_encindex();
1687
+ utf8_encindex = rb_utf8_encindex();
1688
+ binary_encindex = rb_ascii8bit_encindex();
1689
+
1690
+ rb_require("json/ext/generator/state");
1691
+ }