railties 6.0.0.beta3 → 6.0.2.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +139 -8
  3. data/RDOC_MAIN.rdoc +3 -4
  4. data/README.rdoc +1 -1
  5. data/lib/rails/api/task.rb +1 -0
  6. data/lib/rails/application.rb +6 -3
  7. data/lib/rails/application/bootstrap.rb +2 -10
  8. data/lib/rails/application/configuration.rb +45 -1
  9. data/lib/rails/application/default_middleware_stack.rb +1 -0
  10. data/lib/rails/application/dummy_erb_compiler.rb +18 -0
  11. data/lib/rails/application/finisher.rb +44 -1
  12. data/lib/rails/autoloaders.rb +14 -2
  13. data/lib/rails/command/base.rb +4 -0
  14. data/lib/rails/command/environment_argument.rb +7 -4
  15. data/lib/rails/commands/console/console_command.rb +6 -0
  16. data/lib/rails/commands/credentials/USAGE +1 -1
  17. data/lib/rails/commands/credentials/credentials_command.rb +17 -3
  18. data/lib/rails/commands/dbconsole/dbconsole_command.rb +19 -7
  19. data/lib/rails/commands/dev/dev_command.rb +4 -2
  20. data/lib/rails/commands/encrypted/USAGE +28 -0
  21. data/lib/rails/commands/encrypted/encrypted_command.rb +1 -0
  22. data/lib/rails/commands/initializers/initializers_command.rb +7 -0
  23. data/lib/rails/commands/notes/notes_command.rb +1 -1
  24. data/lib/rails/commands/runner/runner_command.rb +7 -3
  25. data/lib/rails/commands/server/server_command.rb +8 -6
  26. data/lib/rails/engine.rb +35 -36
  27. data/lib/rails/engine/configuration.rb +3 -2
  28. data/lib/rails/gem_version.rb +2 -2
  29. data/lib/rails/generators.rb +2 -0
  30. data/lib/rails/generators/app_base.rb +5 -5
  31. data/lib/rails/generators/app_name.rb +2 -2
  32. data/lib/rails/generators/base.rb +4 -0
  33. data/lib/rails/generators/database.rb +1 -1
  34. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +6 -3
  35. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +8 -0
  36. data/lib/rails/generators/generated_attribute.rb +36 -10
  37. data/lib/rails/generators/named_base.rb +1 -1
  38. data/lib/rails/generators/rails/app/app_generator.rb +1 -0
  39. data/lib/rails/generators/rails/app/templates/Gemfile.tt +4 -4
  40. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +8 -0
  41. data/lib/rails/generators/rails/app/templates/bin/setup.tt +3 -2
  42. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
  43. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
  44. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -0
  45. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +2 -0
  46. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +10 -4
  47. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +3 -0
  48. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +12 -0
  49. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +3 -0
  50. data/lib/rails/generators/rails/app/templates/gitignore.tt +1 -0
  51. data/lib/rails/generators/rails/app/templates/package.json.tt +3 -3
  52. data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -1
  53. data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
  54. data/lib/rails/generators/rails/assets/assets_generator.rb +7 -0
  55. data/lib/rails/generators/rails/db/system/change/change_generator.rb +12 -2
  56. data/lib/rails/generators/rails/plugin/plugin_generator.rb +0 -15
  57. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +1 -0
  58. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +14 -0
  59. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
  60. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
  61. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
  62. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +7 -2
  63. data/lib/rails/info.rb +1 -1
  64. data/lib/rails/mailers_controller.rb +6 -3
  65. data/lib/rails/source_annotation_extractor.rb +19 -6
  66. data/lib/rails/tasks.rb +1 -0
  67. data/lib/rails/tasks/zeitwerk.rake +66 -0
  68. metadata +18 -13
  69. data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4b78369d9f271572d3a302573c3074369e2d00f9507ade58f17667c9dda5476
4
- data.tar.gz: b3afe11e12e754306480173cfa772222d9b998d27a232d209a64624604a91341
3
+ metadata.gz: cf37cc2a76f9cfbd932a8804269ee295aa31ef9f6f461c3868bc350425ad8263
4
+ data.tar.gz: 3e46350b318203d9db5c938f475c0fa09a850a87d1f80085b7feb990a19f12f4
5
5
  SHA512:
6
- metadata.gz: fc7ff12025bd5ae53ee9db3a985bbc6fc661d9f11aef9fdcd243e26a7dcd4c7186c12dd888479ebbd9f1da1204c031c9cdfaf34eab2e6411e81b63130a8167d3
7
- data.tar.gz: 612e651ac16761224f2de33b9ee6829309aaa685935d576a935e782762ef5be87b111e585df6741eefe67c5937819b15c3c5be856eae8c74afb3a3185928c6cb
6
+ metadata.gz: 545592751b707fd054ba604f505f3dd6dce218129fd7d1d1c3de5e9755dd4c76910294bf4801b65468f303b7f792e53ab6df8aa8b4c8dd3208764107a125f3be
7
+ data.tar.gz: c3cb4f31a6e9f8b35217893e2b73e3a15ba5ba5af5da591de817a6b492605da070fa5924306dd23f6f5862d4751e360a3977aa2675dbf72dcaf0e0cf2c30e7b9
@@ -1,6 +1,135 @@
1
+ ## Rails 6.0.2.rc2 (December 09, 2019) ##
2
+
3
+ * Fix the collision check for the scaffold generator.
4
+
5
+ *Ryan Robeson*
6
+
7
+ ## Rails 6.0.1 (November 5, 2019) ##
8
+
9
+ * The `zeitwerk:check` Rake task reports files outside the app's root
10
+ directory, as in engines loaded from gems.
11
+
12
+ *Xavier Noria*
13
+
14
+ * Fixed a possible error when using the evented file update checker.
15
+
16
+ *Yuji Yaginuma*
17
+
18
+ * The sqlite3 database files created by the parallel testing feature are
19
+ included in the default `.gitignore` file for newly-generated apps.
20
+
21
+ *Yasuo Honda*
22
+
23
+ * `rails new` generates a `.keep` file in `tmp/pids`. This fixes starting
24
+ a server via `rackup` instead of `rails server`.
25
+
26
+ *Rafael Mendonça França*
27
+
28
+
29
+ ## Rails 6.0.0 (August 16, 2019) ##
30
+
31
+ * `Rails.autoloaders.log!` is a logging shortcut to get the activity of the
32
+ loaders printed to standard output. May be handy for troubleshooting.
33
+
34
+ *Xavier Noria*
35
+
36
+
37
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
38
+
39
+ * The new configuration point `config.add_autoload_paths_to_load_path` allows
40
+ users to opt-out from adding autoload paths to `$LOAD_PATH`. This flag is
41
+ `true` by default, but it is recommended to be set to `false` in `:zeitwerk`
42
+ mode early, in `config/application.rb`.
43
+
44
+ Zeitwerk uses only absolute paths internally, and applications running in
45
+ `:zeitwerk` mode do not need `require_dependency`, so models, controllers,
46
+ jobs, etc. do not need to be in `$LOAD_PATH`. Setting this to `false` saves
47
+ Ruby from checking these directories when resolving `require` calls with
48
+ relative paths, and saves Bootsnap work and RAM, since it does not need to
49
+ build an index for them.
50
+
51
+ *Xavier Noria*
52
+
53
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
54
+
55
+ * Applications upgrading to Rails 6 can run the command
56
+
57
+ ```
58
+ bin/rails zeitwerk:check
59
+ ```
60
+
61
+ to check if the project structure they were using with the classic
62
+ autoloader is compatible with `:zeitwerk` mode.
63
+
64
+ *Matilda Smeds* & *Xavier Noria*
65
+
66
+ * Allow loading seeds without ActiveJob.
67
+
68
+ Fixes #35782
69
+
70
+ *Jeremy Weathers*
71
+
72
+ * `null: false` is set in the migrations by default for column pointed by
73
+ `belongs_to` / `references` association generated by model generator.
74
+
75
+ Also deprecate passing {required} to the model generator.
76
+
77
+ *Prathamesh Sonpatki*
78
+
79
+ * New applications get `config.cache_classes = false` in `config/environments/test.rb`
80
+ unless `--skip-spring`.
81
+
82
+ *Xavier Noria*
83
+
84
+ * Autoloading during initialization is deprecated.
85
+
86
+ *Xavier Noria*
87
+
88
+ * Only force `:async` ActiveJob adapter to `:inline` during seeding.
89
+
90
+ *BatedUrGonnaDie*
91
+
92
+ * The `connection` option of `rails dbconsole` command is deprecated in
93
+ favor of `database` option.
94
+
95
+ *Yuji Yaginuma*
96
+
97
+ * Replace `chromedriver-helper` gem with `webdrivers` in default Gemfile.
98
+ `chromedriver-helper` is deprecated as of March 31, 2019 and won't
99
+ receive any further updates.
100
+
101
+ *Guillermo Iguaran‮*
102
+
103
+ * Applications running in `:zeitwerk` mode that use `bootsnap` need
104
+ to upgrade `bootsnap` to at least 1.4.2.
105
+
106
+ *Xavier Noria*
107
+
108
+ * Add `config.disable_sandbox` option to Rails console.
109
+
110
+ This setting will disable `rails console --sandbox` mode, preventing
111
+ developer from accidentally starting a sandbox console,
112
+ which when left inactive, can cause the database server to run out of memory.
113
+
114
+ *Prem Sichanugrist*
115
+
116
+ * Add `-e/--environment` option to `rails initializers`.
117
+
118
+ *Yuji Yaginuma*
119
+
120
+
1
121
  ## Rails 6.0.0.beta3 (March 11, 2019) ##
2
122
 
3
- * No changes.
123
+ * Generate random development secrets
124
+
125
+ A random development secret is now generated to tmp/development_secret.txt
126
+
127
+ This avoids an issue where development mode servers were vulnerable to
128
+ remote code execution.
129
+
130
+ Fixes CVE-2019-5420
131
+
132
+ *Eileen M. Uchitelle*, *Aaron Patterson*, *John Hawthorn*
4
133
 
5
134
 
6
135
  ## Rails 6.0.0.beta2 (February 25, 2019) ##
@@ -49,7 +178,9 @@
49
178
  gsub Gemfile
50
179
  ```
51
180
 
52
- The change command copies a template `config/database.yml` with the target database adapter into your app, and replaces your database gem with the target database gem.
181
+ The change command copies a template `config/database.yml` with
182
+ the target database adapter into your app, and replaces your database gem
183
+ with the target database gem.
53
184
 
54
185
  *Gannon McGibbon*
55
186
 
@@ -73,9 +204,9 @@
73
204
 
74
205
  *George Claghorn*
75
206
 
76
- * Introduce guard against DNS rebinding attacks
207
+ * Introduce guard against DNS rebinding attacks.
77
208
 
78
- The `ActionDispatch::HostAuthorization` is a new middleware that prevent
209
+ The `ActionDispatch::HostAuthorization` is a new middleware that prevents
79
210
  against DNS rebinding and other `Host` header attacks. It is included in
80
211
  the development environment by default with the following configuration:
81
212
 
@@ -93,7 +224,7 @@
93
224
  Rails.application.config.hosts << "product.com"
94
225
 
95
226
  The host of a request is checked against the `hosts` entries with the case
96
- operator (`#===`), which lets `hosts` support entries of type `RegExp`,
227
+ operator (`#===`), which lets `hosts` support entries of type `Regexp`,
97
228
  `Proc` and `IPAddr` to name a few. Here is an example with a regexp.
98
229
 
99
230
  # Allow requests from subdomains like `www.product.com` and
@@ -183,7 +314,7 @@
183
314
  The encryption key can be in `ENV["RAILS_MASTER_KEY"]` or `config/credentials/production.key`.
184
315
 
185
316
  Environment credentials overrides can be edited with `rails credentials:edit --environment production`.
186
- If no override is setup for the passed environment, it will be created.
317
+ If no override is set up for the passed environment, it will be created.
187
318
 
188
319
  Additionally, the default lookup paths can be overwritten with these configs:
189
320
 
@@ -273,9 +404,9 @@
273
404
 
274
405
  *Jose Luis Duran*
275
406
 
276
- * Deprecate support for using the `HOST` environment to specify the server IP.
407
+ * Deprecate support for using the `HOST` environment variable to specify the server IP.
277
408
 
278
- The `BINDING` environment should be used instead.
409
+ The `BINDING` environment variable should be used instead.
279
410
 
280
411
  Fixes #29516.
281
412
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  \Rails is a web-application framework that includes everything needed to
6
6
  create database-backed web applications according to the
7
- {Model-View-Controller (MVC)}[http://en.wikipedia.org/wiki/Model-view-controller]
7
+ {Model-View-Controller (MVC)}[https://en.wikipedia.org/wiki/Model-view-controller]
8
8
  pattern.
9
9
 
10
10
  Understanding the MVC pattern is key to understanding \Rails. MVC divides your
@@ -79,8 +79,7 @@ and may also be used independently outside \Rails.
79
79
  * The \README file created within your application.
80
80
  * {Getting Started with \Rails}[https://guides.rubyonrails.org/getting_started.html].
81
81
  * {Ruby on \Rails Guides}[https://guides.rubyonrails.org].
82
- * {The API Documentation}[http://api.rubyonrails.org].
83
- * {Ruby on \Rails Tutorial}[https://www.railstutorial.org/book].
82
+ * {The API Documentation}[https://api.rubyonrails.org].
84
83
 
85
84
  == Contributing
86
85
 
@@ -88,7 +87,7 @@ We encourage you to contribute to Ruby on \Rails! Please check out the
88
87
  {Contributing to Ruby on \Rails guide}[https://guides.rubyonrails.org/contributing_to_ruby_on_rails.html] for guidelines about how to proceed. {Join us!}[http://contributors.rubyonrails.org]
89
88
 
90
89
  Trying to report a possible security vulnerability in \Rails? Please
91
- check out our {security policy}[http://rubyonrails.org/security/] for
90
+ check out our {security policy}[https://rubyonrails.org/security/] for
92
91
  guidelines about how to proceed.
93
92
 
94
93
  Everyone interacting in \Rails and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the \Rails {code of conduct}[http://rubyonrails.org/conduct/].
@@ -29,7 +29,7 @@ Railties is released under the MIT license:
29
29
 
30
30
  API documentation is at
31
31
 
32
- * http://api.rubyonrails.org
32
+ * https://api.rubyonrails.org
33
33
 
34
34
  Bug reports can be filed for the Ruby on Rails project here:
35
35
 
@@ -18,6 +18,7 @@ module Rails
18
18
  include: %w(
19
19
  README.rdoc
20
20
  lib/active_record/**/*.rb
21
+ lib/arel.rb
21
22
  )
22
23
  },
23
24
 
@@ -270,7 +270,8 @@ module Rails
270
270
  "action_dispatch.use_cookies_with_metadata" => config.action_dispatch.use_cookies_with_metadata,
271
271
  "action_dispatch.content_security_policy" => config.content_security_policy,
272
272
  "action_dispatch.content_security_policy_report_only" => config.content_security_policy_report_only,
273
- "action_dispatch.content_security_policy_nonce_generator" => config.content_security_policy_nonce_generator
273
+ "action_dispatch.content_security_policy_nonce_generator" => config.content_security_policy_nonce_generator,
274
+ "action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives
274
275
  )
275
276
  end
276
277
  end
@@ -349,7 +350,7 @@ module Rails
349
350
  files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
350
351
 
351
352
  ActiveSupport::Dependencies.autoload_paths.each do |path|
352
- dirs[path.to_s] = [:rb]
353
+ File.file?(path) ? files << path.to_s : dirs[path.to_s] = [:rb]
353
354
  end
354
355
 
355
356
  [files, dirs]
@@ -409,7 +410,8 @@ module Rails
409
410
  # The secret_key_base is used as the input secret to the application's key generator, which in turn
410
411
  # is used to create all MessageVerifiers/MessageEncryptors, including the ones that sign and encrypt cookies.
411
412
  #
412
- # In test and development, this is simply derived as a MD5 hash of the application's name.
413
+ # In development and test, this is randomly generated and stored in a
414
+ # temporary file in <tt>tmp/development_secret.txt</tt>.
413
415
  #
414
416
  # In all other environments, we look for it first in ENV["SECRET_KEY_BASE"],
415
417
  # then credentials.secret_key_base, and finally secrets.secret_key_base. For most applications,
@@ -587,6 +589,7 @@ module Rails
587
589
 
588
590
  if !File.exist?(key_file)
589
591
  random_key = SecureRandom.hex(64)
592
+ FileUtils.mkdir_p(key_file.dirname)
590
593
  File.binwrite(key_file, random_key)
591
594
  end
592
595
 
@@ -34,20 +34,12 @@ INFO
34
34
  # Initialize the logger early in the stack in case we need to log some deprecation.
35
35
  initializer :initialize_logger, group: :all do
36
36
  Rails.logger ||= config.logger || begin
37
- path = config.paths["log"].first
38
- unless File.exist? File.dirname path
39
- FileUtils.mkdir_p File.dirname path
40
- end
41
-
42
- f = File.open path, "a"
43
- f.binmode
44
- f.sync = config.autoflush_log # if true make sure every write flushes
45
-
46
- logger = ActiveSupport::Logger.new f
37
+ logger = ActiveSupport::Logger.new(config.default_log_file)
47
38
  logger.formatter = config.log_formatter
48
39
  logger = ActiveSupport::TaggedLogging.new(logger)
49
40
  logger
50
41
  rescue StandardError
42
+ path = config.paths["log"].first
51
43
  logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDERR))
52
44
  logger.level = ActiveSupport::Logger::WARN
53
45
  logger.warn(
@@ -18,7 +18,8 @@ module Rails
18
18
  :session_options, :time_zone, :reload_classes_only_on_change,
19
19
  :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading,
20
20
  :read_encrypted_secrets, :log_level, :content_security_policy_report_only,
21
- :content_security_policy_nonce_generator, :require_master_key, :credentials
21
+ :content_security_policy_nonce_generator, :content_security_policy_nonce_directives,
22
+ :require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path
22
23
 
23
24
  attr_reader :encoding, :api_only, :loaded_config_version, :autoloader
24
25
 
@@ -59,14 +60,18 @@ module Rails
59
60
  @content_security_policy = nil
60
61
  @content_security_policy_report_only = false
61
62
  @content_security_policy_nonce_generator = nil
63
+ @content_security_policy_nonce_directives = nil
62
64
  @require_master_key = false
63
65
  @loaded_config_version = nil
64
66
  @credentials = ActiveSupport::OrderedOptions.new
65
67
  @credentials.content_path = default_credentials_content_path
66
68
  @credentials.key_path = default_credentials_key_path
67
69
  @autoloader = :classic
70
+ @disable_sandbox = false
71
+ @add_autoload_paths_to_load_path = true
68
72
  end
69
73
 
74
+ # Loads default configurations. See {the result of the method for each version}[https://guides.rubyonrails.org/configuring.html#results-of-config-load-defaults].
70
75
  def load_defaults(target_version)
71
76
  case target_version.to_s
72
77
  when "5.0"
@@ -126,6 +131,7 @@ module Rails
126
131
 
127
132
  if respond_to?(:action_dispatch)
128
133
  action_dispatch.use_cookies_with_metadata = true
134
+ action_dispatch.return_only_media_type_on_content_type = false
129
135
  end
130
136
 
131
137
  if respond_to?(:action_mailer)
@@ -139,6 +145,12 @@ module Rails
139
145
  if respond_to?(:active_storage)
140
146
  active_storage.queues.analysis = :active_storage_analysis
141
147
  active_storage.queues.purge = :active_storage_purge
148
+
149
+ active_storage.replace_on_assign_to_many = true
150
+ end
151
+
152
+ if respond_to?(:active_record)
153
+ active_record.collection_cache_versioning = true
142
154
  end
143
155
  else
144
156
  raise "Unknown version #{target_version.to_s.inspect}"
@@ -184,6 +196,26 @@ module Rails
184
196
  end
185
197
  end
186
198
 
199
+ # Load the database YAML without evaluating ERB. This allows us to
200
+ # create the rake tasks for multiple databases without filling in the
201
+ # configuration values or loading the environment. Do not use this
202
+ # method.
203
+ #
204
+ # This uses a DummyERB custom compiler so YAML can ignore the ERB
205
+ # tags and load the database.yml for the rake tasks.
206
+ def load_database_yaml # :nodoc:
207
+ if path = paths["config/database"].existent.first
208
+ require "rails/application/dummy_erb_compiler"
209
+
210
+ yaml = Pathname.new(path)
211
+ erb = DummyERB.new(yaml.read)
212
+
213
+ YAML.load(erb.result) || {}
214
+ else
215
+ {}
216
+ end
217
+ end
218
+
187
219
  # Loads and returns the entire raw configuration of database from
188
220
  # values stored in <tt>config/database.yml</tt>.
189
221
  def database_configuration
@@ -282,6 +314,18 @@ module Rails
282
314
  end
283
315
  end
284
316
 
317
+ def default_log_file
318
+ path = paths["log"].first
319
+ unless File.exist? File.dirname path
320
+ FileUtils.mkdir_p File.dirname path
321
+ end
322
+
323
+ f = File.open path, "a"
324
+ f.binmode
325
+ f.sync = autoflush_log # if true make sure every write flushes
326
+ f
327
+ end
328
+
285
329
  class Custom #:nodoc:
286
330
  def initialize
287
331
  @configurations = Hash.new
@@ -49,6 +49,7 @@ module Rails
49
49
  middleware.use ::Rails::Rack::Logger, config.log_tags
50
50
  middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app
51
51
  middleware.use ::ActionDispatch::DebugExceptions, app, config.debug_exception_response_format
52
+ middleware.use ::ActionDispatch::ActionableExceptions
52
53
 
53
54
  unless config.cache_classes
54
55
  middleware.use ::ActionDispatch::Reloader, app.reloader
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # These classes are used to strip out the ERB configuration
4
+ # values so we can evaluate the database.yml without evaluating
5
+ # the ERB values.
6
+ class DummyERB < ERB # :nodoc:
7
+ def make_compiler(trim_mode)
8
+ DummyCompiler.new trim_mode
9
+ end
10
+ end
11
+
12
+ class DummyCompiler < ERB::Compiler # :nodoc:
13
+ def compile_content(stag, out)
14
+ if stag == "<%="
15
+ out.push "_erbout << ''"
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/string/inflections"
4
+ require "active_support/core_ext/array/conversions"
5
+
3
6
  module Rails
4
7
  class Application
5
8
  module Finisher
@@ -21,10 +24,50 @@ module Rails
21
24
  end
22
25
  end
23
26
 
27
+ # This will become an error if/when we remove classic mode. The plan is
28
+ # autoloaders won't be configured up to this point in the finisher, so
29
+ # constants just won't be found, raising regular NameError exceptions.
30
+ initializer :warn_if_autoloaded, before: :let_zeitwerk_take_over do
31
+ next if config.cache_classes
32
+ next if ActiveSupport::Dependencies.autoloaded_constants.empty?
33
+
34
+ autoloaded = ActiveSupport::Dependencies.autoloaded_constants
35
+ constants = "constant".pluralize(autoloaded.size)
36
+ enum = autoloaded.to_sentence
37
+ have = autoloaded.size == 1 ? "has" : "have"
38
+ these = autoloaded.size == 1 ? "This" : "These"
39
+ example = autoloaded.first
40
+ example_klass = example.constantize.class
41
+
42
+ if config.autoloader == :zeitwerk
43
+ ActiveSupport::DescendantsTracker.clear
44
+ ActiveSupport::Dependencies.clear
45
+
46
+ unload_message = "#{these} autoloaded #{constants} #{have} been unloaded."
47
+ else
48
+ unload_message = "`config.autoloader` is set to `#{config.autoloader}`. #{these} autoloaded #{constants} would have been unloaded if `config.autoloader` had been set to `:zeitwerk`."
49
+ end
50
+
51
+ ActiveSupport::Deprecation.warn(<<~WARNING)
52
+ Initialization autoloaded the #{constants} #{enum}.
53
+
54
+ Being able to do this is deprecated. Autoloading during initialization is going
55
+ to be an error condition in future versions of Rails.
56
+
57
+ Reloading does not reboot the application, and therefore code executed during
58
+ initialization does not run again. So, if you reload #{example}, for example,
59
+ the expected changes won't be reflected in that stale #{example_klass} object.
60
+
61
+ #{unload_message}
62
+
63
+ Please, check the "Autoloading and Reloading Constants" guide for solutions.
64
+ WARNING
65
+ end
66
+
24
67
  initializer :let_zeitwerk_take_over do
25
68
  if config.autoloader == :zeitwerk
26
69
  require "active_support/dependencies/zeitwerk_integration"
27
- ActiveSupport::Dependencies::ZeitwerkIntegration.take_over
70
+ ActiveSupport::Dependencies::ZeitwerkIntegration.take_over(enable_reloading: !config.cache_classes)
28
71
  end
29
72
  end
30
73