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
@@ -4,12 +4,14 @@ require "yaml"
4
4
  require "active_support/core_ext/hash/keys"
5
5
  require "active_support/core_ext/object/blank"
6
6
  require "active_support/key_generator"
7
- require "active_support/message_verifier"
7
+ require "active_support/message_verifiers"
8
+ require "active_support/deprecation"
8
9
  require "active_support/encrypted_configuration"
9
10
  require "active_support/hash_with_indifferent_access"
10
11
  require "active_support/configuration_file"
11
12
  require "rails/engine"
12
13
  require "rails/secrets"
14
+ require "rails/autoloaders"
13
15
 
14
16
  module Rails
15
17
  # An Engine with the responsibility of coordinating the whole boot process.
@@ -21,12 +23,12 @@ module Rails
21
23
  # Rails::Application::Bootstrap) and finishing initializers, after all the others
22
24
  # are executed (check Rails::Application::Finisher).
23
25
  #
24
- # == Configuration
26
+ # == \Configuration
25
27
  #
26
28
  # Besides providing the same configuration as Rails::Engine and Rails::Railtie,
27
29
  # the application object has several specific configurations, for example
28
- # "cache_classes", "consider_all_requests_local", "filter_parameters",
29
- # "logger" and so forth.
30
+ # +enable_reloading+, +consider_all_requests_local+, +filter_parameters+,
31
+ # +logger+, and so forth.
30
32
  #
31
33
  # Check Rails::Application::Configuration to see them all.
32
34
  #
@@ -42,44 +44,21 @@ module Rails
42
44
  # == Booting process
43
45
  #
44
46
  # The application is also responsible for setting up and executing the booting
45
- # process. From the moment you require "config/application.rb" in your app,
47
+ # process. From the moment you require <tt>config/application.rb</tt> in your app,
46
48
  # the booting process goes like this:
47
49
  #
48
- # 1) require "config/boot.rb" to set up load paths
49
- # 2) require railties and engines
50
- # 3) Define Rails.application as "class MyApp::Application < Rails::Application"
51
- # 4) Run config.before_configuration callbacks
52
- # 5) Load config/environments/ENV.rb
53
- # 6) Run config.before_initialize callbacks
54
- # 7) Run Railtie#initializer defined by railties, engines and application.
55
- # One by one, each engine sets up its load paths, routes and runs its config/initializers/* files.
56
- # 8) Custom Railtie#initializers added by railties, engines and applications are executed
57
- # 9) Build the middleware stack and run to_prepare callbacks
58
- # 10) Run config.before_eager_load and eager_load! if eager_load is true
59
- # 11) Run config.after_initialize callbacks
60
- #
61
- # == Multiple Applications
62
- #
63
- # If you decide to define multiple applications, then the first application
64
- # that is initialized will be set to +Rails.application+, unless you override
65
- # it with a different application.
66
- #
67
- # To create a new application, you can instantiate a new instance of a class
68
- # that has already been created:
69
- #
70
- # class Application < Rails::Application
71
- # end
72
- #
73
- # first_application = Application.new
74
- # second_application = Application.new(config: first_application.config)
75
- #
76
- # In the above example, the configuration from the first application was used
77
- # to initialize the second application. You can also use the +initialize_copy+
78
- # on one of the applications to create a copy of the application which shares
79
- # the configuration.
80
- #
81
- # If you decide to define Rake tasks, runners, or initializers in an
82
- # application other than +Rails.application+, then you must run them manually.
50
+ # 1. <tt>require "config/boot.rb"</tt> to set up load paths.
51
+ # 2. +require+ railties and engines.
52
+ # 3. Define +Rails.application+ as <tt>class MyApp::Application < Rails::Application</tt>.
53
+ # 4. Run +config.before_configuration+ callbacks.
54
+ # 5. Load <tt>config/environments/ENV.rb</tt>.
55
+ # 6. Run +config.before_initialize+ callbacks.
56
+ # 7. Run <tt>Railtie#initializer</tt> defined by railties, engines, and application.
57
+ # One by one, each engine sets up its load paths and routes, and runs its <tt>config/initializers/*</tt> files.
58
+ # 8. Custom <tt>Railtie#initializers</tt> added by railties, engines, and applications are executed.
59
+ # 9. Build the middleware stack and run +to_prepare+ callbacks.
60
+ # 10. Run +config.before_eager_load+ and +eager_load!+ if +eager_load+ is +true+.
61
+ # 11. Run +config.after_initialize+ callbacks.
83
62
  class Application < Engine
84
63
  autoload :Bootstrap, "rails/application/bootstrap"
85
64
  autoload :Configuration, "rails/application/configuration"
@@ -92,6 +71,8 @@ module Rails
92
71
  def inherited(base)
93
72
  super
94
73
  Rails.app_class = base
74
+ # lib has to be added to $LOAD_PATH unconditionally, even if it's in the
75
+ # autoload paths and config.add_autoload_paths_to_load_path is false.
95
76
  add_lib_to_load_path!(find_root(base.called_from))
96
77
  ActiveSupport.run_load_hooks(:before_configuration, base)
97
78
  end
@@ -118,7 +99,7 @@ module Rails
118
99
 
119
100
  attr_accessor :assets, :sandbox
120
101
  alias_method :sandbox?, :sandbox
121
- attr_reader :reloaders, :reloader, :executor
102
+ attr_reader :reloaders, :reloader, :executor, :autoloaders
122
103
 
123
104
  delegate :default_url_options, :default_url_options=, to: :routes
124
105
 
@@ -133,13 +114,17 @@ module Rails
133
114
  @app_env_config = nil
134
115
  @ordered_railties = nil
135
116
  @railties = nil
136
- @message_verifiers = {}
117
+ @key_generators = {}
118
+ @message_verifiers = nil
119
+ @deprecators = nil
137
120
  @ran_load_hooks = false
138
121
 
139
122
  @executor = Class.new(ActiveSupport::Executor)
140
123
  @reloader = Class.new(ActiveSupport::Reloader)
141
124
  @reloader.executor = @executor
142
125
 
126
+ @autoloaders = Rails::Autoloaders.new
127
+
143
128
  # are these actually used?
144
129
  @initial_variable_values = initial_variable_values
145
130
  @block = block
@@ -169,15 +154,53 @@ module Rails
169
154
  routes_reloader.reload!
170
155
  end
171
156
 
172
- # Returns the application's KeyGenerator
173
- def key_generator
157
+ # Returns a key generator (ActiveSupport::CachingKeyGenerator) for a
158
+ # specified +secret_key_base+. The return value is memoized, so additional
159
+ # calls with the same +secret_key_base+ will return the same key generator
160
+ # instance.
161
+ def key_generator(secret_key_base = self.secret_key_base)
174
162
  # number of iterations selected based on consultation with the google security
175
163
  # team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220
176
- @caching_key_generator ||= ActiveSupport::CachingKeyGenerator.new(
164
+ @key_generators[secret_key_base] ||= ActiveSupport::CachingKeyGenerator.new(
177
165
  ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
178
166
  )
179
167
  end
180
168
 
169
+ # Returns a message verifier factory (ActiveSupport::MessageVerifiers). This
170
+ # factory can be used as a central point to configure and create message
171
+ # verifiers (ActiveSupport::MessageVerifier) for your application.
172
+ #
173
+ # By default, message verifiers created by this factory will generate
174
+ # messages using the default ActiveSupport::MessageVerifier options. You can
175
+ # override these options with a combination of
176
+ # ActiveSupport::MessageVerifiers#clear_rotations and
177
+ # ActiveSupport::MessageVerifiers#rotate. However, this must be done prior
178
+ # to building any message verifier instances. For example, in a
179
+ # +before_initialize+ block:
180
+ #
181
+ # # Use `url_safe: true` when generating messages
182
+ # config.before_initialize do |app|
183
+ # app.message_verifiers.clear_rotations
184
+ # app.message_verifiers.rotate(url_safe: true)
185
+ # end
186
+ #
187
+ # Message verifiers created by this factory will always use a secret derived
188
+ # from #secret_key_base when generating messages. +clear_rotations+ will not
189
+ # affect this behavior. However, older +secret_key_base+ values can be
190
+ # rotated for verifying messages:
191
+ #
192
+ # # Fall back to old `secret_key_base` when verifying messages
193
+ # config.before_initialize do |app|
194
+ # app.message_verifiers.rotate(secret_key_base: "old secret_key_base")
195
+ # end
196
+ #
197
+ def message_verifiers
198
+ @message_verifiers ||=
199
+ ActiveSupport::MessageVerifiers.new do |salt, secret_key_base: self.secret_key_base|
200
+ key_generator(secret_key_base).generate_key(salt)
201
+ end.rotate_defaults
202
+ end
203
+
181
204
  # Returns a message verifier object.
182
205
  #
183
206
  # This verifier can be used to generate and verify signed messages in the application.
@@ -195,15 +218,22 @@ module Rails
195
218
  # Rails.application.message_verifier('sensitive_data').verify(message)
196
219
  # # => 'my sensible data'
197
220
  #
198
- # See the +ActiveSupport::MessageVerifier+ documentation for more information.
221
+ # See the ActiveSupport::MessageVerifier documentation for more information.
199
222
  def message_verifier(verifier_name)
200
- @message_verifiers[verifier_name] ||= begin
201
- secret = key_generator.generate_key(verifier_name.to_s)
202
- ActiveSupport::MessageVerifier.new(secret)
223
+ message_verifiers[verifier_name]
224
+ end
225
+
226
+ # A managed collection of deprecators (ActiveSupport::Deprecation::Deprecators).
227
+ # The collection's configuration methods affect all deprecators in the
228
+ # collection. Additionally, the collection's +silence+ method silences all
229
+ # deprecators in the collection for the duration of a given block.
230
+ def deprecators
231
+ @deprecators ||= ActiveSupport::Deprecation::Deprecators.new.tap do |deprecators|
232
+ deprecators[:railties] = Rails.deprecator
203
233
  end
204
234
  end
205
235
 
206
- # Convenience for loading config/foo.yml for the current Rails env.
236
+ # Convenience for loading config/foo.yml for the current \Rails env.
207
237
  #
208
238
  # Examples:
209
239
  #
@@ -247,9 +277,11 @@ module Rails
247
277
  config, shared = all_configs[env.to_sym], all_configs[:shared]
248
278
 
249
279
  if shared
250
- config = {} if config.nil?
251
- if config.is_a?(Hash)
280
+ config = {} if config.nil? && shared.is_a?(Hash)
281
+ if config.is_a?(Hash) && shared.is_a?(Hash)
252
282
  config = shared.deep_merge(config)
283
+ elsif config.nil?
284
+ config = shared
253
285
  end
254
286
  end
255
287
 
@@ -263,16 +295,17 @@ module Rails
263
295
  end
264
296
  end
265
297
 
266
- # Stores some of the Rails initial environment parameters which
298
+ # Stores some of the \Rails initial environment parameters which
267
299
  # will be used by middlewares and engines to configure themselves.
268
300
  def env_config
269
- @app_env_config ||= begin
270
- super.merge(
271
- "action_dispatch.parameter_filter" => config.filter_parameters,
301
+ @app_env_config ||= super.merge(
302
+ "action_dispatch.parameter_filter" => filter_parameters,
272
303
  "action_dispatch.redirect_filter" => config.filter_redirect,
273
304
  "action_dispatch.secret_key_base" => secret_key_base,
274
305
  "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
275
306
  "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
307
+ "action_dispatch.log_rescued_responses" => config.action_dispatch.log_rescued_responses,
308
+ "action_dispatch.debug_exception_log_level" => ActiveSupport::Logger.const_get(config.action_dispatch.debug_exception_log_level.to_s.upcase),
276
309
  "action_dispatch.logger" => Rails.logger,
277
310
  "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner,
278
311
  "action_dispatch.key_generator" => key_generator,
@@ -295,7 +328,6 @@ module Rails
295
328
  "action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives,
296
329
  "action_dispatch.permissions_policy" => config.permissions_policy,
297
330
  )
298
- end
299
331
  end
300
332
 
301
333
  # If you try to define a set of Rake tasks on the instance, these will get
@@ -355,26 +387,26 @@ module Rails
355
387
  # are changing config.root inside your application definition or having a custom
356
388
  # Rails application, you will need to add lib to $LOAD_PATH on your own in case
357
389
  # you need to load files in lib/ during the application configuration as well.
358
- def self.add_lib_to_load_path!(root) #:nodoc:
359
- path = File.join root, "lib"
390
+ def self.add_lib_to_load_path!(root) # :nodoc:
391
+ path = File.join(root, "lib")
360
392
  if File.exist?(path) && !$LOAD_PATH.include?(path)
361
393
  $LOAD_PATH.unshift(path)
362
394
  end
363
395
  end
364
396
 
365
- def require_environment! #:nodoc:
397
+ def require_environment! # :nodoc:
366
398
  environment = paths["config/environment"].existent.first
367
399
  require environment if environment
368
400
  end
369
401
 
370
- def routes_reloader #:nodoc:
402
+ def routes_reloader # :nodoc:
371
403
  @routes_reloader ||= RoutesReloader.new
372
404
  end
373
405
 
374
406
  # Returns an array of file paths appended with a hash of
375
407
  # directories-extensions suitable for ActiveSupport::FileUpdateChecker
376
408
  # API.
377
- def watchable_args #:nodoc:
409
+ def watchable_args # :nodoc:
378
410
  files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
379
411
 
380
412
  ActiveSupport::Dependencies.autoload_paths.each do |path|
@@ -386,26 +418,29 @@ module Rails
386
418
 
387
419
  # Initialize the application passing the given group. By default, the
388
420
  # group is :default
389
- def initialize!(group = :default) #:nodoc:
421
+ def initialize!(group = :default) # :nodoc:
390
422
  raise "Application has been already initialized." if @initialized
391
423
  run_initializers(group, self)
392
424
  @initialized = true
393
425
  self
394
426
  end
395
427
 
396
- def initializers #:nodoc:
428
+ def initializers # :nodoc:
397
429
  Bootstrap.initializers_for(self) +
398
430
  railties_initializers(super) +
399
431
  Finisher.initializers_for(self)
400
432
  end
401
433
 
402
- def config #:nodoc:
434
+ def config # :nodoc:
403
435
  @config ||= Application::Configuration.new(self.class.find_root(self.class.called_from))
404
436
  end
405
437
 
406
438
  attr_writer :config
407
439
 
408
440
  def secrets
441
+ Rails.deprecator.warn(<<~MSG.squish)
442
+ `Rails.application.secrets` is deprecated in favor of `Rails.application.credentials` and will be removed in Rails 7.2.
443
+ MSG
409
444
  @secrets ||= begin
410
445
  secrets = ActiveSupport::OrderedOptions.new
411
446
  files = config.paths["config/secrets"].existent
@@ -422,62 +457,78 @@ module Rails
422
457
  attr_writer :secrets, :credentials
423
458
 
424
459
  # The secret_key_base is used as the input secret to the application's key generator, which in turn
425
- # is used to create all MessageVerifiers/MessageEncryptors, including the ones that sign and encrypt cookies.
460
+ # is used to create all ActiveSupport::MessageVerifier and ActiveSupport::MessageEncryptor instances,
461
+ # including the ones that sign and encrypt cookies.
426
462
  #
427
463
  # In development and test, this is randomly generated and stored in a
428
- # temporary file in <tt>tmp/development_secret.txt</tt>.
464
+ # temporary file in <tt>tmp/local_secret.txt</tt>.
465
+ #
466
+ # You can also set <tt>ENV["SECRET_KEY_BASE_DUMMY"]</tt> to trigger the use of a randomly generated
467
+ # secret_key_base that's stored in a temporary file. This is useful when precompiling assets for
468
+ # production as part of a build step that otherwise does not need access to the production secrets.
429
469
  #
430
- # In all other environments, we look for it first in ENV["SECRET_KEY_BASE"],
431
- # then credentials.secret_key_base, and finally secrets.secret_key_base. For most applications,
470
+ # Dockerfile example: <tt>RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile</tt>.
471
+ #
472
+ # In all other environments, we look for it first in <tt>ENV["SECRET_KEY_BASE"]</tt>,
473
+ # then +credentials.secret_key_base+, and finally +secrets.secret_key_base+. For most applications,
432
474
  # the correct place to store it is in the encrypted credentials file.
433
475
  def secret_key_base
434
- if Rails.env.development? || Rails.env.test?
435
- secrets.secret_key_base ||= generate_development_secret
476
+ if Rails.env.local? || ENV["SECRET_KEY_BASE_DUMMY"]
477
+ config.secret_key_base ||= generate_local_secret
436
478
  else
437
479
  validate_secret_key_base(
438
- ENV["SECRET_KEY_BASE"] || credentials.secret_key_base || secrets.secret_key_base
480
+ ENV["SECRET_KEY_BASE"] || credentials.secret_key_base || begin
481
+ secret_skb = secrets_secret_key_base
482
+
483
+ if secret_skb.equal?(config.secret_key_base)
484
+ config.secret_key_base
485
+ else
486
+ Rails.deprecator.warn(<<~MSG.squish)
487
+ Your `secret_key_base is configured in `Rails.application.secrets`,
488
+ which is deprecated in favor of `Rails.application.credentials` and
489
+ will be removed in Rails 7.2.
490
+ MSG
491
+
492
+ secret_skb
493
+ end
494
+ end
439
495
  )
440
496
  end
441
497
  end
442
498
 
443
- # Decrypts the credentials hash as kept in +config/credentials.yml.enc+. This file is encrypted with
444
- # the Rails master key, which is either taken from <tt>ENV["RAILS_MASTER_KEY"]</tt> or from loading
445
- # +config/master.key+.
446
- # If specific credentials file exists for current environment, it takes precedence, thus for +production+
447
- # environment look first for +config/credentials/production.yml.enc+ with master key taken
448
- # from <tt>ENV["RAILS_MASTER_KEY"]</tt> or from loading +config/credentials/production.key+.
449
- # Default behavior can be overwritten by setting +config.credentials.content_path+ and +config.credentials.key_path+.
499
+ # Returns an ActiveSupport::EncryptedConfiguration instance for the
500
+ # credentials file specified by +config.credentials.content_path+.
501
+ #
502
+ # By default, +config.credentials.content_path+ will point to either
503
+ # <tt>config/credentials/#{environment}.yml.enc</tt> for the current
504
+ # environment (for example, +config/credentials/production.yml.enc+ for the
505
+ # +production+ environment), or +config/credentials.yml.enc+ if that file
506
+ # does not exist.
507
+ #
508
+ # The encryption key is taken from either <tt>ENV["RAILS_MASTER_KEY"]</tt>,
509
+ # or from the file specified by +config.credentials.key_path+. By default,
510
+ # +config.credentials.key_path+ will point to either
511
+ # <tt>config/credentials/#{environment}.key</tt> for the current
512
+ # environment, or +config/master.key+ if that file does not exist.
450
513
  def credentials
451
514
  @credentials ||= encrypted(config.credentials.content_path, key_path: config.credentials.key_path)
452
515
  end
453
516
 
454
- # Shorthand to decrypt any encrypted configurations or files.
455
- #
456
- # For any file added with <tt>rails encrypted:edit</tt> call +read+ to decrypt
457
- # the file with the master key.
458
- # The master key is either stored in +config/master.key+ or <tt>ENV["RAILS_MASTER_KEY"]</tt>.
459
- #
460
- # Rails.application.encrypted("config/mystery_man.txt.enc").read
461
- # # => "We've met before, haven't we?"
462
- #
463
- # It's also possible to interpret encrypted YAML files with +config+.
464
- #
465
- # Rails.application.encrypted("config/credentials.yml.enc").config
466
- # # => { next_guys_line: "I don't think so. Where was it you think we met?" }
467
- #
468
- # Any top-level configs are also accessible directly on the return value:
517
+ # Returns an ActiveSupport::EncryptedConfiguration instance for an encrypted
518
+ # file. By default, the encryption key is taken from either
519
+ # <tt>ENV["RAILS_MASTER_KEY"]</tt>, or from the +config/master.key+ file.
469
520
  #
470
- # Rails.application.encrypted("config/credentials.yml.enc").next_guys_line
471
- # # => "I don't think so. Where was it you think we met?"
521
+ # my_config = Rails.application.encrypted("config/my_config.enc")
472
522
  #
473
- # The files or configs can also be encrypted with a custom key. To decrypt with
474
- # a key in the +ENV+, use:
523
+ # my_config.read
524
+ # # => "foo:\n bar: 123\n"
475
525
  #
476
- # Rails.application.encrypted("config/special_tokens.yml.enc", env_key: "SPECIAL_TOKENS")
526
+ # my_config.foo.bar
527
+ # # => 123
477
528
  #
478
- # Or to decrypt with a file, that should be version control ignored, relative to +Rails.root+:
479
- #
480
- # Rails.application.encrypted("config/special_tokens.yml.enc", key_path: "config/special_tokens.key")
529
+ # Encrypted files can be edited with the <tt>bin/rails encrypted:edit</tt>
530
+ # command. (See the output of <tt>bin/rails encrypted:edit --help</tt> for
531
+ # more information.)
481
532
  def encrypted(path, key_path: "config/master.key", env_key: "RAILS_MASTER_KEY")
482
533
  ActiveSupport::EncryptedConfiguration.new(
483
534
  config_path: Rails.root.join(path),
@@ -487,11 +538,11 @@ module Rails
487
538
  )
488
539
  end
489
540
 
490
- def to_app #:nodoc:
541
+ def to_app # :nodoc:
491
542
  self
492
543
  end
493
544
 
494
- def helpers_paths #:nodoc:
545
+ def helpers_paths # :nodoc:
495
546
  config.helpers_paths
496
547
  end
497
548
 
@@ -511,19 +562,20 @@ module Rails
511
562
  ordered_railties.flatten - [self]
512
563
  end
513
564
 
565
+ def load_generators(app = self) # :nodoc:
566
+ app.ensure_generator_templates_added
567
+ super
568
+ end
569
+
514
570
  # Eager loads the application code.
515
571
  def eager_load!
516
- if Rails.autoloaders.zeitwerk_enabled?
517
- Rails.autoloaders.each(&:eager_load)
518
- else
519
- super
520
- end
572
+ Rails.autoloaders.each(&:eager_load)
521
573
  end
522
574
 
523
575
  protected
524
576
  alias :build_middleware_stack :app
525
577
 
526
- def run_tasks_blocks(app) #:nodoc:
578
+ def run_tasks_blocks(app) # :nodoc:
527
579
  railties.each { |r| r.run_tasks_blocks(app) }
528
580
  super
529
581
  load "rails/tasks.rb"
@@ -534,28 +586,28 @@ module Rails
534
586
  end
535
587
  end
536
588
 
537
- def run_generators_blocks(app) #:nodoc:
589
+ def run_generators_blocks(app) # :nodoc:
538
590
  railties.each { |r| r.run_generators_blocks(app) }
539
591
  super
540
592
  end
541
593
 
542
- def run_runner_blocks(app) #:nodoc:
594
+ def run_runner_blocks(app) # :nodoc:
543
595
  railties.each { |r| r.run_runner_blocks(app) }
544
596
  super
545
597
  end
546
598
 
547
- def run_console_blocks(app) #:nodoc:
599
+ def run_console_blocks(app) # :nodoc:
548
600
  railties.each { |r| r.run_console_blocks(app) }
549
601
  super
550
602
  end
551
603
 
552
- def run_server_blocks(app) #:nodoc:
604
+ def run_server_blocks(app) # :nodoc:
553
605
  railties.each { |r| r.run_server_blocks(app) }
554
606
  super
555
607
  end
556
608
 
557
609
  # Returns the ordered railties for this application considering railties_order.
558
- def ordered_railties #:nodoc:
610
+ def ordered_railties # :nodoc:
559
611
  @ordered_railties ||= begin
560
612
  order = config.railties_order.map do |railtie|
561
613
  if railtie == :main_app
@@ -577,7 +629,7 @@ module Rails
577
629
  end
578
630
  end
579
631
 
580
- def railties_initializers(current) #:nodoc:
632
+ def railties_initializers(current) # :nodoc:
581
633
  initializers = []
582
634
  ordered_railties.reverse.flatten.each do |r|
583
635
  if r == self
@@ -589,7 +641,7 @@ module Rails
589
641
  initializers
590
642
  end
591
643
 
592
- def default_middleware_stack #:nodoc:
644
+ def default_middleware_stack # :nodoc:
593
645
  default_stack = DefaultMiddlewareStack.new(self, config, paths)
594
646
  default_stack.build_stack
595
647
  end
@@ -604,21 +656,35 @@ module Rails
604
656
  end
605
657
  end
606
658
 
607
- private
608
- def generate_development_secret
609
- if secrets.secret_key_base.nil?
610
- key_file = Rails.root.join("tmp/development_secret.txt")
659
+ def ensure_generator_templates_added
660
+ configured_paths = config.generators.templates
661
+ configured_paths.unshift(*(paths["lib/templates"].existent - configured_paths))
662
+ end
611
663
 
612
- if !File.exist?(key_file)
664
+ private
665
+ def generate_local_secret
666
+ if config.secret_key_base.nil?
667
+ key_file = Rails.root.join("tmp/local_secret.txt")
668
+
669
+ if File.exist?(key_file)
670
+ config.secret_key_base = File.binread(key_file)
671
+ elsif secrets_secret_key_base
672
+ config.secret_key_base = secrets_secret_key_base
673
+ else
613
674
  random_key = SecureRandom.hex(64)
614
675
  FileUtils.mkdir_p(key_file.dirname)
615
676
  File.binwrite(key_file, random_key)
677
+ config.secret_key_base = File.binread(key_file)
616
678
  end
617
-
618
- secrets.secret_key_base = File.binread(key_file)
619
679
  end
620
680
 
621
- secrets.secret_key_base
681
+ config.secret_key_base
682
+ end
683
+
684
+ def secrets_secret_key_base
685
+ Rails.deprecator.silence do
686
+ secrets.secret_key_base
687
+ end
622
688
  end
623
689
 
624
690
  def build_request(env)
@@ -635,5 +701,14 @@ module Rails
635
701
  def coerce_same_site_protection(protection)
636
702
  protection.respond_to?(:call) ? protection : proc { protection }
637
703
  end
704
+
705
+ def filter_parameters
706
+ if config.precompile_filter_parameters
707
+ config.filter_parameters.replace(
708
+ ActiveSupport::ParameterFilter.precompile_filters(config.filter_parameters)
709
+ )
710
+ end
711
+ config.filter_parameters
712
+ end
638
713
  end
639
714
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rails::ApplicationController < ActionController::Base # :nodoc:
4
- self.view_paths = File.expand_path("templates", __dir__)
4
+ prepend_view_path File.expand_path("templates", __dir__)
5
5
  layout "application"
6
6
 
7
7
  before_action :disable_content_security_policy_nonce!
8
8
 
9
9
  content_security_policy do |policy|
10
- policy.script_src :unsafe_inline
11
- policy.style_src :unsafe_inline
10
+ policy.script_src :self, :unsafe_inline
11
+ policy.style_src :self, :unsafe_inline
12
12
  end
13
13
 
14
14
  private
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/inflector"
4
+
5
+ module Rails
6
+ class Autoloaders
7
+ module Inflector # :nodoc:
8
+ # Concurrent::Map is not needed. This is a private class, and overrides
9
+ # must be defined while the application boots.
10
+ @overrides = {}
11
+
12
+ def self.camelize(basename, _abspath)
13
+ @overrides[basename] || basename.camelize
14
+ end
15
+
16
+ def self.inflect(overrides)
17
+ @overrides.merge!(overrides)
18
+ end
19
+ end
20
+ end
21
+ end