omg-railties 8.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (351) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +171 -0
  3. data/MIT-LICENSE +20 -0
  4. data/RDOC_MAIN.md +99 -0
  5. data/README.rdoc +39 -0
  6. data/exe/rails +10 -0
  7. data/lib/minitest/rails_plugin.rb +140 -0
  8. data/lib/rails/all.rb +21 -0
  9. data/lib/rails/api/generator.rb +38 -0
  10. data/lib/rails/api/task.rb +235 -0
  11. data/lib/rails/app_loader.rb +77 -0
  12. data/lib/rails/application/bootstrap.rb +118 -0
  13. data/lib/rails/application/configuration.rb +659 -0
  14. data/lib/rails/application/default_middleware_stack.rb +140 -0
  15. data/lib/rails/application/dummy_config.rb +19 -0
  16. data/lib/rails/application/finisher.rb +238 -0
  17. data/lib/rails/application/routes_reloader.rb +79 -0
  18. data/lib/rails/application.rb +658 -0
  19. data/lib/rails/application_controller.rb +28 -0
  20. data/lib/rails/autoloaders/inflector.rb +21 -0
  21. data/lib/rails/autoloaders.rb +48 -0
  22. data/lib/rails/backtrace_cleaner.rb +42 -0
  23. data/lib/rails/cli.rb +21 -0
  24. data/lib/rails/code_statistics.rb +159 -0
  25. data/lib/rails/code_statistics_calculator.rb +99 -0
  26. data/lib/rails/command/actions.rb +52 -0
  27. data/lib/rails/command/base.rb +185 -0
  28. data/lib/rails/command/behavior.rb +84 -0
  29. data/lib/rails/command/environment_argument.rb +56 -0
  30. data/lib/rails/command/helpers/editor.rb +40 -0
  31. data/lib/rails/command.rb +172 -0
  32. data/lib/rails/commands/about/about_command.rb +14 -0
  33. data/lib/rails/commands/app/update_command.rb +94 -0
  34. data/lib/rails/commands/application/application_command.rb +33 -0
  35. data/lib/rails/commands/boot/boot_command.rb +14 -0
  36. data/lib/rails/commands/console/console_command.rb +91 -0
  37. data/lib/rails/commands/console/irb_console.rb +136 -0
  38. data/lib/rails/commands/credentials/USAGE +73 -0
  39. data/lib/rails/commands/credentials/credentials_command/diffing.rb +53 -0
  40. data/lib/rails/commands/credentials/credentials_command.rb +139 -0
  41. data/lib/rails/commands/db/system/change/change_command.rb +26 -0
  42. data/lib/rails/commands/dbconsole/dbconsole_command.rb +88 -0
  43. data/lib/rails/commands/destroy/destroy_command.rb +29 -0
  44. data/lib/rails/commands/dev/dev_command.rb +14 -0
  45. data/lib/rails/commands/devcontainer/devcontainer_command.rb +39 -0
  46. data/lib/rails/commands/encrypted/USAGE +23 -0
  47. data/lib/rails/commands/encrypted/encrypted_command.rb +98 -0
  48. data/lib/rails/commands/gem_help/USAGE +16 -0
  49. data/lib/rails/commands/gem_help/gem_help_command.rb +13 -0
  50. data/lib/rails/commands/generate/generate_command.rb +30 -0
  51. data/lib/rails/commands/help/USAGE +17 -0
  52. data/lib/rails/commands/help/help_command.rb +34 -0
  53. data/lib/rails/commands/initializers/initializers_command.rb +20 -0
  54. data/lib/rails/commands/middleware/middleware_command.rb +17 -0
  55. data/lib/rails/commands/new/new_command.rb +21 -0
  56. data/lib/rails/commands/notes/notes_command.rb +30 -0
  57. data/lib/rails/commands/plugin/plugin_command.rb +47 -0
  58. data/lib/rails/commands/rake/rake_command.rb +55 -0
  59. data/lib/rails/commands/restart/restart_command.rb +14 -0
  60. data/lib/rails/commands/routes/routes_command.rb +49 -0
  61. data/lib/rails/commands/runner/USAGE +22 -0
  62. data/lib/rails/commands/runner/runner_command.rb +81 -0
  63. data/lib/rails/commands/secret/secret_command.rb +13 -0
  64. data/lib/rails/commands/server/server_command.rb +290 -0
  65. data/lib/rails/commands/stats/stats_command.rb +19 -0
  66. data/lib/rails/commands/test/USAGE +14 -0
  67. data/lib/rails/commands/test/test_command.rb +81 -0
  68. data/lib/rails/commands/unused_routes/unused_routes_command.rb +75 -0
  69. data/lib/rails/commands/version/version_command.rb +12 -0
  70. data/lib/rails/commands.rb +18 -0
  71. data/lib/rails/configuration.rb +170 -0
  72. data/lib/rails/console/app.rb +8 -0
  73. data/lib/rails/console/helpers.rb +8 -0
  74. data/lib/rails/console/methods.rb +23 -0
  75. data/lib/rails/deprecator.rb +7 -0
  76. data/lib/rails/dev_caching.rb +44 -0
  77. data/lib/rails/engine/commands.rb +9 -0
  78. data/lib/rails/engine/configuration.rb +138 -0
  79. data/lib/rails/engine/lazy_route_set.rb +109 -0
  80. data/lib/rails/engine/railties.rb +23 -0
  81. data/lib/rails/engine/updater.rb +21 -0
  82. data/lib/rails/engine.rb +760 -0
  83. data/lib/rails/gem_version.rb +17 -0
  84. data/lib/rails/generators/actions/create_migration.rb +75 -0
  85. data/lib/rails/generators/actions.rb +528 -0
  86. data/lib/rails/generators/active_model.rb +94 -0
  87. data/lib/rails/generators/app_base.rb +806 -0
  88. data/lib/rails/generators/app_name.rb +39 -0
  89. data/lib/rails/generators/base.rb +432 -0
  90. data/lib/rails/generators/database.rb +287 -0
  91. data/lib/rails/generators/erb/authentication/authentication_generator.rb +15 -0
  92. data/lib/rails/generators/erb/authentication/templates/views/passwords/edit.html.erb +9 -0
  93. data/lib/rails/generators/erb/authentication/templates/views/passwords/new.html.erb +8 -0
  94. data/lib/rails/generators/erb/authentication/templates/views/sessions/new.html.erb +11 -0
  95. data/lib/rails/generators/erb/controller/controller_generator.rb +24 -0
  96. data/lib/rails/generators/erb/controller/templates/view.html.erb.tt +2 -0
  97. data/lib/rails/generators/erb/mailer/mailer_generator.rb +41 -0
  98. data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +13 -0
  99. data/lib/rails/generators/erb/mailer/templates/layout.text.erb.tt +1 -0
  100. data/lib/rails/generators/erb/mailer/templates/view.html.erb.tt +5 -0
  101. data/lib/rails/generators/erb/mailer/templates/view.text.erb.tt +3 -0
  102. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +34 -0
  103. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +37 -0
  104. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +12 -0
  105. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +16 -0
  106. data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +11 -0
  107. data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +17 -0
  108. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +10 -0
  109. data/lib/rails/generators/erb.rb +26 -0
  110. data/lib/rails/generators/generated_attribute.rb +274 -0
  111. data/lib/rails/generators/migration.rb +71 -0
  112. data/lib/rails/generators/model_helpers.rb +62 -0
  113. data/lib/rails/generators/named_base.rb +227 -0
  114. data/lib/rails/generators/rails/app/USAGE +31 -0
  115. data/lib/rails/generators/rails/app/app_generator.rb +678 -0
  116. data/lib/rails/generators/rails/app/templates/Dockerfile.tt +119 -0
  117. data/lib/rails/generators/rails/app/templates/Gemfile.tt +83 -0
  118. data/lib/rails/generators/rails/app/templates/README.md.tt +24 -0
  119. data/lib/rails/generators/rails/app/templates/Rakefile.tt +6 -0
  120. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +15 -0
  121. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +6 -0
  122. data/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb.tt +2 -0
  123. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +7 -0
  124. data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +4 -0
  125. data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +3 -0
  126. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +33 -0
  127. data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +13 -0
  128. data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.text.erb.tt +1 -0
  129. data/lib/rails/generators/rails/app/templates/app/views/pwa/manifest.json.erb.tt +22 -0
  130. data/lib/rails/generators/rails/app/templates/app/views/pwa/service-worker.js +26 -0
  131. data/lib/rails/generators/rails/app/templates/bin/brakeman.tt +6 -0
  132. data/lib/rails/generators/rails/app/templates/bin/dev.tt +1 -0
  133. data/lib/rails/generators/rails/app/templates/bin/rails.tt +3 -0
  134. data/lib/rails/generators/rails/app/templates/bin/rake.tt +3 -0
  135. data/lib/rails/generators/rails/app/templates/bin/rubocop.tt +7 -0
  136. data/lib/rails/generators/rails/app/templates/bin/setup.tt +45 -0
  137. data/lib/rails/generators/rails/app/templates/bin/thrust.tt +4 -0
  138. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +42 -0
  139. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +6 -0
  140. data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +10 -0
  141. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +82 -0
  142. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +114 -0
  143. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +72 -0
  144. data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +82 -0
  145. data/lib/rails/generators/rails/app/templates/config/deploy.yml.tt +107 -0
  146. data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +5 -0
  147. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +89 -0
  148. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +125 -0
  149. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +62 -0
  150. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +7 -0
  151. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +25 -0
  152. data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +16 -0
  153. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +8 -0
  154. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +16 -0
  155. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_8_0.rb.tt +25 -0
  156. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +31 -0
  157. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +43 -0
  158. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +16 -0
  159. data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +34 -0
  160. data/lib/rails/generators/rails/app/templates/config.ru.tt +6 -0
  161. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +9 -0
  162. data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +16 -0
  163. data/lib/rails/generators/rails/app/templates/dockerignore.tt +56 -0
  164. data/lib/rails/generators/rails/app/templates/env.erb.tt +5 -0
  165. data/lib/rails/generators/rails/app/templates/gitattributes.tt +9 -0
  166. data/lib/rails/generators/rails/app/templates/github/ci.yml.tt +138 -0
  167. data/lib/rails/generators/rails/app/templates/github/dependabot.yml +12 -0
  168. data/lib/rails/generators/rails/app/templates/gitignore.tt +38 -0
  169. data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
  170. data/lib/rails/generators/rails/app/templates/public/400.html +67 -0
  171. data/lib/rails/generators/rails/app/templates/public/404.html +67 -0
  172. data/lib/rails/generators/rails/app/templates/public/406-unsupported-browser.html +66 -0
  173. data/lib/rails/generators/rails/app/templates/public/422.html +67 -0
  174. data/lib/rails/generators/rails/app/templates/public/500.html +66 -0
  175. data/lib/rails/generators/rails/app/templates/public/icon.png +0 -0
  176. data/lib/rails/generators/rails/app/templates/public/icon.svg +3 -0
  177. data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -0
  178. data/lib/rails/generators/rails/app/templates/rubocop.yml.tt +8 -0
  179. data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -0
  180. data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb.tt +5 -0
  181. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +21 -0
  182. data/lib/rails/generators/rails/application_record/application_record_generator.rb +13 -0
  183. data/lib/rails/generators/rails/authentication/USAGE +6 -0
  184. data/lib/rails/generators/rails/authentication/authentication_generator.rb +54 -0
  185. data/lib/rails/generators/rails/authentication/templates/controllers/concerns/authentication.rb +55 -0
  186. data/lib/rails/generators/rails/authentication/templates/controllers/passwords_controller.rb +33 -0
  187. data/lib/rails/generators/rails/authentication/templates/controllers/sessions_controller.rb +21 -0
  188. data/lib/rails/generators/rails/authentication/templates/mailers/passwords_mailer.rb +6 -0
  189. data/lib/rails/generators/rails/authentication/templates/models/current.rb +4 -0
  190. data/lib/rails/generators/rails/authentication/templates/models/session.rb +3 -0
  191. data/lib/rails/generators/rails/authentication/templates/models/user.rb +6 -0
  192. data/lib/rails/generators/rails/authentication/templates/test/mailers/previews/passwords_mailer_preview.rb +7 -0
  193. data/lib/rails/generators/rails/authentication/templates/views/passwords_mailer/reset.html.erb +4 -0
  194. data/lib/rails/generators/rails/authentication/templates/views/passwords_mailer/reset.text.erb +2 -0
  195. data/lib/rails/generators/rails/benchmark/USAGE +19 -0
  196. data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +30 -0
  197. data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
  198. data/lib/rails/generators/rails/controller/USAGE +26 -0
  199. data/lib/rails/generators/rails/controller/controller_generator.rb +42 -0
  200. data/lib/rails/generators/rails/controller/templates/controller.rb.tt +9 -0
  201. data/lib/rails/generators/rails/credentials/credentials_generator.rb +61 -0
  202. data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +12 -0
  203. data/lib/rails/generators/rails/db/system/change/change_generator.rb +206 -0
  204. data/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb +168 -0
  205. data/lib/rails/generators/rails/devcontainer/templates/devcontainer/Dockerfile.tt +3 -0
  206. data/lib/rails/generators/rails/devcontainer/templates/devcontainer/compose.yaml.tt +47 -0
  207. data/lib/rails/generators/rails/devcontainer/templates/devcontainer/devcontainer.json.tt +37 -0
  208. data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +31 -0
  209. data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +57 -0
  210. data/lib/rails/generators/rails/generator/USAGE +13 -0
  211. data/lib/rails/generators/rails/generator/generator_generator.rb +27 -0
  212. data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +3 -0
  213. data/lib/rails/generators/rails/generator/templates/USAGE.tt +8 -0
  214. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  215. data/lib/rails/generators/rails/helper/USAGE +12 -0
  216. data/lib/rails/generators/rails/helper/helper_generator.rb +20 -0
  217. data/lib/rails/generators/rails/helper/templates/helper.rb.tt +4 -0
  218. data/lib/rails/generators/rails/integration_test/USAGE +10 -0
  219. data/lib/rails/generators/rails/integration_test/integration_test_generator.rb +9 -0
  220. data/lib/rails/generators/rails/master_key/master_key_generator.rb +53 -0
  221. data/lib/rails/generators/rails/migration/USAGE +45 -0
  222. data/lib/rails/generators/rails/migration/migration_generator.rb +14 -0
  223. data/lib/rails/generators/rails/model/model_generator.rb +18 -0
  224. data/lib/rails/generators/rails/plugin/USAGE +21 -0
  225. data/lib/rails/generators/rails/plugin/plugin_generator.rb +499 -0
  226. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +28 -0
  227. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +23 -0
  228. data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +20 -0
  229. data/lib/rails/generators/rails/plugin/templates/README.md.tt +28 -0
  230. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +14 -0
  231. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +5 -0
  232. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +5 -0
  233. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +5 -0
  234. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +7 -0
  235. data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +6 -0
  236. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +17 -0
  237. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +15 -0
  238. data/lib/rails/generators/rails/plugin/templates/bin/rubocop.tt +7 -0
  239. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +4 -0
  240. data/lib/rails/generators/rails/plugin/templates/config/routes.rb.tt +6 -0
  241. data/lib/rails/generators/rails/plugin/templates/github/ci.yml.tt +103 -0
  242. data/lib/rails/generators/rails/plugin/templates/github/dependabot.yml +12 -0
  243. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +14 -0
  244. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +7 -0
  245. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +5 -0
  246. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -0
  247. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +8 -0
  248. data/lib/rails/generators/rails/plugin/templates/lib/tasks/%namespaced_name%_tasks.rake.tt +4 -0
  249. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +5 -0
  250. data/lib/rails/generators/rails/plugin/templates/rails/routes.rb.tt +3 -0
  251. data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +15 -0
  252. data/lib/rails/generators/rails/plugin/templates/rubocop.yml.tt +8 -0
  253. data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +7 -0
  254. data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb.tt +5 -0
  255. data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +7 -0
  256. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +21 -0
  257. data/lib/rails/generators/rails/resource/USAGE +23 -0
  258. data/lib/rails/generators/rails/resource/resource_generator.rb +27 -0
  259. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +23 -0
  260. data/lib/rails/generators/rails/scaffold/USAGE +41 -0
  261. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +18 -0
  262. data/lib/rails/generators/rails/scaffold_controller/USAGE +19 -0
  263. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +56 -0
  264. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +57 -0
  265. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +64 -0
  266. data/lib/rails/generators/rails/script/USAGE +18 -0
  267. data/lib/rails/generators/rails/script/script_generator.rb +18 -0
  268. data/lib/rails/generators/rails/script/templates/script.rb.tt +3 -0
  269. data/lib/rails/generators/rails/system_test/USAGE +10 -0
  270. data/lib/rails/generators/rails/system_test/system_test_generator.rb +9 -0
  271. data/lib/rails/generators/rails/task/USAGE +9 -0
  272. data/lib/rails/generators/rails/task/task_generator.rb +13 -0
  273. data/lib/rails/generators/rails/task/templates/task.rb.tt +8 -0
  274. data/lib/rails/generators/resource_helpers.rb +82 -0
  275. data/lib/rails/generators/test_case.rb +37 -0
  276. data/lib/rails/generators/test_unit/controller/controller_generator.rb +19 -0
  277. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +23 -0
  278. data/lib/rails/generators/test_unit/generator/generator_generator.rb +27 -0
  279. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +16 -0
  280. data/lib/rails/generators/test_unit/helper/helper_generator.rb +11 -0
  281. data/lib/rails/generators/test_unit/integration/integration_generator.rb +20 -0
  282. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +9 -0
  283. data/lib/rails/generators/test_unit/job/job_generator.rb +20 -0
  284. data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +9 -0
  285. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +28 -0
  286. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +23 -0
  287. data/lib/rails/generators/test_unit/mailer/templates/preview.rb.tt +14 -0
  288. data/lib/rails/generators/test_unit/model/model_generator.rb +37 -0
  289. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +29 -0
  290. data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +9 -0
  291. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +15 -0
  292. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +7 -0
  293. data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -0
  294. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +82 -0
  295. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +44 -0
  296. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +54 -0
  297. data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +57 -0
  298. data/lib/rails/generators/test_unit/system/system_generator.rb +24 -0
  299. data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb.tt +5 -0
  300. data/lib/rails/generators/test_unit/system/templates/system_test.rb.tt +9 -0
  301. data/lib/rails/generators/test_unit.rb +10 -0
  302. data/lib/rails/generators/testing/assertions.rb +147 -0
  303. data/lib/rails/generators/testing/behavior.rb +116 -0
  304. data/lib/rails/generators/testing/setup_and_teardown.rb +20 -0
  305. data/lib/rails/generators.rb +327 -0
  306. data/lib/rails/health_controller.rb +55 -0
  307. data/lib/rails/info.rb +105 -0
  308. data/lib/rails/info_controller.rb +71 -0
  309. data/lib/rails/initializable.rb +95 -0
  310. data/lib/rails/mailers_controller.rb +122 -0
  311. data/lib/rails/paths.rb +246 -0
  312. data/lib/rails/plugin/test.rb +9 -0
  313. data/lib/rails/pwa_controller.rb +15 -0
  314. data/lib/rails/rack/logger.rb +88 -0
  315. data/lib/rails/rack/silence_request.rb +33 -0
  316. data/lib/rails/rack.rb +8 -0
  317. data/lib/rails/rackup/server.rb +15 -0
  318. data/lib/rails/railtie/configurable.rb +36 -0
  319. data/lib/rails/railtie/configuration.rb +114 -0
  320. data/lib/rails/railtie.rb +302 -0
  321. data/lib/rails/source_annotation_extractor.rb +214 -0
  322. data/lib/rails/tasks/engine.rake +85 -0
  323. data/lib/rails/tasks/framework.rake +34 -0
  324. data/lib/rails/tasks/log.rake +41 -0
  325. data/lib/rails/tasks/misc.rake +68 -0
  326. data/lib/rails/tasks/statistics.rake +23 -0
  327. data/lib/rails/tasks/tmp.rake +51 -0
  328. data/lib/rails/tasks/yarn.rake +29 -0
  329. data/lib/rails/tasks/zeitwerk.rake +41 -0
  330. data/lib/rails/tasks.rb +17 -0
  331. data/lib/rails/templates/layouts/application.html.erb +51 -0
  332. data/lib/rails/templates/rails/info/notes.html.erb +65 -0
  333. data/lib/rails/templates/rails/info/properties.html.erb +1 -0
  334. data/lib/rails/templates/rails/info/routes.html.erb +9 -0
  335. data/lib/rails/templates/rails/mailers/email.html.erb +201 -0
  336. data/lib/rails/templates/rails/mailers/index.html.erb +15 -0
  337. data/lib/rails/templates/rails/mailers/mailer.html.erb +12 -0
  338. data/lib/rails/templates/rails/welcome/index.html.erb +93 -0
  339. data/lib/rails/test_help.rb +47 -0
  340. data/lib/rails/test_unit/line_filtering.rb +13 -0
  341. data/lib/rails/test_unit/railtie.rb +25 -0
  342. data/lib/rails/test_unit/reporter.rb +121 -0
  343. data/lib/rails/test_unit/runner.rb +209 -0
  344. data/lib/rails/test_unit/test_parser.rb +133 -0
  345. data/lib/rails/test_unit/testing.rake +39 -0
  346. data/lib/rails/testing/maintain_test_schema.rb +16 -0
  347. data/lib/rails/version.rb +10 -0
  348. data/lib/rails/welcome_controller.rb +11 -0
  349. data/lib/rails/zeitwerk_checker.rb +15 -0
  350. data/lib/rails.rb +130 -0
  351. metadata +518 -0
@@ -0,0 +1,302 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/initializable"
4
+ require "active_support/descendants_tracker"
5
+ require "active_support/inflector"
6
+ require "active_support/core_ext/module/introspection"
7
+ require "active_support/core_ext/module/delegation"
8
+
9
+ module Rails
10
+ # +Rails::Railtie+ is the core of the \Rails framework and provides
11
+ # several hooks to extend \Rails and/or modify the initialization process.
12
+ #
13
+ # Every major component of \Rails (Action Mailer, Action Controller, Active
14
+ # Record, etc.) implements a railtie. Each of them is responsible for their
15
+ # own initialization. This makes \Rails itself absent of any component hooks,
16
+ # allowing other components to be used in place of any of the \Rails defaults.
17
+ #
18
+ # Developing a \Rails extension does _not_ require implementing a railtie, but
19
+ # if you need to interact with the \Rails framework during or after boot, then
20
+ # a railtie is needed.
21
+ #
22
+ # For example, an extension doing any of the following would need a railtie:
23
+ #
24
+ # * creating initializers
25
+ # * configuring a \Rails framework for the application, like setting a generator
26
+ # * adding <tt>config.*</tt> keys to the environment
27
+ # * setting up a subscriber with ActiveSupport::Notifications
28
+ # * adding Rake tasks
29
+ #
30
+ # == Creating a Railtie
31
+ #
32
+ # To extend \Rails using a railtie, create a subclass of +Rails::Railtie+.
33
+ # This class must be loaded during the \Rails boot process, and is conventionally
34
+ # called +MyNamespace::Railtie+.
35
+ #
36
+ # The following example demonstrates an extension which can be used with or
37
+ # without \Rails.
38
+ #
39
+ # # lib/my_gem/railtie.rb
40
+ # module MyGem
41
+ # class Railtie < Rails::Railtie
42
+ # end
43
+ # end
44
+ #
45
+ # # lib/my_gem.rb
46
+ # require "my_gem/railtie" if defined?(Rails::Railtie)
47
+ #
48
+ # == Initializers
49
+ #
50
+ # To add an initialization step to the \Rails boot process from your railtie, just
51
+ # define the initialization code with the +initializer+ macro:
52
+ #
53
+ # class MyGem::Railtie < Rails::Railtie
54
+ # initializer "my_gem.configure_rails_initialization" do
55
+ # # some initialization behavior
56
+ # end
57
+ # end
58
+ #
59
+ # If specified, the block can also receive the application object, in case you
60
+ # need to access some application-specific configuration, like middleware:
61
+ #
62
+ # class MyGem::Railtie < Rails::Railtie
63
+ # initializer "my_gem.configure_rails_initialization" do |app|
64
+ # app.middleware.use MyGem::Middleware
65
+ # end
66
+ # end
67
+ #
68
+ # Finally, you can also pass <tt>:before</tt> and <tt>:after</tt> as options to
69
+ # +initializer+, in case you want to couple it with a specific step in the
70
+ # initialization process.
71
+ #
72
+ # == Configuration
73
+ #
74
+ # Railties can access a config object which contains configuration shared by all
75
+ # railties and the application:
76
+ #
77
+ # class MyGem::Railtie < Rails::Railtie
78
+ # # Customize the ORM
79
+ # config.app_generators.orm :my_gem_orm
80
+ #
81
+ # # Add a to_prepare block which is executed once in production
82
+ # # and before each request in development.
83
+ # config.to_prepare do
84
+ # MyGem.setup!
85
+ # end
86
+ # end
87
+ #
88
+ # == Loading Rake Tasks and Generators
89
+ #
90
+ # If your railtie has Rake tasks, you can tell \Rails to load them through the method
91
+ # +rake_tasks+:
92
+ #
93
+ # class MyGem::Railtie < Rails::Railtie
94
+ # rake_tasks do
95
+ # load "path/to/my_gem.tasks"
96
+ # end
97
+ # end
98
+ #
99
+ # By default, \Rails loads generators from your load path. However, if you want to place
100
+ # your generators at a different location, you can specify in your railtie a block which
101
+ # will load them during normal generators lookup:
102
+ #
103
+ # class MyGem::Railtie < Rails::Railtie
104
+ # generators do
105
+ # require "path/to/my_gem_generator"
106
+ # end
107
+ # end
108
+ #
109
+ # Since filenames on the load path are shared across gems, be sure that files you load
110
+ # through a railtie have unique names.
111
+ #
112
+ # == Run another program when the \Rails server starts
113
+ #
114
+ # In development, it's very usual to have to run another process next to the \Rails Server. In example
115
+ # you might want to start the Webpack or React server. Or maybe you need to run your job scheduler process
116
+ # like Sidekiq. This is usually done by opening a new shell and running the program from here.
117
+ #
118
+ # \Rails allow you to specify a +server+ block which will get called when a \Rails server starts.
119
+ # This way, your users don't need to remember to have to open a new shell and run another program, making
120
+ # this less confusing for everyone.
121
+ # It can be used like this:
122
+ #
123
+ # class MyGem::Railtie < Rails::Railtie
124
+ # server do
125
+ # WebpackServer.start
126
+ # end
127
+ # end
128
+ #
129
+ # == Application and Engine
130
+ #
131
+ # An engine is nothing more than a railtie with some initializers already set. And since
132
+ # Rails::Application is an engine, the same configuration described here can be
133
+ # used in both.
134
+ #
135
+ # Be sure to look at the documentation of those specific classes for more information.
136
+ class Railtie
137
+ autoload :Configuration, "rails/railtie/configuration"
138
+
139
+ extend ActiveSupport::DescendantsTracker
140
+ include Initializable
141
+
142
+ ABSTRACT_RAILTIES = %w(Rails::Railtie Rails::Engine Rails::Application)
143
+
144
+ class << self
145
+ private :new
146
+ delegate :config, to: :instance
147
+
148
+ def subclasses
149
+ super.reject(&:abstract_railtie?).sort
150
+ end
151
+
152
+ def rake_tasks(&blk)
153
+ register_block_for(:rake_tasks, &blk)
154
+ end
155
+
156
+ def console(&blk)
157
+ register_block_for(:load_console, &blk)
158
+ end
159
+
160
+ def runner(&blk)
161
+ register_block_for(:runner, &blk)
162
+ end
163
+
164
+ def generators(&blk)
165
+ register_block_for(:generators, &blk)
166
+ end
167
+
168
+ def server(&blk)
169
+ register_block_for(:server, &blk)
170
+ end
171
+
172
+ def abstract_railtie?
173
+ ABSTRACT_RAILTIES.include?(name)
174
+ end
175
+
176
+ def railtie_name(name = nil)
177
+ @railtie_name = name.to_s if name
178
+ @railtie_name ||= generate_railtie_name(self.name)
179
+ end
180
+
181
+ # Since Rails::Railtie cannot be instantiated, any methods that call
182
+ # +instance+ are intended to be called only on subclasses of a Railtie.
183
+ def instance
184
+ @instance ||= new
185
+ end
186
+
187
+ # Allows you to configure the railtie. This is the same method seen in
188
+ # Railtie::Configurable, but this module is no longer required for all
189
+ # subclasses of Railtie so we provide the class method here.
190
+ def configure(&block)
191
+ instance.configure(&block)
192
+ end
193
+
194
+ def <=>(other) # :nodoc:
195
+ load_index <=> other.load_index
196
+ end
197
+
198
+ def inherited(subclass)
199
+ subclass.increment_load_index
200
+ super
201
+ end
202
+
203
+ protected
204
+ attr_reader :load_index
205
+
206
+ def increment_load_index
207
+ @@load_counter ||= 0
208
+ @load_index = (@@load_counter += 1)
209
+ end
210
+
211
+ private
212
+ def generate_railtie_name(string)
213
+ ActiveSupport::Inflector.underscore(string).tr("/", "_")
214
+ end
215
+
216
+ def respond_to_missing?(name, _)
217
+ return super if abstract_railtie?
218
+
219
+ instance.respond_to?(name) || super
220
+ end
221
+
222
+ # If the class method does not have a method, then send the method call
223
+ # to the Railtie instance.
224
+ def method_missing(name, ...)
225
+ if !abstract_railtie? && instance.respond_to?(name)
226
+ instance.public_send(name, ...)
227
+ else
228
+ super
229
+ end
230
+ end
231
+
232
+ # receives an instance variable identifier, set the variable value if is
233
+ # blank and append given block to value, which will be used later in
234
+ # `#each_registered_block(type, &block)`
235
+ def register_block_for(type, &blk)
236
+ var_name = "@#{type}"
237
+ blocks = instance_variable_defined?(var_name) ? instance_variable_get(var_name) : instance_variable_set(var_name, [])
238
+ blocks << blk if blk
239
+ blocks
240
+ end
241
+ end
242
+
243
+ delegate :railtie_name, to: :class
244
+
245
+ def initialize # :nodoc:
246
+ if self.class.abstract_railtie?
247
+ raise "#{self.class.name} is abstract, you cannot instantiate it directly."
248
+ end
249
+ end
250
+
251
+ def inspect # :nodoc:
252
+ "#<#{self.class.name}>"
253
+ end
254
+
255
+ def configure(&block) # :nodoc:
256
+ instance_eval(&block)
257
+ end
258
+
259
+ # This is used to create the <tt>config</tt> object on Railties, an instance of
260
+ # Railtie::Configuration, that is used by Railties and Application to store
261
+ # related configuration.
262
+ def config
263
+ @config ||= Railtie::Configuration.new
264
+ end
265
+
266
+ def railtie_namespace # :nodoc:
267
+ @railtie_namespace ||= self.class.module_parents.detect { |n| n.respond_to?(:railtie_namespace) }
268
+ end
269
+
270
+ protected
271
+ def run_console_blocks(app) # :nodoc:
272
+ each_registered_block(:console) { |block| block.call(app) }
273
+ end
274
+
275
+ def run_generators_blocks(app) # :nodoc:
276
+ each_registered_block(:generators) { |block| block.call(app) }
277
+ end
278
+
279
+ def run_runner_blocks(app) # :nodoc:
280
+ each_registered_block(:runner) { |block| block.call(app) }
281
+ end
282
+
283
+ def run_tasks_blocks(app) # :nodoc:
284
+ extend Rake::DSL
285
+ each_registered_block(:rake_tasks) { |block| instance_exec(app, &block) }
286
+ end
287
+
288
+ def run_server_blocks(app) # :nodoc:
289
+ each_registered_block(:server) { |block| block.call(app) }
290
+ end
291
+
292
+ private
293
+ # run `&block` in every registered block in `#register_block_for`
294
+ def each_registered_block(type, &block)
295
+ klass = self.class
296
+ while klass.respond_to?(type)
297
+ klass.public_send(type).each(&block)
298
+ klass = klass.superclass
299
+ end
300
+ end
301
+ end
302
+ end
@@ -0,0 +1,214 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "prism"
5
+ rescue LoadError
6
+ # If Prism isn't available (because of using an older Ruby version) then we'll
7
+ # define a fallback for the ParserExtractor using ripper.
8
+ require "ripper"
9
+ end
10
+
11
+ module Rails
12
+ # Implements the logic behind +Rails::Command::NotesCommand+. See <tt>rails notes --help</tt> for usage information.
13
+ #
14
+ # Annotation objects are triplets <tt>:line</tt>, <tt>:tag</tt>, <tt>:text</tt> that
15
+ # represent the line where the annotation lives, its tag, and its text. Note
16
+ # the filename is not stored.
17
+ #
18
+ # Annotations are looked for in comments and modulus whitespace they have to
19
+ # start with the tag optionally followed by a colon. Everything up to the end
20
+ # of the line (or closing ERB comment tag) is considered to be their text.
21
+ class SourceAnnotationExtractor
22
+ # Wraps a regular expression that will be tested against each of the source
23
+ # file's comments.
24
+ class ParserExtractor < Struct.new(:pattern)
25
+ if defined?(Prism)
26
+ def annotations(file)
27
+ result = Prism.parse_file(file)
28
+ return [] unless result.success?
29
+
30
+ result.comments.filter_map do |comment|
31
+ Annotation.new(comment.location.start_line, $1, $2) if comment.location.slice =~ pattern
32
+ end
33
+ end
34
+ else
35
+ class Parser < Ripper
36
+ attr_reader :comments, :pattern
37
+
38
+ def initialize(source, pattern:)
39
+ super(source)
40
+ @pattern = pattern
41
+ @comments = []
42
+ end
43
+
44
+ def on_comment(value)
45
+ @comments << Annotation.new(lineno, $1, $2) if value =~ pattern
46
+ end
47
+ end
48
+
49
+ def annotations(file)
50
+ contents = File.read(file, encoding: Encoding::BINARY)
51
+ parser = Parser.new(contents, pattern: pattern).tap(&:parse)
52
+ parser.error? ? [] : parser.comments
53
+ end
54
+ end
55
+ end
56
+
57
+ # Wraps a regular expression that will iterate through a file's lines and
58
+ # test each one for the given pattern.
59
+ class PatternExtractor < Struct.new(:pattern)
60
+ def annotations(file)
61
+ lineno = 0
62
+
63
+ File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
64
+ lineno += 1
65
+ next list unless line =~ pattern
66
+ list << Annotation.new(lineno, $1, $2)
67
+ end
68
+ end
69
+ end
70
+
71
+ class Annotation < Struct.new(:line, :tag, :text)
72
+ def self.directories
73
+ @@directories ||= %w(app config db lib test)
74
+ end
75
+
76
+ # Registers additional directories to be included
77
+ # Rails::SourceAnnotationExtractor::Annotation.register_directories("spec", "another")
78
+ def self.register_directories(*dirs)
79
+ directories.push(*dirs)
80
+ end
81
+
82
+ def self.tags
83
+ @@tags ||= %w(OPTIMIZE FIXME TODO)
84
+ end
85
+
86
+ # Registers additional tags
87
+ # Rails::SourceAnnotationExtractor::Annotation.register_tags("TESTME", "DEPRECATEME")
88
+ def self.register_tags(*additional_tags)
89
+ tags.push(*additional_tags)
90
+ end
91
+
92
+ def self.extensions
93
+ @@extensions ||= {}
94
+ end
95
+
96
+ # Registers new Annotations File Extensions
97
+ # Rails::SourceAnnotationExtractor::Annotation.register_extensions("css", "scss", "sass", "less", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
98
+ def self.register_extensions(*exts, &block)
99
+ extensions[/\.(#{exts.join("|")})$/] = block
100
+ end
101
+
102
+ register_extensions("builder", "rb", "rake", "ruby") do |tag|
103
+ ParserExtractor.new(/#\s*(#{tag}):?\s*(.*)$/)
104
+ end
105
+
106
+ register_extensions("yml", "yaml") do |tag|
107
+ PatternExtractor.new(/#\s*(#{tag}):?\s*(.*)$/)
108
+ end
109
+
110
+ register_extensions("css", "js") do |tag|
111
+ PatternExtractor.new(/\/\/\s*(#{tag}):?\s*(.*)$/)
112
+ end
113
+
114
+ register_extensions("erb") do |tag|
115
+ PatternExtractor.new(/<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/)
116
+ end
117
+
118
+ # Returns a representation of the annotation that looks like this:
119
+ #
120
+ # [126] [TODO] This algorithm is simple and clearly correct, make it faster.
121
+ #
122
+ # If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
123
+ # Otherwise the string contains just line and text.
124
+ def to_s(options = {})
125
+ s = +"[#{line.to_s.rjust(options[:indent])}] "
126
+ s << "[#{tag}] " if options[:tag]
127
+ s << text
128
+ end
129
+ end
130
+
131
+ # Prints all annotations with tag +tag+ under the root directories +app+,
132
+ # +config+, +db+, +lib+, and +test+ (recursively).
133
+ #
134
+ # If +tag+ is <tt>nil</tt>, annotations with either default or registered tags are printed.
135
+ #
136
+ # Specific directories can be explicitly set using the <tt>:dirs</tt> key in +options+.
137
+ #
138
+ # Rails::SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true
139
+ #
140
+ # If +options+ has a <tt>:tag</tt> flag, it will be passed to each annotation's +to_s+.
141
+ #
142
+ # See SourceAnnotationExtractor#find_in for a list of file extensions that will be taken into account.
143
+ #
144
+ # This class method is the single entry point for the <tt>rails notes</tt> command.
145
+ def self.enumerate(tag = nil, options = {})
146
+ tag ||= Annotation.tags.join("|")
147
+ extractor = new(tag)
148
+ dirs = options.delete(:dirs) || Annotation.directories
149
+ extractor.display(extractor.find(dirs), options)
150
+ end
151
+
152
+ attr_reader :tag
153
+
154
+ def initialize(tag)
155
+ @tag = tag
156
+ end
157
+
158
+ # Returns a hash that maps filenames under +dirs+ (recursively) to arrays
159
+ # with their annotations.
160
+ def find(dirs)
161
+ dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
162
+ end
163
+
164
+ # Returns a hash that maps filenames under +dir+ (recursively) to arrays
165
+ # with their annotations. Files with extensions registered in
166
+ # <tt>Rails::SourceAnnotationExtractor::Annotation.extensions</tt> are
167
+ # taken into account. Only files with annotations are included.
168
+ def find_in(dir)
169
+ results = {}
170
+
171
+ Dir.glob("#{dir}/*") do |item|
172
+ next if File.basename(item).start_with?(".")
173
+
174
+ if File.directory?(item)
175
+ results.update(find_in(item))
176
+ else
177
+ extension = Annotation.extensions.detect do |regexp, _block|
178
+ regexp.match(item)
179
+ end
180
+
181
+ if extension
182
+ pattern = extension.last.call(tag)
183
+
184
+ # In case a user-defined pattern returns nothing for the given set
185
+ # of tags, we exit early.
186
+ next unless pattern
187
+
188
+ # If a user-defined pattern returns a regular expression, we will
189
+ # wrap it in a PatternExtractor to keep the same API.
190
+ pattern = PatternExtractor.new(pattern) if pattern.is_a?(Regexp)
191
+
192
+ annotations = pattern.annotations(item)
193
+ results.update(item => annotations) if annotations.any?
194
+ end
195
+ end
196
+ end
197
+
198
+ results
199
+ end
200
+
201
+ # Prints the mapping from filenames to annotations in +results+ ordered by filename.
202
+ # The +options+ hash is passed to each annotation's +to_s+.
203
+ def display(results, options = {})
204
+ options[:indent] = results.flat_map { |f, a| a.map(&:line) }.max.to_s.size
205
+ results.keys.sort.each do |file|
206
+ puts "#{file}:"
207
+ results[file].each do |note|
208
+ puts " * #{note.to_s(options)}"
209
+ end
210
+ puts
211
+ end
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ task "load_app" do
4
+ namespace :app do
5
+ load APP_RAKEFILE
6
+
7
+ desc "Update some initially generated files"
8
+ task update: [ "update:bin" ]
9
+
10
+ namespace :update do
11
+ require "rails/engine/updater"
12
+ # desc "Adds new executables to the engine bin/ directory"
13
+ task :bin do
14
+ Rails::Engine::Updater.run(:create_bin_files)
15
+ end
16
+ end
17
+ end
18
+ task environment: "app:environment"
19
+
20
+ if !defined?(ENGINE_ROOT) || !ENGINE_ROOT
21
+ ENGINE_ROOT = find_engine_path(Pathname.new(APP_RAKEFILE))
22
+ end
23
+ end
24
+
25
+ def app_task(name)
26
+ task name => [:load_app, "app:db:#{name}"]
27
+ end
28
+
29
+ namespace :db do
30
+ app_task "reset"
31
+
32
+ desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
33
+ app_task "migrate"
34
+ app_task "migrate:up"
35
+ app_task "migrate:down"
36
+ app_task "migrate:redo"
37
+ app_task "migrate:reset"
38
+
39
+ desc "Display status of migrations"
40
+ app_task "migrate:status"
41
+
42
+ desc "Create the database from config/database.yml for the current Rails.env (use db:create:all to create all databases in the config)"
43
+ app_task "create"
44
+ app_task "create:all"
45
+
46
+ desc "Drop the database for the current Rails.env (use db:drop:all to drop all databases)"
47
+ app_task "drop"
48
+ app_task "drop:all"
49
+
50
+ desc "Load fixtures into the current environment's database."
51
+ app_task "fixtures:load"
52
+
53
+ desc "Roll the schema back to the previous version (specify steps w/ STEP=n)."
54
+ app_task "rollback"
55
+
56
+ desc "Create a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`)"
57
+ app_task "schema:dump"
58
+
59
+ desc "Load a schema.rb file into the database"
60
+ app_task "schema:load"
61
+
62
+ desc "Load the seed data from db/seeds.rb"
63
+ app_task "seed"
64
+
65
+ desc "Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the database first)"
66
+ app_task "setup"
67
+
68
+ desc "Retrieve the current schema version number"
69
+ app_task "version"
70
+
71
+ # desc 'Load the test schema'
72
+ app_task "test:prepare"
73
+ end
74
+
75
+ def find_engine_path(path)
76
+ return File.expand_path(Dir.pwd) if path.root?
77
+
78
+ if Rails::Engine.find(path)
79
+ path.to_s
80
+ else
81
+ find_engine_path(path.join(".."))
82
+ end
83
+ end
84
+
85
+ Rake.application.invoke_task(:load_app)
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :app do
4
+ desc "Apply the template supplied by LOCATION=(/path/to/template) or URL"
5
+ task template: :environment do
6
+ template = ENV["LOCATION"]
7
+ raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank?
8
+ require "rails/generators"
9
+ require "rails/generators/rails/app/app_generator"
10
+ Rails::Generators::AppGenerator.apply_rails_template(template, Rails.root)
11
+ end
12
+
13
+ namespace :templates do
14
+ # desc "Copy all the templates from rails to the application directory for customization. Already existing local copies will be overwritten"
15
+ task :copy do
16
+ generators_lib = File.expand_path("../generators", __dir__)
17
+ project_templates = "#{Rails.root}/lib/templates"
18
+
19
+ default_templates = { "erb" => %w{controller mailer scaffold},
20
+ "rails" => %w{controller helper scaffold_controller} }
21
+
22
+ default_templates.each do |type, names|
23
+ local_template_type_dir = File.join(project_templates, type)
24
+ mkdir_p local_template_type_dir, verbose: false
25
+
26
+ names.each do |name|
27
+ dst_name = File.join(local_template_type_dir, name)
28
+ src_name = File.join(generators_lib, type, name, "templates")
29
+ cp_r src_name, dst_name, verbose: false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :log do
4
+ ##
5
+ # Truncates all/specified log files
6
+ # ENV['LOGS']
7
+ # - defaults to all environments log files i.e. 'development,test,production'
8
+ # - ENV['LOGS']=all truncates all files i.e. log/*.log
9
+ # - ENV['LOGS']='test,development' truncates only specified files
10
+ desc "Truncate all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)"
11
+ task :clear do
12
+ log_files.each do |file|
13
+ clear_log_file(file)
14
+ end
15
+ end
16
+
17
+ def log_files
18
+ if ENV["LOGS"] == "all"
19
+ FileList["log/*.log"]
20
+ elsif ENV["LOGS"]
21
+ log_files_to_truncate(ENV["LOGS"])
22
+ else
23
+ log_files_to_truncate(all_environments.join(","))
24
+ end
25
+ end
26
+
27
+ def log_files_to_truncate(envs)
28
+ envs.split(",")
29
+ .map { |file| "log/#{file.strip}.log" }
30
+ .select { |file| File.exist?(file) }
31
+ end
32
+
33
+ def clear_log_file(file)
34
+ f = File.open(file, "w")
35
+ f.close
36
+ end
37
+
38
+ def all_environments
39
+ Dir["config/environments/*.rb"].map { |fname| File.basename(fname, ".*") }
40
+ end
41
+ end