railties 6.1.6 → 7.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +626 -259
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.md +99 -0
  5. data/README.rdoc +5 -6
  6. data/lib/minitest/rails_plugin.rb +64 -1
  7. data/lib/rails/all.rb +0 -1
  8. data/lib/rails/api/task.rb +35 -4
  9. data/lib/rails/app_updater.rb +9 -6
  10. data/lib/rails/application/bootstrap.rb +41 -7
  11. data/lib/rails/application/configuration.rb +262 -88
  12. data/lib/rails/application/default_middleware_stack.rb +29 -4
  13. data/lib/rails/application/dummy_config.rb +19 -0
  14. data/lib/rails/application/finisher.rb +89 -124
  15. data/lib/rails/application/routes_reloader.rb +8 -0
  16. data/lib/rails/application.rb +200 -125
  17. data/lib/rails/application_controller.rb +3 -3
  18. data/lib/rails/autoloaders/inflector.rb +21 -0
  19. data/lib/rails/autoloaders.rb +42 -42
  20. data/lib/rails/backtrace_cleaner.rb +1 -1
  21. data/lib/rails/cli.rb +5 -2
  22. data/lib/rails/code_statistics.rb +2 -2
  23. data/lib/rails/code_statistics_calculator.rb +10 -1
  24. data/lib/rails/command/actions.rb +10 -12
  25. data/lib/rails/command/base.rb +61 -45
  26. data/lib/rails/command/behavior.rb +1 -1
  27. data/lib/rails/command/environment_argument.rb +33 -17
  28. data/lib/rails/command/helpers/editor.rb +17 -12
  29. data/lib/rails/command.rb +90 -36
  30. data/lib/rails/commands/about/about_command.rb +14 -0
  31. data/lib/rails/commands/application/application_command.rb +2 -0
  32. data/lib/rails/commands/console/console_command.rb +17 -13
  33. data/lib/rails/commands/credentials/USAGE +53 -53
  34. data/lib/rails/commands/credentials/credentials_command/diffing.rb +31 -19
  35. data/lib/rails/commands/credentials/credentials_command.rb +67 -69
  36. data/lib/rails/commands/db/system/change/change_command.rb +2 -1
  37. data/lib/rails/commands/dbconsole/dbconsole_command.rb +26 -117
  38. data/lib/rails/commands/destroy/destroy_command.rb +3 -2
  39. data/lib/rails/commands/dev/dev_command.rb +1 -6
  40. data/lib/rails/commands/encrypted/USAGE +15 -20
  41. data/lib/rails/commands/encrypted/encrypted_command.rb +46 -35
  42. data/lib/rails/commands/gem_help/USAGE +16 -0
  43. data/lib/rails/commands/gem_help/gem_help_command.rb +13 -0
  44. data/lib/rails/commands/generate/generate_command.rb +2 -2
  45. data/lib/rails/commands/help/USAGE +15 -14
  46. data/lib/rails/commands/help/help_command.rb +21 -2
  47. data/lib/rails/commands/initializers/initializers_command.rb +1 -4
  48. data/lib/rails/commands/middleware/middleware_command.rb +17 -0
  49. data/lib/rails/commands/new/new_command.rb +2 -0
  50. data/lib/rails/commands/notes/notes_command.rb +2 -1
  51. data/lib/rails/commands/plugin/plugin_command.rb +2 -0
  52. data/lib/rails/commands/rake/rake_command.rb +25 -22
  53. data/lib/rails/commands/restart/restart_command.rb +14 -0
  54. data/lib/rails/commands/routes/routes_command.rb +13 -1
  55. data/lib/rails/commands/runner/USAGE +14 -12
  56. data/lib/rails/commands/runner/runner_command.rb +34 -21
  57. data/lib/rails/commands/secret/secret_command.rb +13 -0
  58. data/lib/rails/commands/secrets/USAGE +44 -49
  59. data/lib/rails/commands/secrets/secrets_command.rb +20 -38
  60. data/lib/rails/commands/server/server_command.rb +33 -30
  61. data/lib/rails/commands/test/USAGE +14 -0
  62. data/lib/rails/commands/test/test_command.rb +56 -14
  63. data/lib/rails/commands/unused_routes/unused_routes_command.rb +75 -0
  64. data/lib/rails/commands/version/version_command.rb +1 -0
  65. data/lib/rails/configuration.rb +23 -28
  66. data/lib/rails/console/app.rb +1 -4
  67. data/lib/rails/console/helpers.rb +2 -2
  68. data/lib/rails/deprecator.rb +7 -0
  69. data/lib/rails/engine/configuration.rb +53 -9
  70. data/lib/rails/engine.rb +63 -48
  71. data/lib/rails/gem_version.rb +3 -3
  72. data/lib/rails/generators/actions/create_migration.rb +2 -4
  73. data/lib/rails/generators/actions.rb +231 -73
  74. data/lib/rails/generators/active_model.rb +28 -14
  75. data/lib/rails/generators/app_base.rb +476 -176
  76. data/lib/rails/generators/app_name.rb +3 -14
  77. data/lib/rails/generators/base.rb +24 -20
  78. data/lib/rails/generators/database.rb +39 -1
  79. data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +1 -1
  80. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
  81. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +8 -8
  82. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
  83. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +11 -28
  84. data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
  85. data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +17 -0
  86. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +8 -17
  87. data/lib/rails/generators/erb.rb +1 -1
  88. data/lib/rails/generators/generated_attribute.rb +57 -9
  89. data/lib/rails/generators/migration.rb +2 -7
  90. data/lib/rails/generators/model_helpers.rb +3 -2
  91. data/lib/rails/generators/named_base.rb +13 -13
  92. data/lib/rails/generators/rails/app/USAGE +22 -6
  93. data/lib/rails/generators/rails/app/app_generator.rb +113 -114
  94. data/lib/rails/generators/rails/app/templates/Dockerfile.tt +103 -0
  95. data/lib/rails/generators/rails/app/templates/Gemfile.tt +43 -53
  96. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +2 -2
  97. data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +2 -2
  98. data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +1 -1
  99. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +3 -9
  100. data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +1 -1
  101. data/lib/rails/generators/rails/app/templates/bin/rails.tt +1 -4
  102. data/lib/rails/generators/rails/app/templates/bin/rake.tt +0 -3
  103. data/lib/rails/generators/rails/app/templates/bin/setup.tt +16 -12
  104. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +6 -18
  105. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +1 -1
  106. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
  107. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
  108. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +7 -7
  109. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +5 -5
  110. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
  111. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
  112. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +7 -9
  113. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +4 -4
  114. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +5 -5
  115. data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +59 -0
  116. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +16 -12
  117. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +38 -61
  118. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +14 -15
  119. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +3 -5
  120. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +21 -28
  121. data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +3 -3
  122. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
  123. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +4 -4
  124. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_1.rb.tt +283 -0
  125. data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -9
  126. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +13 -15
  127. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +12 -20
  128. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +8 -1
  129. data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
  130. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +6 -4
  131. data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +10 -0
  132. data/lib/rails/generators/rails/app/templates/dockerignore.tt +43 -0
  133. data/lib/rails/generators/rails/app/templates/gitattributes.tt +0 -5
  134. data/lib/rails/generators/rails/app/templates/gitignore.tt +7 -9
  135. data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
  136. data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +10 -8
  137. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +10 -8
  138. data/lib/rails/generators/rails/application_record/application_record_generator.rb +4 -0
  139. data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +2 -1
  140. data/lib/rails/generators/rails/controller/USAGE +12 -4
  141. data/lib/rails/generators/rails/controller/controller_generator.rb +6 -2
  142. data/lib/rails/generators/rails/controller/templates/controller.rb.tt +1 -5
  143. data/lib/rails/generators/rails/credentials/credentials_generator.rb +29 -24
  144. data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +8 -0
  145. data/lib/rails/generators/rails/db/system/change/change_generator.rb +31 -1
  146. data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -2
  147. data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
  148. data/lib/rails/generators/rails/migration/USAGE +21 -11
  149. data/lib/rails/generators/rails/model/model_generator.rb +4 -0
  150. data/lib/rails/generators/rails/plugin/USAGE +17 -6
  151. data/lib/rails/generators/rails/plugin/plugin_generator.rb +69 -30
  152. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +7 -3
  153. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +9 -31
  154. data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +1 -1
  155. data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
  156. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +2 -2
  157. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
  158. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +5 -20
  159. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -7
  160. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +2 -2
  161. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -1
  162. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +2 -2
  163. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +6 -11
  164. data/lib/rails/generators/rails/resource/resource_generator.rb +6 -0
  165. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -20
  166. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
  167. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -5
  168. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +6 -10
  169. data/lib/rails/generators/resource_helpers.rb +2 -2
  170. data/lib/rails/generators/test_case.rb +2 -2
  171. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +1 -1
  172. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
  173. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +4 -4
  174. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +5 -5
  175. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +7 -7
  176. data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +9 -11
  177. data/lib/rails/generators/testing/{behaviour.rb → behavior.rb} +7 -5
  178. data/lib/rails/generators.rb +14 -29
  179. data/lib/rails/health_controller.rb +55 -0
  180. data/lib/rails/info.rb +2 -2
  181. data/lib/rails/info_controller.rb +31 -13
  182. data/lib/rails/initializable.rb +1 -1
  183. data/lib/rails/mailers_controller.rb +17 -9
  184. data/lib/rails/paths.rb +14 -11
  185. data/lib/rails/rack/logger.rb +16 -15
  186. data/lib/rails/rackup/server.rb +15 -0
  187. data/lib/rails/railtie/configuration.rb +15 -3
  188. data/lib/rails/railtie.rb +54 -31
  189. data/lib/rails/ruby_version_check.rb +5 -3
  190. data/lib/rails/secrets.rb +10 -8
  191. data/lib/rails/source_annotation_extractor.rb +68 -19
  192. data/lib/rails/tasks/engine.rake +8 -8
  193. data/lib/rails/tasks/framework.rake +4 -12
  194. data/lib/rails/tasks/log.rake +1 -1
  195. data/lib/rails/tasks/misc.rake +3 -14
  196. data/lib/rails/tasks/statistics.rake +8 -5
  197. data/lib/rails/tasks/tmp.rake +13 -6
  198. data/lib/rails/tasks/yarn.rake +8 -9
  199. data/lib/rails/tasks/zeitwerk.rake +14 -42
  200. data/lib/rails/tasks.rb +0 -2
  201. data/lib/rails/templates/layouts/application.html.erb +15 -0
  202. data/lib/rails/templates/rails/mailers/email.html.erb +45 -11
  203. data/lib/rails/templates/rails/mailers/index.html.erb +14 -7
  204. data/lib/rails/templates/rails/mailers/mailer.html.erb +11 -5
  205. data/lib/rails/templates/rails/welcome/index.html.erb +65 -48
  206. data/lib/rails/test_help.rb +13 -14
  207. data/lib/rails/test_unit/line_filtering.rb +1 -1
  208. data/lib/rails/test_unit/railtie.rb +0 -4
  209. data/lib/rails/test_unit/reporter.rb +6 -2
  210. data/lib/rails/test_unit/runner.rb +45 -20
  211. data/lib/rails/test_unit/test_parser.rb +88 -0
  212. data/lib/rails/test_unit/testing.rake +18 -43
  213. data/lib/rails/testing/maintain_test_schema.rb +16 -0
  214. data/lib/rails/version.rb +1 -1
  215. data/lib/rails/welcome_controller.rb +1 -0
  216. data/lib/rails/zeitwerk_checker.rb +15 -0
  217. data/lib/rails.rb +26 -15
  218. metadata +74 -42
  219. data/RDOC_MAIN.rdoc +0 -97
  220. data/lib/rails/.DS_Store +0 -0
  221. data/lib/rails/application/dummy_erb_compiler.rb +0 -18
  222. data/lib/rails/command/spellchecker.rb +0 -57
  223. data/lib/rails/generators/css/assets/assets_generator.rb +0 -15
  224. data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
  225. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -18
  226. data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +0 -6
  227. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +0 -5
  228. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +0 -23
  229. data/lib/rails/generators/rails/app/templates/bin/spring.tt +0 -13
  230. data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -16
  231. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb.tt +0 -8
  232. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +0 -8
  233. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb.tt +0 -5
  234. data/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb.tt +0 -4
  235. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -67
  236. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +0 -16
  237. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +0 -6
  238. data/lib/rails/generators/rails/app/templates/package.json.tt +0 -11
  239. data/lib/rails/generators/rails/assets/USAGE +0 -16
  240. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -26
  241. data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
  242. data/lib/rails/generators/rails/model/USAGE +0 -113
  243. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
  244. data/lib/rails/tasks/middleware.rake +0 -9
  245. data/lib/rails/tasks/restart.rake +0 -9
@@ -1,14 +1,14 @@
1
- # Files in the config/locales directory are used for internationalization
2
- # and are automatically loaded by Rails. If you want to use locales other
3
- # than English, add the necessary files in this directory.
1
+ # Files in the config/locales directory are used for internationalization and
2
+ # are automatically loaded by Rails. If you want to use locales other than
3
+ # English, add the necessary files in this directory.
4
4
  #
5
5
  # To use the locales, use `I18n.t`:
6
6
  #
7
- # I18n.t 'hello'
7
+ # I18n.t "hello"
8
8
  #
9
9
  # In views, this is aliased to just `t`:
10
10
  #
11
- # <%= t('hello') %>
11
+ # <%= t("hello") %>
12
12
  #
13
13
  # To use a different locale, set it with `I18n.locale`:
14
14
  #
@@ -16,18 +16,16 @@
16
16
  #
17
17
  # This would use the information in config/locales/es.yml.
18
18
  #
19
- # The following keys must be escaped otherwise they will not be retrieved by
20
- # the default I18n backend:
19
+ # To learn more about the API, please read the Rails Internationalization guide
20
+ # at https://guides.rubyonrails.org/i18n.html.
21
21
  #
22
- # true, false, on, off, yes, no
22
+ # Be aware that YAML interprets the following case-insensitive strings as
23
+ # booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings
24
+ # must be quoted to be interpreted as strings. For example:
23
25
  #
24
- # Instead, surround them with single quotes.
25
- #
26
- # en:
27
- # 'true': 'foo'
28
- #
29
- # To learn more, please read the Rails Internationalization guide
30
- # available at https://guides.rubyonrails.org/i18n.html.
26
+ # en:
27
+ # "yes": yup
28
+ # enabled: "ON"
31
29
 
32
30
  en:
33
31
  hello: "Hello world"
@@ -1,43 +1,35 @@
1
+ # This configuration file will be evaluated by Puma. The top-level methods that
2
+ # are invoked here are part of Puma's configuration DSL. For more information
3
+ # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
4
+
1
5
  # Puma can serve each request in a thread from an internal thread pool.
2
6
  # The `threads` method setting takes two numbers: a minimum and maximum.
3
7
  # Any libraries that use thread pools should be configured to match
4
8
  # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
9
  # and maximum; this matches the default thread size of Active Record.
6
- #
7
10
  max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8
11
  min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9
12
  threads min_threads_count, max_threads_count
10
13
 
14
+ # Specifies that the worker count should equal the number of processors in production.
15
+ if ENV["RAILS_ENV"] == "production"
16
+ require "concurrent-ruby"
17
+ worker_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.physical_processor_count })
18
+ workers worker_count if worker_count > 1
19
+ end
20
+
11
21
  # Specifies the `worker_timeout` threshold that Puma will use to wait before
12
22
  # terminating a worker in development environments.
13
- #
14
23
  worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
15
24
 
16
25
  # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
17
- #
18
26
  port ENV.fetch("PORT") { 3000 }
19
27
 
20
28
  # Specifies the `environment` that Puma will run in.
21
- #
22
29
  environment ENV.fetch("RAILS_ENV") { "development" }
23
30
 
24
31
  # Specifies the `pidfile` that Puma will use.
25
32
  pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
26
33
 
27
- # Specifies the number of `workers` to boot in clustered mode.
28
- # Workers are forked web server processes. If using threads and workers together
29
- # the concurrency of the application would be max `threads` * `workers`.
30
- # Workers do not work on JRuby or Windows (both of which do not support
31
- # processes).
32
- #
33
- # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
34
-
35
- # Use the `preload_app!` method when specifying a `workers` number.
36
- # This directive tells Puma to first boot the application and load code
37
- # before forking the application. This takes advantage of Copy On Write
38
- # process behavior so workers use less memory.
39
- #
40
- # preload_app!
41
-
42
- # Allow puma to be restarted by `rails restart` command.
34
+ # Allow puma to be restarted by `bin/rails restart` command.
43
35
  plugin :tmp_restart
@@ -1,3 +1,10 @@
1
1
  Rails.application.routes.draw do
2
- # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
2
+ # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
3
+
4
+ # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
5
+ # Can be used by load balancers and uptime monitors to verify that the app is live.
6
+ get "up" => "rails/health#show", as: :rails_health_check
7
+
8
+ # Defines the root path route ("/")
9
+ # root "posts#index"
3
10
  end
@@ -6,27 +6,27 @@ local:
6
6
  service: Disk
7
7
  root: <%%= Rails.root.join("storage") %>
8
8
 
9
- # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
9
+ # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10
10
  # amazon:
11
11
  # service: S3
12
12
  # access_key_id: <%%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13
13
  # secret_access_key: <%%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14
14
  # region: us-east-1
15
- # bucket: your_own_bucket
15
+ # bucket: your_own_bucket-<%%= Rails.env %>
16
16
 
17
17
  # Remember not to checkin your GCS keyfile to a repository
18
18
  # google:
19
19
  # service: GCS
20
20
  # project: your_project
21
21
  # credentials: <%%= Rails.root.join("path/to/gcs.keyfile") %>
22
- # bucket: your_own_bucket
22
+ # bucket: your_own_bucket-<%%= Rails.env %>
23
23
 
24
- # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
24
+ # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25
25
  # microsoft:
26
26
  # service: AzureStorage
27
27
  # storage_account_name: your_account_name
28
28
  # storage_access_key: <%%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29
- # container: your_container_name
29
+ # container: your_container_name-<%%= Rails.env %>
30
30
 
31
31
  # mirror:
32
32
  # service: Mirror
@@ -1,7 +1,9 @@
1
- # This file should contain all the record creation needed to seed the database with its default values.
1
+ # This file should ensure the existence of records required to run the application in every environment (production,
2
+ # development, test). The code here should be idempotent so that it can be executed at any point in every environment.
2
3
  # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
3
4
  #
4
- # Examples:
5
+ # Example:
5
6
  #
6
- # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7
- # Character.create(name: 'Luke', movie: movies.first)
7
+ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
8
+ # MovieGenre.find_or_create_by!(name: genre_name)
9
+ # end
@@ -0,0 +1,10 @@
1
+ #!/bin/bash -e
2
+
3
+ <% unless skip_active_record? -%>
4
+ # If running the rails server then create or migrate existing database
5
+ if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
6
+ ./bin/rails db:prepare
7
+ fi
8
+
9
+ <% end -%>
10
+ exec "${@}"
@@ -0,0 +1,43 @@
1
+ # See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
2
+
3
+ # Ignore git directory.
4
+ /.git/
5
+
6
+ # Ignore bundler config.
7
+ /.bundle
8
+
9
+ # Ignore all environment files (except templates).
10
+ /.env*
11
+ !/.env*.erb
12
+
13
+ # Ignore all default key files.
14
+ /config/master.key
15
+ /config/credentials/*.key
16
+
17
+ # Ignore all logfiles and tempfiles.
18
+ /log/*
19
+ /tmp/*
20
+ <% if keeps? -%>
21
+ !/log/.keep
22
+ !/tmp/.keep
23
+
24
+ # Ignore pidfiles, but keep the directory.
25
+ /tmp/pids/*
26
+ !/tmp/pids/.keep
27
+ <% end -%>
28
+
29
+ # Ignore storage (uploaded files in development and any SQLite databases).
30
+ /storage/*
31
+ <% if keeps? -%>
32
+ !/storage/.keep
33
+ /tmp/storage/*
34
+ !/tmp/storage/.keep
35
+ <% end -%>
36
+ <% unless options.api? -%>
37
+
38
+ # Ignore assets.
39
+ /node_modules/
40
+ /app/assets/builds/*
41
+ !/app/assets/builds/.keep
42
+ /public/assets
43
+ <% end -%>
@@ -5,10 +5,5 @@
5
5
  db/schema.rb linguist-generated
6
6
  <% end -%>
7
7
 
8
- <% unless options[:skip_javascript] -%>
9
- # Mark the yarn lockfile as having been generated.
10
- yarn.lock linguist-generated
11
- <% end -%>
12
-
13
8
  # Mark any vendored files as having been vendored.
14
9
  vendor/* linguist-vendored
@@ -7,12 +7,10 @@
7
7
  # Ignore bundler config.
8
8
  /.bundle
9
9
 
10
- <% if sqlite3? -%>
11
- # Ignore the default SQLite database.
12
- /db/*.sqlite3
13
- /db/*.sqlite3-*
10
+ # Ignore all environment files (except templates).
11
+ /.env*
12
+ !/.env*.erb
14
13
 
15
- <% end -%>
16
14
  # Ignore all logfiles and tempfiles.
17
15
  /log/*
18
16
  /tmp/*
@@ -26,15 +24,15 @@
26
24
  !/tmp/pids/.keep
27
25
  <% end -%>
28
26
 
29
- <% unless skip_active_storage? -%>
30
- # Ignore uploaded files in development.
27
+ # Ignore storage (uploaded files in development and any SQLite databases).
31
28
  /storage/*
32
29
  <% if keeps? -%>
33
30
  !/storage/.keep
34
- <% end -%>
31
+ /tmp/storage/*
32
+ !/tmp/storage/
33
+ !/tmp/storage/.keep
35
34
  <% end -%>
36
35
  <% unless options.api? -%>
37
36
 
38
37
  /public/assets
39
38
  <% end -%>
40
- .byebug_history
@@ -0,0 +1 @@
1
+ <%= node_version %>
@@ -1,11 +1,13 @@
1
1
  require "test_helper"
2
2
 
3
- class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
4
- # test "connects with cookies" do
5
- # cookies.signed[:user_id] = 42
6
- #
7
- # connect
8
- #
9
- # assert_equal connection.user_id, "42"
10
- # end
3
+ module ApplicationCable
4
+ class ConnectionTest < ActionCable::Connection::TestCase
5
+ # test "connects with cookies" do
6
+ # cookies.signed[:user_id] = 42
7
+ #
8
+ # connect
9
+ #
10
+ # assert_equal connection.user_id, "42"
11
+ # end
12
+ end
11
13
  end
@@ -1,19 +1,21 @@
1
- ENV['RAILS_ENV'] ||= 'test'
1
+ ENV["RAILS_ENV"] ||= "test"
2
2
  require_relative "../config/environment"
3
3
  require "rails/test_help"
4
4
 
5
- class ActiveSupport::TestCase
6
- # Run tests in parallel with specified workers
5
+ module ActiveSupport
6
+ class TestCase
7
+ # Run tests in parallel with specified workers
7
8
  <% if Process.respond_to?(:fork) && !Gem.win_platform? -%>
8
- parallelize(workers: :number_of_processors)
9
+ parallelize(workers: :number_of_processors)
9
10
  <%- else -%>
10
- parallelize(workers: :number_of_processors, with: :threads)
11
+ parallelize(workers: :number_of_processors, with: :threads)
11
12
  <% end -%>
12
13
 
13
14
  <% unless options[:skip_active_record] -%>
14
- # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
15
- fixtures :all
15
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
16
+ fixtures :all
16
17
 
17
18
  <% end -%>
18
- # Add more helper methods to be used by all tests here...
19
+ # Add more helper methods to be used by all tests here...
20
+ end
19
21
  end
@@ -4,6 +4,10 @@ module Rails
4
4
  module Generators
5
5
  class ApplicationRecordGenerator < Base # :nodoc:
6
6
  hook_for :orm, required: true, desc: "ORM to be invoked"
7
+
8
+ class << self
9
+ delegate(:desc, to: :orm_generator)
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -6,6 +6,7 @@ module Rails
6
6
  module Generators
7
7
  class BenchmarkGenerator < NamedBase
8
8
  IPS_GEM_NAME = "benchmark-ips"
9
+ IPS_GEM_USED_REGEXP = /gem.*\b#{IPS_GEM_NAME}\b.*/
9
10
 
10
11
  argument :reports, type: :array, default: ["before", "after"]
11
12
 
@@ -21,7 +22,7 @@ module Rails
21
22
 
22
23
  def ips_installed?
23
24
  in_root do
24
- return File.read("Gemfile").match?(/gem.*\b#{IPS_GEM_NAME}\b.*/)
25
+ return File.read("Gemfile").match?(IPS_GEM_USED_REGEXP)
25
26
  end
26
27
  end
27
28
  end
@@ -1,6 +1,6 @@
1
1
  Description:
2
2
  Generates a new controller and its views. Pass the controller name, either
3
- CamelCased or under_scored, and a list of views as arguments.
3
+ CamelCased or under_scored, and a list of actions as arguments.
4
4
 
5
5
  To create a controller within a module, specify the controller name as a
6
6
  path like 'parent_module/controller_name'.
@@ -8,11 +8,19 @@ Description:
8
8
  This generates a controller class in app/controllers and invokes helper,
9
9
  template engine, assets, and test framework generators.
10
10
 
11
- Example:
12
- `bin/rails generate controller CreditCards open debit credit close`
11
+ Examples:
12
+ `bin/rails generate controller credit_cards open debit credit close`
13
13
 
14
- CreditCards controller with URLs like /credit_cards/debit.
14
+ This generates a `CreditCardsController` with routes like /credit_cards/debit.
15
15
  Controller: app/controllers/credit_cards_controller.rb
16
16
  Test: test/controllers/credit_cards_controller_test.rb
17
17
  Views: app/views/credit_cards/debit.html.erb [...]
18
18
  Helper: app/helpers/credit_cards_helper.rb
19
+
20
+ `bin/rails generate controller users index --skip-routes`
21
+
22
+ This generates a `UsersController` with an index action and no routes.
23
+
24
+ `bin/rails generate controller admin/dashboard --parent=admin_controller`
25
+
26
+ This generates a `Admin::DashboardController` with an `AdminController` parent class.
@@ -6,7 +6,7 @@ module Rails
6
6
  argument :actions, type: :array, default: [], banner: "action action"
7
7
  class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
8
8
  class_option :helper, type: :boolean
9
- class_option :assets, type: :boolean
9
+ class_option :parent, type: :string, default: "ApplicationController", desc: "The parent class for the generated controller"
10
10
 
11
11
  check_class_collision suffix: "Controller"
12
12
 
@@ -21,11 +21,15 @@ module Rails
21
21
  route routing_code, namespace: regular_class_path
22
22
  end
23
23
 
24
- hook_for :template_engine, :test_framework, :helper, :assets do |generator|
24
+ hook_for :template_engine, :test_framework, :helper do |generator|
25
25
  invoke generator, [ remove_possible_suffix(name), actions ]
26
26
  end
27
27
 
28
28
  private
29
+ def parent_class_name
30
+ options[:parent]
31
+ end
32
+
29
33
  def file_name
30
34
  @_file_name ||= remove_possible_suffix(super)
31
35
  end
@@ -1,9 +1,5 @@
1
- <% if namespaced? -%>
2
- require_dependency "<%= namespaced_path %>/application_controller"
3
-
4
- <% end -%>
5
1
  <% module_namespacing do -%>
6
- class <%= class_name %>Controller < ApplicationController
2
+ class <%= class_name %>Controller < <%= parent_class_name.classify %>
7
3
  <% actions.each do |action| -%>
8
4
  def <%= action %>
9
5
  end
@@ -7,49 +7,54 @@ require "active_support/encrypted_configuration"
7
7
  module Rails
8
8
  module Generators
9
9
  class CredentialsGenerator < Base # :nodoc:
10
+ argument :content_path, default: "config/credentials.yml.enc"
11
+ argument :key_path, default: "config/master.key"
12
+ class_option :skip_secret_key_base, type: :boolean
13
+
10
14
  def add_credentials_file
11
- unless credentials.content_path.exist?
12
- template = credentials_template
15
+ in_root do
16
+ return if File.exist?(content_path)
13
17
 
14
- say "Adding #{credentials.content_path} to store encrypted credentials."
18
+ say "Adding #{content_path} to store encrypted credentials."
15
19
  say ""
20
+
21
+ content = render_template_to_encrypted_file
22
+
16
23
  say "The following content has been encrypted with the Rails master key:"
17
24
  say ""
18
- say template, :on_green
25
+ say content, :on_green
19
26
  say ""
20
-
21
- add_credentials_file_silently(template)
22
-
23
27
  say "You can edit encrypted credentials with `bin/rails credentials:edit`."
24
28
  say ""
25
29
  end
26
30
  end
27
31
 
28
- def add_credentials_file_silently(template = nil)
29
- unless credentials.content_path.exist?
30
- credentials.write(credentials_template)
31
- end
32
- end
33
-
34
32
  private
35
- def credentials
33
+ def encrypted_file
36
34
  ActiveSupport::EncryptedConfiguration.new(
37
- config_path: "config/credentials.yml.enc",
38
- key_path: "config/master.key",
35
+ config_path: content_path,
36
+ key_path: key_path,
39
37
  env_key: "RAILS_MASTER_KEY",
40
38
  raise_if_missing_key: true
41
39
  )
42
40
  end
43
41
 
44
- def credentials_template
45
- <<~YAML
46
- # aws:
47
- # access_key_id: 123
48
- # secret_access_key: 345
42
+ def secret_key_base
43
+ @secret_key_base ||= SecureRandom.hex(64)
44
+ end
45
+
46
+ def render_template_to_encrypted_file
47
+ empty_directory File.dirname(content_path)
48
+
49
+ content = nil
50
+
51
+ encrypted_file.change do |tmp_path|
52
+ template("credentials.yml", tmp_path, force: true, verbose: false) do |rendered|
53
+ content = rendered
54
+ end
55
+ end
49
56
 
50
- # Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
51
- secret_key_base: #{SecureRandom.hex(64)}
52
- YAML
57
+ content
53
58
  end
54
59
  end
55
60
  end
@@ -0,0 +1,8 @@
1
+ # aws:
2
+ # access_key_id: 123
3
+ # secret_access_key: 345
4
+ <% unless options.skip_secret_key_base? -%>
5
+
6
+ # Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
7
+ secret_key_base: <%= secret_key_base %>
8
+ <% end -%>
@@ -40,22 +40,52 @@ module Rails
40
40
  gsub_file("Gemfile", gem_entry_regex_for(name), gem_entry_for(name, *version))
41
41
  end
42
42
 
43
+ def edit_dockerfile
44
+ dockerfile_path = File.expand_path("Dockerfile", destination_root)
45
+ return unless File.exist?(dockerfile_path)
46
+
47
+ build_name = docker_for_database_build
48
+ deploy_name = docker_for_database_deploy
49
+ if build_name
50
+ gsub_file("Dockerfile", all_docker_builds_regex, build_name)
51
+ end
52
+ if deploy_name
53
+ gsub_file("Dockerfile", all_docker_deploys_regex, deploy_name)
54
+ end
55
+ end
56
+
43
57
  private
44
58
  def all_database_gems
45
59
  DATABASES.map { |database| gem_for_database(database) }
46
60
  end
47
61
 
62
+ def all_docker_builds
63
+ DATABASES.map { |database| docker_for_database_build(database).nil? ? nil : docker_for_database_build(database) }.compact!
64
+ end
65
+
66
+ def all_docker_deploys
67
+ DATABASES.map { |database| docker_for_database_deploy(database).nil? ? nil : docker_for_database_deploy(database) }.compact!
68
+ end
69
+
48
70
  def all_database_gems_regex
49
71
  all_database_gem_names = all_database_gems.map(&:first)
50
72
  /(\b#{all_database_gem_names.join('\b|\b')}\b)/
51
73
  end
52
74
 
75
+ def all_docker_builds_regex
76
+ /(\b#{all_docker_builds.join('\b|\b')}\b)/
77
+ end
78
+
79
+ def all_docker_deploys_regex
80
+ /(\b#{all_docker_deploys.join('\b|\b')}\b)/
81
+ end
82
+
53
83
  def gem_entry_regex_for(gem_name)
54
84
  /^gem.*\b#{gem_name}\b.*/
55
85
  end
56
86
 
57
87
  def gem_entry_for(*gem_name_and_version)
58
- gem_name_and_version.map! { |segment| "'#{segment}'" }
88
+ gem_name_and_version.map! { |segment| "\"#{segment}\"" }
59
89
  "gem #{gem_name_and_version.join(", ")}"
60
90
  end
61
91
  end
@@ -26,8 +26,7 @@ module Rails
26
26
  end
27
27
 
28
28
  def add_key_file_silently(key_path, key = nil)
29
- create_file key_path, key || ActiveSupport::EncryptedFile.generate_key
30
- key_path.chmod 0600
29
+ create_file key_path, key || ActiveSupport::EncryptedFile.generate_key, perm: 0600
31
30
  end
32
31
 
33
32
  def ignore_key_file(key_path, ignore: key_ignore(key_path))
@@ -1,3 +1,3 @@
1
1
  class <%= class_name %>Generator < Rails::Generators::NamedBase
2
- source_root File.expand_path('templates', __dir__)
2
+ source_root File.expand_path("templates", __dir__)
3
3
  end
@@ -5,31 +5,41 @@ Description:
5
5
  A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
6
6
 
7
7
  You can name your migration in either of these formats to generate add/remove
8
- column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
8
+ column lines from supplied attributes: add_{columns}_to_{table} or remove_{columns}_from_{table}.
9
9
 
10
- Example:
11
- `bin/rails generate migration AddSslFlag`
10
+ A migration name containing JoinTable will generate join tables for use with
11
+ has_and_belongs_to_many associations.
12
+
13
+ You can also name your migration create_{table} along with any attributes to generate a regular table.
14
+
15
+ Examples:
16
+ `bin/rails generate migration add_ssl_flag`
12
17
 
13
18
  If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
14
19
  db/migrate/20080514090912_add_ssl_flag.rb
15
20
 
16
- `bin/rails generate migration AddTitleBodyToPost title:string body:text published:boolean`
21
+ `bin/rails generate migration add_title_body_published_to_post title:string body:text published:boolean`
17
22
 
18
- This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with this in the Change migration:
23
+ This will create db/migrate/20080514090912_add_title_body_published_to_post.rb with this in the migration:
19
24
 
20
25
  add_column :posts, :title, :string
21
26
  add_column :posts, :body, :text
22
27
  add_column :posts, :published, :boolean
23
28
 
24
- Migration names containing JoinTable will generate join tables for use with
25
- has_and_belongs_to_many associations.
29
+ `bin/rails generate migration create_media_join_table artists musics:uniq`
26
30
 
27
- Example:
28
- `bin/rails g migration CreateMediaJoinTable artists musics:uniq`
29
-
30
- will create the migration
31
+ This will create a join table migration:
31
32
 
32
33
  create_join_table :artists, :musics do |t|
33
34
  # t.index [:artist_id, :music_id]
34
35
  t.index [:music_id, :artist_id], unique: true
35
36
  end
37
+
38
+ `bin/rails generate migration create_users email:string`
39
+
40
+ This will create the migration:
41
+
42
+ create_table :users do |t|
43
+ t.string :email
44
+ t.timestamps
45
+ end
@@ -9,6 +9,10 @@ module Rails
9
9
 
10
10
  argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
11
11
  hook_for :orm, required: true, desc: "ORM to be invoked"
12
+
13
+ class << self
14
+ delegate(:desc, to: :orm_generator)
15
+ end
12
16
  end
13
17
  end
14
18
  end