active_cached_resource 0.0.1.pre → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/LICENSE +21 -0
  4. data/lib/active_cached_resource/caching.rb +104 -1
  5. data/lib/active_cached_resource/configuration.rb +22 -1
  6. data/lib/active_cached_resource/logger.rb +14 -0
  7. data/lib/active_cached_resource/model.rb +18 -0
  8. data/lib/active_cached_resource/version.rb +1 -8
  9. data/lib/activeresource/lib/active_resource/collection.rb +14 -1
  10. data/lib/activeresource/lib/active_resource/railtie.rb +2 -2
  11. data/lib/activeresource/lib/active_resource.rb +1 -1
  12. metadata +5 -401
  13. data/.rspec +0 -3
  14. data/.rubocop.yml +0 -22
  15. data/.standard.yml +0 -2
  16. data/Rakefile +0 -21
  17. data/example/consumer/.dockerignore +0 -41
  18. data/example/consumer/.gitattributes +0 -9
  19. data/example/consumer/.gitignore +0 -36
  20. data/example/consumer/.kamal/hooks/docker-setup.sample +0 -3
  21. data/example/consumer/.kamal/hooks/post-deploy.sample +0 -14
  22. data/example/consumer/.kamal/hooks/post-proxy-reboot.sample +0 -3
  23. data/example/consumer/.kamal/hooks/pre-build.sample +0 -51
  24. data/example/consumer/.kamal/hooks/pre-connect.sample +0 -47
  25. data/example/consumer/.kamal/hooks/pre-deploy.sample +0 -109
  26. data/example/consumer/.kamal/hooks/pre-proxy-reboot.sample +0 -3
  27. data/example/consumer/.kamal/secrets +0 -17
  28. data/example/consumer/Dockerfile +0 -65
  29. data/example/consumer/Gemfile +0 -17
  30. data/example/consumer/Rakefile +0 -6
  31. data/example/consumer/app/controllers/application_controller.rb +0 -2
  32. data/example/consumer/app/controllers/concerns/.keep +0 -0
  33. data/example/consumer/app/jobs/application_job.rb +0 -7
  34. data/example/consumer/app/mailers/application_mailer.rb +0 -4
  35. data/example/consumer/app/models/application_record.rb +0 -3
  36. data/example/consumer/app/models/concerns/.keep +0 -0
  37. data/example/consumer/app/models/person.rb +0 -9
  38. data/example/consumer/app/views/layouts/mailer.html.erb +0 -13
  39. data/example/consumer/app/views/layouts/mailer.text.erb +0 -1
  40. data/example/consumer/bin/brakeman +0 -7
  41. data/example/consumer/bin/bundle +0 -109
  42. data/example/consumer/bin/dev +0 -2
  43. data/example/consumer/bin/docker-entrypoint +0 -14
  44. data/example/consumer/bin/jobs +0 -6
  45. data/example/consumer/bin/kamal +0 -27
  46. data/example/consumer/bin/rails +0 -4
  47. data/example/consumer/bin/rake +0 -4
  48. data/example/consumer/bin/rubocop +0 -8
  49. data/example/consumer/bin/setup +0 -34
  50. data/example/consumer/bin/thrust +0 -5
  51. data/example/consumer/config/application.rb +0 -20
  52. data/example/consumer/config/boot.rb +0 -3
  53. data/example/consumer/config/cache.yml +0 -16
  54. data/example/consumer/config/credentials.yml.enc +0 -1
  55. data/example/consumer/config/database.yml +0 -14
  56. data/example/consumer/config/deploy.yml +0 -116
  57. data/example/consumer/config/environment.rb +0 -5
  58. data/example/consumer/config/environments/development.rb +0 -64
  59. data/example/consumer/config/environments/production.rb +0 -85
  60. data/example/consumer/config/environments/test.rb +0 -50
  61. data/example/consumer/config/initializers/cors.rb +0 -16
  62. data/example/consumer/config/initializers/filter_parameter_logging.rb +0 -8
  63. data/example/consumer/config/initializers/inflections.rb +0 -16
  64. data/example/consumer/config/locales/en.yml +0 -31
  65. data/example/consumer/config/puma.rb +0 -41
  66. data/example/consumer/config/queue.yml +0 -18
  67. data/example/consumer/config/recurring.yml +0 -10
  68. data/example/consumer/config/routes.rb +0 -10
  69. data/example/consumer/config.ru +0 -6
  70. data/example/consumer/db/cache_schema.rb +0 -14
  71. data/example/consumer/db/queue_schema.rb +0 -129
  72. data/example/consumer/db/seeds.rb +0 -0
  73. data/example/consumer/lib/tasks/.keep +0 -0
  74. data/example/consumer/log/.keep +0 -0
  75. data/example/consumer/public/robots.txt +0 -1
  76. data/example/consumer/script/.keep +0 -0
  77. data/example/consumer/storage/.keep +0 -0
  78. data/example/consumer/tmp/.keep +0 -0
  79. data/example/consumer/tmp/cache/.keep +0 -0
  80. data/example/consumer/tmp/pids/.keep +0 -0
  81. data/example/consumer/tmp/storage/.keep +0 -0
  82. data/example/consumer/vendor/.keep +0 -0
  83. data/example/provider/.dockerignore +0 -41
  84. data/example/provider/.gitattributes +0 -9
  85. data/example/provider/.gitignore +0 -32
  86. data/example/provider/.kamal/hooks/docker-setup.sample +0 -3
  87. data/example/provider/.kamal/hooks/post-deploy.sample +0 -14
  88. data/example/provider/.kamal/hooks/post-proxy-reboot.sample +0 -3
  89. data/example/provider/.kamal/hooks/pre-build.sample +0 -51
  90. data/example/provider/.kamal/hooks/pre-connect.sample +0 -47
  91. data/example/provider/.kamal/hooks/pre-deploy.sample +0 -109
  92. data/example/provider/.kamal/hooks/pre-proxy-reboot.sample +0 -3
  93. data/example/provider/.kamal/secrets +0 -17
  94. data/example/provider/Dockerfile +0 -65
  95. data/example/provider/Gemfile +0 -14
  96. data/example/provider/Rakefile +0 -6
  97. data/example/provider/app/controllers/application_controller.rb +0 -2
  98. data/example/provider/app/controllers/concerns/.keep +0 -0
  99. data/example/provider/app/controllers/people_controller.rb +0 -68
  100. data/example/provider/app/jobs/application_job.rb +0 -7
  101. data/example/provider/app/mailers/application_mailer.rb +0 -4
  102. data/example/provider/app/models/address.rb +0 -3
  103. data/example/provider/app/models/application_record.rb +0 -3
  104. data/example/provider/app/models/company.rb +0 -3
  105. data/example/provider/app/models/concerns/.keep +0 -0
  106. data/example/provider/app/models/person.rb +0 -6
  107. data/example/provider/app/views/layouts/mailer.html.erb +0 -13
  108. data/example/provider/app/views/layouts/mailer.text.erb +0 -1
  109. data/example/provider/bin/brakeman +0 -7
  110. data/example/provider/bin/bundle +0 -109
  111. data/example/provider/bin/dev +0 -2
  112. data/example/provider/bin/docker-entrypoint +0 -14
  113. data/example/provider/bin/jobs +0 -6
  114. data/example/provider/bin/kamal +0 -27
  115. data/example/provider/bin/rails +0 -4
  116. data/example/provider/bin/rake +0 -4
  117. data/example/provider/bin/rubocop +0 -8
  118. data/example/provider/bin/setup +0 -34
  119. data/example/provider/bin/thrust +0 -5
  120. data/example/provider/config/application.rb +0 -44
  121. data/example/provider/config/boot.rb +0 -3
  122. data/example/provider/config/cache.yml +0 -16
  123. data/example/provider/config/credentials.yml.enc +0 -1
  124. data/example/provider/config/database.yml +0 -20
  125. data/example/provider/config/deploy.yml +0 -116
  126. data/example/provider/config/environment.rb +0 -5
  127. data/example/provider/config/environments/development.rb +0 -64
  128. data/example/provider/config/environments/production.rb +0 -85
  129. data/example/provider/config/environments/test.rb +0 -50
  130. data/example/provider/config/initializers/cors.rb +0 -16
  131. data/example/provider/config/initializers/filter_parameter_logging.rb +0 -8
  132. data/example/provider/config/initializers/inflections.rb +0 -16
  133. data/example/provider/config/locales/en.yml +0 -31
  134. data/example/provider/config/puma.rb +0 -41
  135. data/example/provider/config/queue.yml +0 -18
  136. data/example/provider/config/recurring.yml +0 -10
  137. data/example/provider/config/routes.rb +0 -4
  138. data/example/provider/config.ru +0 -6
  139. data/example/provider/db/cache_schema.rb +0 -14
  140. data/example/provider/db/migrate/20241202183937_create_people.rb +0 -11
  141. data/example/provider/db/migrate/20241202183955_create_addresses.rb +0 -13
  142. data/example/provider/db/migrate/20241202184017_create_companies.rb +0 -14
  143. data/example/provider/db/queue_schema.rb +0 -129
  144. data/example/provider/db/schema.rb +0 -47
  145. data/example/provider/db/seeds.rb +0 -18
  146. data/example/provider/lib/tasks/.keep +0 -0
  147. data/example/provider/log/.keep +0 -0
  148. data/example/provider/public/robots.txt +0 -1
  149. data/example/provider/script/.keep +0 -0
  150. data/example/provider/storage/.keep +0 -0
  151. data/example/provider/tmp/.keep +0 -0
  152. data/example/provider/tmp/pids/.keep +0 -0
  153. data/example/provider/tmp/storage/.keep +0 -0
  154. data/example/provider/vendor/.keep +0 -0
  155. data/lib/activeresource/.gitignore +0 -15
  156. data/lib/activeresource/examples/performance.rb +0 -72
  157. data/lib/activeresource/test/abstract_unit.rb +0 -153
  158. data/lib/activeresource/test/cases/active_job_serializer_test.rb +0 -53
  159. data/lib/activeresource/test/cases/association_test.rb +0 -104
  160. data/lib/activeresource/test/cases/associations/builder/belongs_to_test.rb +0 -42
  161. data/lib/activeresource/test/cases/associations/builder/has_many_test.rb +0 -28
  162. data/lib/activeresource/test/cases/associations/builder/has_one_test.rb +0 -28
  163. data/lib/activeresource/test/cases/authorization_test.rb +0 -276
  164. data/lib/activeresource/test/cases/base/custom_methods_test.rb +0 -155
  165. data/lib/activeresource/test/cases/base/equality_test.rb +0 -53
  166. data/lib/activeresource/test/cases/base/load_test.rb +0 -249
  167. data/lib/activeresource/test/cases/base/schema_test.rb +0 -428
  168. data/lib/activeresource/test/cases/base_errors_test.rb +0 -129
  169. data/lib/activeresource/test/cases/base_test.rb +0 -1622
  170. data/lib/activeresource/test/cases/callbacks_test.rb +0 -155
  171. data/lib/activeresource/test/cases/collection_test.rb +0 -172
  172. data/lib/activeresource/test/cases/connection_test.rb +0 -357
  173. data/lib/activeresource/test/cases/finder_test.rb +0 -217
  174. data/lib/activeresource/test/cases/format_test.rb +0 -137
  175. data/lib/activeresource/test/cases/http_mock_test.rb +0 -213
  176. data/lib/activeresource/test/cases/inheritence_test.rb +0 -19
  177. data/lib/activeresource/test/cases/inheriting_hash_test.rb +0 -25
  178. data/lib/activeresource/test/cases/log_subscriber_test.rb +0 -63
  179. data/lib/activeresource/test/cases/reflection_test.rb +0 -65
  180. data/lib/activeresource/test/cases/validations_test.rb +0 -78
  181. data/lib/activeresource/test/fixtures/address.rb +0 -20
  182. data/lib/activeresource/test/fixtures/beast.rb +0 -16
  183. data/lib/activeresource/test/fixtures/comment.rb +0 -5
  184. data/lib/activeresource/test/fixtures/customer.rb +0 -5
  185. data/lib/activeresource/test/fixtures/inventory.rb +0 -14
  186. data/lib/activeresource/test/fixtures/person.rb +0 -15
  187. data/lib/activeresource/test/fixtures/pet.rb +0 -6
  188. data/lib/activeresource/test/fixtures/post.rb +0 -5
  189. data/lib/activeresource/test/fixtures/product.rb +0 -11
  190. data/lib/activeresource/test/fixtures/project.rb +0 -19
  191. data/lib/activeresource/test/fixtures/proxy.rb +0 -6
  192. data/lib/activeresource/test/fixtures/sound.rb +0 -11
  193. data/lib/activeresource/test/fixtures/street_address.rb +0 -6
  194. data/lib/activeresource/test/fixtures/subscription_plan.rb +0 -7
  195. data/lib/activeresource/test/fixtures/weather.rb +0 -21
  196. data/lib/activeresource/test/setter_trap.rb +0 -28
  197. data/lib/activeresource/test/singleton_test.rb +0 -138
  198. data/lib/activeresource/test/threadsafe_attributes_test.rb +0 -91
  199. data/sorbet/config +0 -4
  200. data/sorbet/rbi/annotations/.gitattributes +0 -1
  201. data/sorbet/rbi/annotations/activemodel.rbi +0 -89
  202. data/sorbet/rbi/annotations/activesupport.rbi +0 -457
  203. data/sorbet/rbi/annotations/minitest.rbi +0 -119
  204. data/sorbet/rbi/annotations/rainbow.rbi +0 -269
  205. data/sorbet/rbi/dsl/.gitattributes +0 -1
  206. data/sorbet/rbi/dsl/active_support/callbacks.rbi +0 -21
  207. data/sorbet/rbi/gems/.gitattributes +0 -1
  208. data/sorbet/rbi/gems/actioncable@8.0.0.rbi +0 -252
  209. data/sorbet/rbi/gems/actionmailbox@8.0.0.rbi +0 -9
  210. data/sorbet/rbi/gems/actionmailer@8.0.0.rbi +0 -9
  211. data/sorbet/rbi/gems/actionpack@8.0.0.rbi +0 -20909
  212. data/sorbet/rbi/gems/actiontext@8.0.0.rbi +0 -9
  213. data/sorbet/rbi/gems/actionview@8.0.0.rbi +0 -16207
  214. data/sorbet/rbi/gems/activejob@8.0.0.rbi +0 -9
  215. data/sorbet/rbi/gems/activemodel-serializers-xml@1.0.3.rbi +0 -166
  216. data/sorbet/rbi/gems/activemodel@8.0.0.rbi +0 -6857
  217. data/sorbet/rbi/gems/activerecord@8.0.0.rbi +0 -42896
  218. data/sorbet/rbi/gems/activeresource@6.1.4.rbi +0 -3944
  219. data/sorbet/rbi/gems/activestorage@8.0.0.rbi +0 -9
  220. data/sorbet/rbi/gems/activesupport@8.0.0.rbi +0 -21251
  221. data/sorbet/rbi/gems/ast@2.4.2.rbi +0 -585
  222. data/sorbet/rbi/gems/base64@0.2.0.rbi +0 -509
  223. data/sorbet/rbi/gems/benchmark@0.4.0.rbi +0 -618
  224. data/sorbet/rbi/gems/bigdecimal@3.1.8.rbi +0 -78
  225. data/sorbet/rbi/gems/builder@3.3.0.rbi +0 -9
  226. data/sorbet/rbi/gems/bump@0.10.0.rbi +0 -169
  227. data/sorbet/rbi/gems/byebug@11.1.3.rbi +0 -3607
  228. data/sorbet/rbi/gems/coderay@1.1.3.rbi +0 -3427
  229. data/sorbet/rbi/gems/concurrent-ruby@1.3.4.rbi +0 -11645
  230. data/sorbet/rbi/gems/connection_pool@2.4.1.rbi +0 -9
  231. data/sorbet/rbi/gems/crass@1.0.6.rbi +0 -623
  232. data/sorbet/rbi/gems/date@3.4.0.rbi +0 -75
  233. data/sorbet/rbi/gems/diff-lcs@1.5.1.rbi +0 -1131
  234. data/sorbet/rbi/gems/docile@1.4.1.rbi +0 -377
  235. data/sorbet/rbi/gems/drb@2.2.1.rbi +0 -1347
  236. data/sorbet/rbi/gems/erubi@1.13.0.rbi +0 -150
  237. data/sorbet/rbi/gems/globalid@1.2.1.rbi +0 -9
  238. data/sorbet/rbi/gems/i18n@1.14.6.rbi +0 -2359
  239. data/sorbet/rbi/gems/io-console@0.7.2.rbi +0 -9
  240. data/sorbet/rbi/gems/json@2.8.2.rbi +0 -1901
  241. data/sorbet/rbi/gems/language_server-protocol@3.17.0.3.rbi +0 -14238
  242. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +0 -240
  243. data/sorbet/rbi/gems/logger@1.6.1.rbi +0 -920
  244. data/sorbet/rbi/gems/loofah@2.23.1.rbi +0 -1081
  245. data/sorbet/rbi/gems/mail@2.8.1.rbi +0 -9
  246. data/sorbet/rbi/gems/marcel@1.0.4.rbi +0 -9
  247. data/sorbet/rbi/gems/method_source@1.1.0.rbi +0 -304
  248. data/sorbet/rbi/gems/mini_mime@1.1.5.rbi +0 -9
  249. data/sorbet/rbi/gems/minitest@5.25.2.rbi +0 -1547
  250. data/sorbet/rbi/gems/net-imap@0.5.1.rbi +0 -9
  251. data/sorbet/rbi/gems/net-pop@0.1.2.rbi +0 -9
  252. data/sorbet/rbi/gems/net-protocol@0.2.2.rbi +0 -292
  253. data/sorbet/rbi/gems/net-smtp@0.5.0.rbi +0 -9
  254. data/sorbet/rbi/gems/netrc@0.11.0.rbi +0 -159
  255. data/sorbet/rbi/gems/nio4r@2.7.4.rbi +0 -9
  256. data/sorbet/rbi/gems/nokogiri@1.16.7.rbi +0 -7311
  257. data/sorbet/rbi/gems/parallel@1.26.3.rbi +0 -291
  258. data/sorbet/rbi/gems/parser@3.3.6.0.rbi +0 -5519
  259. data/sorbet/rbi/gems/prism@1.2.0.rbi +0 -39085
  260. data/sorbet/rbi/gems/pry-byebug@3.10.1.rbi +0 -1151
  261. data/sorbet/rbi/gems/pry@0.14.2.rbi +0 -10076
  262. data/sorbet/rbi/gems/psych@5.2.0.rbi +0 -1785
  263. data/sorbet/rbi/gems/racc@1.8.1.rbi +0 -162
  264. data/sorbet/rbi/gems/rack-session@2.0.0.rbi +0 -727
  265. data/sorbet/rbi/gems/rack-test@2.1.0.rbi +0 -747
  266. data/sorbet/rbi/gems/rack@3.1.8.rbi +0 -4905
  267. data/sorbet/rbi/gems/rackup@2.2.1.rbi +0 -230
  268. data/sorbet/rbi/gems/rails-dom-testing@2.2.0.rbi +0 -758
  269. data/sorbet/rbi/gems/rails-html-sanitizer@1.6.0.rbi +0 -785
  270. data/sorbet/rbi/gems/rails@8.0.0.rbi +0 -9
  271. data/sorbet/rbi/gems/railties@8.0.0.rbi +0 -6287
  272. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +0 -403
  273. data/sorbet/rbi/gems/rake@13.2.1.rbi +0 -3091
  274. data/sorbet/rbi/gems/rbi@0.2.1.rbi +0 -4535
  275. data/sorbet/rbi/gems/rdoc@6.8.1.rbi +0 -12572
  276. data/sorbet/rbi/gems/regexp_parser@2.9.2.rbi +0 -3772
  277. data/sorbet/rbi/gems/reline@0.5.12.rbi +0 -2416
  278. data/sorbet/rbi/gems/rexml@3.3.9.rbi +0 -4858
  279. data/sorbet/rbi/gems/rspec-core@3.13.2.rbi +0 -11287
  280. data/sorbet/rbi/gems/rspec-expectations@3.13.3.rbi +0 -8183
  281. data/sorbet/rbi/gems/rspec-mocks@3.13.2.rbi +0 -5341
  282. data/sorbet/rbi/gems/rspec-support@3.13.1.rbi +0 -1630
  283. data/sorbet/rbi/gems/rspec@3.13.0.rbi +0 -83
  284. data/sorbet/rbi/gems/rubocop-ast@1.36.1.rbi +0 -7303
  285. data/sorbet/rbi/gems/rubocop-performance@1.21.1.rbi +0 -9
  286. data/sorbet/rbi/gems/rubocop@1.65.1.rbi +0 -58170
  287. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +0 -1318
  288. data/sorbet/rbi/gems/securerandom@0.3.2.rbi +0 -395
  289. data/sorbet/rbi/gems/simplecov-html@0.13.1.rbi +0 -225
  290. data/sorbet/rbi/gems/simplecov@0.22.0.rbi +0 -2149
  291. data/sorbet/rbi/gems/simplecov_json_formatter@0.1.4.rbi +0 -9
  292. data/sorbet/rbi/gems/spoom@1.5.0.rbi +0 -4932
  293. data/sorbet/rbi/gems/standard-custom@1.0.2.rbi +0 -9
  294. data/sorbet/rbi/gems/standard-performance@1.4.0.rbi +0 -9
  295. data/sorbet/rbi/gems/standard@1.40.0.rbi +0 -929
  296. data/sorbet/rbi/gems/stringio@3.1.2.rbi +0 -9
  297. data/sorbet/rbi/gems/tapioca@0.16.4.rbi +0 -3597
  298. data/sorbet/rbi/gems/thor@1.3.2.rbi +0 -4378
  299. data/sorbet/rbi/gems/timeout@0.4.2.rbi +0 -151
  300. data/sorbet/rbi/gems/tzinfo@2.0.6.rbi +0 -5918
  301. data/sorbet/rbi/gems/unicode-display_width@2.6.0.rbi +0 -66
  302. data/sorbet/rbi/gems/uri@1.0.2.rbi +0 -2377
  303. data/sorbet/rbi/gems/useragent@0.16.10.rbi +0 -9
  304. data/sorbet/rbi/gems/websocket-driver@0.7.6.rbi +0 -9
  305. data/sorbet/rbi/gems/websocket-extensions@0.1.5.rbi +0 -9
  306. data/sorbet/rbi/gems/yard-sorbet@0.9.0.rbi +0 -435
  307. data/sorbet/rbi/gems/yard@0.9.37.rbi +0 -18504
  308. data/sorbet/rbi/gems/zeitwerk@2.7.1.rbi +0 -9
  309. data/sorbet/tapioca/config.yml +0 -13
  310. data/sorbet/tapioca/require.rb +0 -12
@@ -1,585 +0,0 @@
1
- # typed: true
2
-
3
- # DO NOT EDIT MANUALLY
4
- # This is an autogenerated file for types exported from the `ast` gem.
5
- # Please instead update this file by running `bin/tapioca gem ast`.
6
-
7
-
8
- # {AST} is a library for manipulating abstract syntax trees.
9
- #
10
- # It embraces immutability; each AST node is inherently frozen at
11
- # creation, and updating a child node requires recreating that node
12
- # and its every parent, recursively.
13
- # This is a design choice. It does create some pressure on
14
- # garbage collector, but completely eliminates all concurrency
15
- # and aliasing problems.
16
- #
17
- # See also {AST::Node}, {AST::Processor::Mixin} and {AST::Sexp} for
18
- # additional recommendations and design patterns.
19
- #
20
- # source://ast//lib/ast.rb#13
21
- module AST; end
22
-
23
- # Node is an immutable class, instances of which represent abstract
24
- # syntax tree nodes. It combines semantic information (i.e. anything
25
- # that affects the algorithmic properties of a program) with
26
- # meta-information (line numbers or compiler intermediates).
27
- #
28
- # Notes on inheritance
29
- # ====================
30
- #
31
- # The distinction between semantics and metadata is important. Complete
32
- # semantic information should be contained within just the {#type} and
33
- # {#children} of a Node instance; in other words, if an AST was to be
34
- # stripped of all meta-information, it should remain a valid AST which
35
- # could be successfully processed to yield a result with the same
36
- # algorithmic properties.
37
- #
38
- # Thus, Node should never be inherited in order to define methods which
39
- # affect or return semantic information, such as getters for `class_name`,
40
- # `superclass` and `body` in the case of a hypothetical `ClassNode`. The
41
- # correct solution is to use a generic Node with a {#type} of `:class`
42
- # and three children. See also {Processor} for tips on working with such
43
- # ASTs.
44
- #
45
- # On the other hand, Node can and should be inherited to define
46
- # application-specific metadata (see also {#initialize}) or customize the
47
- # printing format. It is expected that an application would have one or two
48
- # such classes and use them across the entire codebase.
49
- #
50
- # The rationale for this pattern is extensibility and maintainability.
51
- # Unlike static ones, dynamic languages do not require the presence of a
52
- # predefined, rigid structure, nor does it improve dispatch efficiency,
53
- # and while such a structure can certainly be defined, it does not add
54
- # any value but incurs a maintaining cost.
55
- # For example, extending the AST even with a transformation-local
56
- # temporary node type requires making globally visible changes to
57
- # the codebase.
58
- #
59
- # source://ast//lib/ast/node.rb#40
60
- class AST::Node
61
- # Constructs a new instance of Node.
62
- #
63
- # The arguments `type` and `children` are converted with `to_sym` and
64
- # `to_a` respectively. Additionally, the result of converting `children`
65
- # is frozen. While mutating the arguments is generally considered harmful,
66
- # the most common case is to pass an array literal to the constructor. If
67
- # your code does not expect the argument to be frozen, use `#dup`.
68
- #
69
- # The `properties` hash is passed to {#assign_properties}.
70
- #
71
- # @return [Node] a new instance of Node
72
- #
73
- # source://ast//lib/ast/node.rb#72
74
- def initialize(type, children = T.unsafe(nil), properties = T.unsafe(nil)); end
75
-
76
- # Concatenates `array` with `children` and returns the resulting node.
77
- #
78
- # @return [AST::Node]
79
- #
80
- # source://ast//lib/ast/node.rb#168
81
- def +(array); end
82
-
83
- # Appends `element` to `children` and returns the resulting node.
84
- #
85
- # @return [AST::Node]
86
- #
87
- # source://ast//lib/ast/node.rb#177
88
- def <<(element); end
89
-
90
- # Compares `self` to `other`, possibly converting with `to_ast`. Only
91
- # `type` and `children` are compared; metadata is deliberately ignored.
92
- #
93
- # @return [Boolean]
94
- #
95
- # source://ast//lib/ast/node.rb#153
96
- def ==(other); end
97
-
98
- # Appends `element` to `children` and returns the resulting node.
99
- #
100
- # @return [AST::Node]
101
- #
102
- # source://ast//lib/ast/node.rb#177
103
- def append(element); end
104
-
105
- # Returns the children of this node.
106
- # The returned value is frozen.
107
- # The to_a alias is useful for decomposing nodes concisely.
108
- # For example:
109
- #
110
- # node = s(:gasgn, :$foo, s(:integer, 1))
111
- # var_name, value = *node
112
- # p var_name # => :$foo
113
- # p value # => (integer 1)
114
- #
115
- # @return [Array]
116
- #
117
- # source://ast//lib/ast/node.rb#56
118
- def children; end
119
-
120
- # Nodes are already frozen, so there is no harm in returning the
121
- # current node as opposed to initializing from scratch and freezing
122
- # another one.
123
- #
124
- # @return self
125
- #
126
- # source://ast//lib/ast/node.rb#115
127
- def clone; end
128
-
129
- # Concatenates `array` with `children` and returns the resulting node.
130
- #
131
- # @return [AST::Node]
132
- #
133
- # source://ast//lib/ast/node.rb#168
134
- def concat(array); end
135
-
136
- # Enables matching for Node, where type is the first element
137
- # and the children are remaining items.
138
- #
139
- # @return [Array]
140
- #
141
- # source://ast//lib/ast/node.rb#253
142
- def deconstruct; end
143
-
144
- # Nodes are already frozen, so there is no harm in returning the
145
- # current node as opposed to initializing from scratch and freezing
146
- # another one.
147
- #
148
- # @return self
149
- #
150
- # source://ast//lib/ast/node.rb#115
151
- def dup; end
152
-
153
- # Test if other object is equal to
154
- #
155
- # @param other [Object]
156
- # @return [Boolean]
157
- #
158
- # source://ast//lib/ast/node.rb#85
159
- def eql?(other); end
160
-
161
- # Returns the precomputed hash value for this node
162
- #
163
- # @return [Fixnum]
164
- #
165
- # source://ast//lib/ast/node.rb#61
166
- def hash; end
167
-
168
- # Converts `self` to a s-expression ruby string.
169
- # The code return will recreate the node, using the sexp module s()
170
- #
171
- # @param indent [Integer] Base indentation level.
172
- # @return [String]
173
- #
174
- # source://ast//lib/ast/node.rb#211
175
- def inspect(indent = T.unsafe(nil)); end
176
-
177
- # Returns the children of this node.
178
- # The returned value is frozen.
179
- # The to_a alias is useful for decomposing nodes concisely.
180
- # For example:
181
- #
182
- # node = s(:gasgn, :$foo, s(:integer, 1))
183
- # var_name, value = *node
184
- # p var_name # => :$foo
185
- # p value # => (integer 1)
186
- #
187
- # @return [Array]
188
- #
189
- # source://ast//lib/ast/node.rb#56
190
- def to_a; end
191
-
192
- # @return [AST::Node] self
193
- #
194
- # source://ast//lib/ast/node.rb#229
195
- def to_ast; end
196
-
197
- # Converts `self` to a pretty-printed s-expression.
198
- #
199
- # @param indent [Integer] Base indentation level.
200
- # @return [String]
201
- #
202
- # source://ast//lib/ast/node.rb#187
203
- def to_s(indent = T.unsafe(nil)); end
204
-
205
- # Converts `self` to a pretty-printed s-expression.
206
- #
207
- # @param indent [Integer] Base indentation level.
208
- # @return [String]
209
- #
210
- # source://ast//lib/ast/node.rb#187
211
- def to_sexp(indent = T.unsafe(nil)); end
212
-
213
- # Converts `self` to an Array where the first element is the type as a Symbol,
214
- # and subsequent elements are the same representation of its children.
215
- #
216
- # @return [Array<Symbol, [...Array]>]
217
- #
218
- # source://ast//lib/ast/node.rb#237
219
- def to_sexp_array; end
220
-
221
- # Returns the type of this node.
222
- #
223
- # @return [Symbol]
224
- #
225
- # source://ast//lib/ast/node.rb#43
226
- def type; end
227
-
228
- # Returns a new instance of Node where non-nil arguments replace the
229
- # corresponding fields of `self`.
230
- #
231
- # For example, `Node.new(:foo, [ 1, 2 ]).updated(:bar)` would yield
232
- # `(bar 1 2)`, and `Node.new(:foo, [ 1, 2 ]).updated(nil, [])` would
233
- # yield `(foo)`.
234
- #
235
- # If the resulting node would be identical to `self`, does nothing.
236
- #
237
- # @param type [Symbol, nil]
238
- # @param children [Array, nil]
239
- # @param properties [Hash, nil]
240
- # @return [AST::Node]
241
- #
242
- # source://ast//lib/ast/node.rb#133
243
- def updated(type = T.unsafe(nil), children = T.unsafe(nil), properties = T.unsafe(nil)); end
244
-
245
- protected
246
-
247
- # By default, each entry in the `properties` hash is assigned to
248
- # an instance variable in this instance of Node. A subclass should define
249
- # attribute readers for such variables. The values passed in the hash
250
- # are not frozen or whitelisted; such behavior can also be implemented
251
- # by subclassing Node and overriding this method.
252
- #
253
- # @return [nil]
254
- #
255
- # source://ast//lib/ast/node.rb#98
256
- def assign_properties(properties); end
257
-
258
- # Returns `@type` with all underscores replaced by dashes. This allows
259
- # to write symbol literals without quotes in Ruby sources and yet have
260
- # nicely looking s-expressions.
261
- #
262
- # @return [String]
263
- #
264
- # source://ast//lib/ast/node.rb#264
265
- def fancy_type; end
266
-
267
- private
268
-
269
- def original_dup; end
270
- end
271
-
272
- # This class includes {AST::Processor::Mixin}; however, it is
273
- # deprecated, since the module defines all of the behaviors that
274
- # the processor includes. Any new libraries should use
275
- # {AST::Processor::Mixin} instead of subclassing this.
276
- #
277
- # @deprecated Use {AST::Processor::Mixin} instead.
278
- #
279
- # source://ast//lib/ast/processor.rb#8
280
- class AST::Processor
281
- include ::AST::Processor::Mixin
282
- end
283
-
284
- # The processor module is a module which helps transforming one
285
- # AST into another. In a nutshell, the {#process} method accepts
286
- # a {Node} and dispatches it to a handler corresponding to its
287
- # type, and returns a (possibly) updated variant of the node.
288
- #
289
- # The processor module has a set of associated design patterns.
290
- # They are best explained with a concrete example. Let's define a
291
- # simple arithmetic language and an AST format for it:
292
- #
293
- # Terminals (AST nodes which do not have other AST nodes inside):
294
- #
295
- # * `(integer <int-literal>)`,
296
- #
297
- # Nonterminals (AST nodes with other nodes as children):
298
- #
299
- # * `(add <node> <node>)`,
300
- # * `(multiply <node> <node>)`,
301
- # * `(divide <node> <node>)`,
302
- # * `(negate <node>)`,
303
- # * `(store <node> <string-literal>)`: stores value of `<node>`
304
- # into a variable named `<string-literal>`,
305
- # * `(load <string-literal>)`: loads value of a variable named
306
- # `<string-literal>`,
307
- # * `(each <node> ...)`: computes each of the `<node>`s and
308
- # prints the result.
309
- #
310
- # All AST nodes have the same Ruby class, and therefore they don't
311
- # know how to traverse themselves. (A solution which dynamically
312
- # checks the type of children is possible, but is slow and
313
- # error-prone.) So, a class including the module which knows how
314
- # to traverse the entire tree should be defined. Such classes
315
- # have a handler for each nonterminal node which recursively
316
- # processes children nodes:
317
- #
318
- # require 'ast'
319
- #
320
- # class ArithmeticsProcessor
321
- # include AST::Processor::Mixin
322
- # # This method traverses any binary operators such as (add)
323
- # # or (multiply).
324
- # def process_binary_op(node)
325
- # # Children aren't decomposed automatically; it is
326
- # # suggested to use Ruby multiple assignment expansion,
327
- # # as it is very convenient here.
328
- # left_expr, right_expr = *node
329
- #
330
- # # AST::Node#updated won't change node type if nil is
331
- # # passed as a first argument, which allows to reuse the
332
- # # same handler for multiple node types using `alias'
333
- # # (below).
334
- # node.updated(nil, [
335
- # process(left_expr),
336
- # process(right_expr)
337
- # ])
338
- # end
339
- # alias_method :on_add, :process_binary_op
340
- # alias_method :on_multiply, :process_binary_op
341
- # alias_method :on_divide, :process_binary_op
342
- #
343
- # def on_negate(node)
344
- # # It is also possible to use #process_all for more
345
- # # compact code if every child is a Node.
346
- # node.updated(nil, process_all(node))
347
- # end
348
- #
349
- # def on_store(node)
350
- # expr, variable_name = *node
351
- #
352
- # # Note that variable_name is not a Node and thus isn't
353
- # # passed to #process.
354
- # node.updated(nil, [
355
- # process(expr),
356
- # variable_name
357
- # ])
358
- # end
359
- #
360
- # # (load) is effectively a terminal node, and so it does
361
- # # not need an explicit handler, as the following is the
362
- # # default behavior. Essentially, for any nodes that don't
363
- # # have a defined handler, the node remains unchanged.
364
- # def on_load(node)
365
- # nil
366
- # end
367
- #
368
- # def on_each(node)
369
- # node.updated(nil, process_all(node))
370
- # end
371
- # end
372
- #
373
- # Let's test our ArithmeticsProcessor:
374
- #
375
- # include AST::Sexp
376
- # expr = s(:add, s(:integer, 2), s(:integer, 2))
377
- #
378
- # p ArithmeticsProcessor.new.process(expr) == expr # => true
379
- #
380
- # As expected, it does not change anything at all. This isn't
381
- # actually very useful, so let's now define a Calculator, which
382
- # will compute the expression values:
383
- #
384
- # # This Processor folds nonterminal nodes and returns an
385
- # # (integer) terminal node.
386
- # class ArithmeticsCalculator < ArithmeticsProcessor
387
- # def compute_op(node)
388
- # # First, node children are processed and then unpacked
389
- # # to local variables.
390
- # nodes = process_all(node)
391
- #
392
- # if nodes.all? { |node| node.type == :integer }
393
- # # If each of those nodes represents a literal, we can
394
- # # fold this node!
395
- # values = nodes.map { |node| node.children.first }
396
- # AST::Node.new(:integer, [
397
- # yield(values)
398
- # ])
399
- # else
400
- # # Otherwise, we can just leave the current node in the
401
- # # tree and only update it with processed children
402
- # # nodes, which can be partially folded.
403
- # node.updated(nil, nodes)
404
- # end
405
- # end
406
- #
407
- # def on_add(node)
408
- # compute_op(node) { |left, right| left + right }
409
- # end
410
- #
411
- # def on_multiply(node)
412
- # compute_op(node) { |left, right| left * right }
413
- # end
414
- # end
415
- #
416
- # Let's check:
417
- #
418
- # p ArithmeticsCalculator.new.process(expr) # => (integer 4)
419
- #
420
- # Excellent, the calculator works! Now, a careful reader could
421
- # notice that the ArithmeticsCalculator does not know how to
422
- # divide numbers. What if we pass an expression with division to
423
- # it?
424
- #
425
- # expr_with_division = \
426
- # s(:add,
427
- # s(:integer, 1),
428
- # s(:divide,
429
- # s(:add, s(:integer, 8), s(:integer, 4)),
430
- # s(:integer, 3))) # 1 + (8 + 4) / 3
431
- #
432
- # folded_expr_with_division = ArithmeticsCalculator.new.process(expr_with_division)
433
- # p folded_expr_with_division
434
- # # => (add
435
- # # (integer 1)
436
- # # (divide
437
- # # (integer 12)
438
- # # (integer 3)))
439
- #
440
- # As you can see, the expression was folded _partially_: the inner
441
- # `(add)` node which could be computed was folded to
442
- # `(integer 12)`, the `(divide)` node is left as-is because there
443
- # is no computing handler for it, and the root `(add)` node was
444
- # also left as it is because some of its children were not
445
- # literals.
446
- #
447
- # Note that this partial folding is only possible because the
448
- # _data_ format, i.e. the format in which the computed values of
449
- # the nodes are represented, is the same as the AST itself.
450
- #
451
- # Let's extend our ArithmeticsCalculator class further.
452
- #
453
- # class ArithmeticsCalculator
454
- # def on_divide(node)
455
- # compute_op(node) { |left, right| left / right }
456
- # end
457
- #
458
- # def on_negate(node)
459
- # # Note how #compute_op works regardless of the operator
460
- # # arity.
461
- # compute_op(node) { |value| -value }
462
- # end
463
- # end
464
- #
465
- # Now, let's apply our renewed ArithmeticsCalculator to a partial
466
- # result of previous evaluation:
467
- #
468
- # p ArithmeticsCalculator.new.process(expr_with_division) # => (integer 5)
469
- #
470
- # Five! Excellent. This is also pretty much how CRuby 1.8 executed
471
- # its programs.
472
- #
473
- # Now, let's do some automated bug searching. Division by zero is
474
- # an error, right? So if we could detect that someone has divided
475
- # by zero before the program is even run, that could save some
476
- # debugging time.
477
- #
478
- # class DivisionByZeroVerifier < ArithmeticsProcessor
479
- # class VerificationFailure < Exception; end
480
- #
481
- # def on_divide(node)
482
- # # You need to process the children to handle nested divisions
483
- # # such as:
484
- # # (divide
485
- # # (integer 1)
486
- # # (divide (integer 1) (integer 0))
487
- # left, right = process_all(node)
488
- #
489
- # if right.type == :integer &&
490
- # right.children.first == 0
491
- # raise VerificationFailure, "Ouch! This code divides by zero."
492
- # end
493
- # end
494
- #
495
- # def divides_by_zero?(ast)
496
- # process(ast)
497
- # false
498
- # rescue VerificationFailure
499
- # true
500
- # end
501
- # end
502
- #
503
- # nice_expr = \
504
- # s(:divide,
505
- # s(:add, s(:integer, 10), s(:integer, 2)),
506
- # s(:integer, 4))
507
- #
508
- # p DivisionByZeroVerifier.new.divides_by_zero?(nice_expr)
509
- # # => false. Good.
510
- #
511
- # bad_expr = \
512
- # s(:add, s(:integer, 10),
513
- # s(:divide, s(:integer, 1), s(:integer, 0)))
514
- #
515
- # p DivisionByZeroVerifier.new.divides_by_zero?(bad_expr)
516
- # # => true. WHOOPS. DO NOT RUN THIS.
517
- #
518
- # Of course, this won't detect more complex cases... unless you
519
- # use some partial evaluation before! The possibilites are
520
- # endless. Have fun.
521
- #
522
- # source://ast//lib/ast/processor/mixin.rb#240
523
- module AST::Processor::Mixin
524
- # Default handler. Does nothing.
525
- #
526
- # @param node [AST::Node]
527
- # @return [AST::Node, nil]
528
- #
529
- # source://ast//lib/ast/processor/mixin.rb#284
530
- def handler_missing(node); end
531
-
532
- # Dispatches `node`. If a node has type `:foo`, then a handler
533
- # named `on_foo` is invoked with one argument, the `node`; if
534
- # there isn't such a handler, {#handler_missing} is invoked
535
- # with the same argument.
536
- #
537
- # If the handler returns `nil`, `node` is returned; otherwise,
538
- # the return value of the handler is passed along.
539
- #
540
- # @param node [AST::Node, nil]
541
- # @return [AST::Node, nil]
542
- #
543
- # source://ast//lib/ast/processor/mixin.rb#251
544
- def process(node); end
545
-
546
- # {#process}es each node from `nodes` and returns an array of
547
- # results.
548
- #
549
- # @param nodes [Array<AST::Node>]
550
- # @return [Array<AST::Node>]
551
- #
552
- # source://ast//lib/ast/processor/mixin.rb#274
553
- def process_all(nodes); end
554
- end
555
-
556
- # This simple module is very useful in the cases where one needs
557
- # to define deeply nested ASTs from Ruby code, for example, in
558
- # tests. It should be used like this:
559
- #
560
- # describe YourLanguage::AST do
561
- # include Sexp
562
- #
563
- # it "should correctly parse expressions" do
564
- # YourLanguage.parse("1 + 2 * 3").should ==
565
- # s(:add,
566
- # s(:integer, 1),
567
- # s(:multiply,
568
- # s(:integer, 2),
569
- # s(:integer, 3)))
570
- # end
571
- # end
572
- #
573
- # This way the amount of boilerplate code is greatly reduced.
574
- #
575
- # source://ast//lib/ast/sexp.rb#20
576
- module AST::Sexp
577
- # Creates a {Node} with type `type` and children `children`.
578
- # Note that the resulting node is of the type AST::Node and not a
579
- # subclass.
580
- # This would not pose a problem with comparisons, as {Node#==}
581
- # ignores metadata.
582
- #
583
- # source://ast//lib/ast/sexp.rb#26
584
- def s(type, *children); end
585
- end