railties 6.1.6 → 7.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +93 -412
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +16 -16
- data/README.rdoc +0 -1
- data/lib/rails/app_updater.rb +2 -4
- data/lib/rails/application/bootstrap.rb +17 -5
- data/lib/rails/application/configuration.rb +52 -31
- data/lib/rails/application/default_middleware_stack.rb +6 -3
- data/lib/rails/application/finisher.rb +43 -85
- data/lib/rails/application/routes_reloader.rb +8 -0
- data/lib/rails/application.rb +24 -50
- data/lib/rails/application_controller.rb +2 -2
- data/lib/rails/autoloaders/inflector.rb +21 -0
- data/lib/rails/autoloaders.rb +12 -16
- data/lib/rails/code_statistics.rb +2 -2
- data/lib/rails/code_statistics_calculator.rb +10 -1
- data/lib/rails/command/base.rb +26 -12
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +1 -1
- data/lib/rails/command.rb +8 -5
- data/lib/rails/commands/credentials/USAGE +4 -2
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +26 -16
- data/lib/rails/commands/credentials/credentials_command.rb +6 -2
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +16 -15
- data/lib/rails/commands/help/USAGE +3 -2
- data/lib/rails/commands/runner/runner_command.rb +3 -2
- data/lib/rails/commands/server/server_command.rb +2 -5
- data/lib/rails/configuration.rb +18 -23
- data/lib/rails/engine/configuration.rb +2 -2
- data/lib/rails/engine.rb +23 -27
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions/create_migration.rb +2 -4
- data/lib/rails/generators/actions.rb +35 -13
- data/lib/rails/generators/app_base.rb +66 -102
- data/lib/rails/generators/app_name.rb +1 -1
- data/lib/rails/generators/base.rb +9 -13
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +5 -27
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
- data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +20 -0
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +7 -16
- data/lib/rails/generators/erb.rb +1 -1
- data/lib/rails/generators/generated_attribute.rb +40 -4
- data/lib/rails/generators/migration.rb +2 -6
- data/lib/rails/generators/model_helpers.rb +1 -1
- data/lib/rails/generators/named_base.rb +1 -1
- data/lib/rails/generators/rails/app/app_generator.rb +44 -88
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +41 -52
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +3 -10
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +1 -4
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +0 -3
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -14
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -11
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +9 -15
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +2 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +0 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +85 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +3 -3
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +3 -0
- data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +0 -5
- data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
- data/lib/rails/generators/rails/controller/controller_generator.rb +1 -2
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +0 -4
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +1 -1
- data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +40 -15
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +4 -2
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +9 -9
- data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +4 -4
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -5
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +3 -3
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +0 -19
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -5
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +6 -10
- data/lib/rails/generators/resource_helpers.rb +2 -2
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +5 -5
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +3 -3
- data/lib/rails/generators/testing/behaviour.rb +1 -2
- data/lib/rails/generators.rb +9 -22
- data/lib/rails/info.rb +1 -1
- data/lib/rails/info_controller.rb +1 -3
- data/lib/rails/initializable.rb +1 -1
- data/lib/rails/mailers_controller.rb +2 -4
- data/lib/rails/rack/logger.rb +0 -1
- data/lib/rails/railtie/configuration.rb +1 -2
- data/lib/rails/railtie.rb +9 -9
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/tasks/framework.rake +2 -8
- data/lib/rails/tasks/statistics.rake +3 -1
- data/lib/rails/tasks/tmp.rake +8 -1
- data/lib/rails/tasks/yarn.rake +5 -1
- data/lib/rails/tasks/zeitwerk.rake +2 -10
- data/lib/rails/templates/layouts/application.html.erb +15 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +12 -10
- data/lib/rails/templates/rails/welcome/index.html.erb +3 -0
- data/lib/rails/test_unit/railtie.rb +0 -4
- data/lib/rails/test_unit/runner.rb +7 -5
- data/lib/rails/test_unit/testing.rake +4 -9
- data/lib/rails.rb +1 -0
- metadata +37 -40
- data/lib/rails/.DS_Store +0 -0
- data/lib/rails/command/spellchecker.rb +0 -57
- data/lib/rails/generators/css/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -18
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +0 -6
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +0 -5
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +0 -23
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +0 -13
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -16
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb.tt +0 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb.tt +0 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -67
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +0 -6
- data/lib/rails/generators/rails/app/templates/package.json.tt +0 -11
- data/lib/rails/generators/rails/assets/USAGE +0 -16
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -26
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
data/lib/rails/app_updater.rb
CHANGED
@@ -13,7 +13,7 @@ module Rails
|
|
13
13
|
def app_generator
|
14
14
|
@app_generator ||= begin
|
15
15
|
gen = Rails::Generators::AppGenerator.new ["rails"], generator_options, destination_root: Rails.root
|
16
|
-
File.exist?(Rails.root.join("config", "application.rb"))
|
16
|
+
gen.send(:valid_const?) unless File.exist?(Rails.root.join("config", "application.rb"))
|
17
17
|
gen
|
18
18
|
end
|
19
19
|
end
|
@@ -21,15 +21,13 @@ module Rails
|
|
21
21
|
private
|
22
22
|
def generator_options
|
23
23
|
options = { api: !!Rails.application.config.api_only, update: true }
|
24
|
-
options[:skip_javascript] = !File.exist?(Rails.root.join("bin", "yarn"))
|
25
24
|
options[:skip_active_record] = !defined?(ActiveRecord::Railtie)
|
26
25
|
options[:skip_active_storage] = !defined?(ActiveStorage::Engine) || !defined?(ActiveRecord::Railtie)
|
27
26
|
options[:skip_action_mailer] = !defined?(ActionMailer::Railtie)
|
28
27
|
options[:skip_action_cable] = !defined?(ActionCable::Engine)
|
29
28
|
options[:skip_sprockets] = !defined?(Sprockets::Railtie)
|
30
|
-
options[:skip_puma] = !defined?(Puma)
|
31
29
|
options[:skip_bootsnap] = !defined?(Bootsnap)
|
32
|
-
options[:
|
30
|
+
options[:updating] = true
|
33
31
|
options
|
34
32
|
end
|
35
33
|
end
|
@@ -44,7 +44,7 @@ module Rails
|
|
44
44
|
logger.level = ActiveSupport::Logger::WARN
|
45
45
|
logger.warn(
|
46
46
|
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is writable " \
|
47
|
-
"(
|
47
|
+
"(i.e. make it writable for user and group: chmod 0664 #{path}). " \
|
48
48
|
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
|
49
49
|
)
|
50
50
|
logger
|
@@ -59,14 +59,26 @@ module Rails
|
|
59
59
|
Rails.cache = ActiveSupport::Cache.lookup_store(*config.cache_store)
|
60
60
|
|
61
61
|
if Rails.cache.respond_to?(:middleware)
|
62
|
-
config.middleware.
|
62
|
+
config.middleware.insert_after(ActionDispatch::Executor, Rails.cache.middleware)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
#
|
68
|
-
|
69
|
-
|
67
|
+
# We setup the once autoloader this early so that engines and applications
|
68
|
+
# are able to autoload from these paths during initialization.
|
69
|
+
initializer :setup_once_autoloader do
|
70
|
+
autoloader = Rails.autoloaders.once
|
71
|
+
|
72
|
+
ActiveSupport::Dependencies.autoload_once_paths.freeze
|
73
|
+
ActiveSupport::Dependencies.autoload_once_paths.uniq.each do |path|
|
74
|
+
# Zeitwerk only accepts existing directories in `push_dir`.
|
75
|
+
next unless File.directory?(path)
|
76
|
+
|
77
|
+
autoloader.push_dir(path)
|
78
|
+
autoloader.do_not_eager_load(path) unless ActiveSupport::Dependencies.eager_load?(path)
|
79
|
+
end
|
80
|
+
|
81
|
+
autoloader.setup
|
70
82
|
end
|
71
83
|
|
72
84
|
initializer :bootstrap_hook, group: :all do |app|
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require "ipaddr"
|
4
4
|
require "active_support/core_ext/kernel/reporting"
|
5
|
-
require "active_support/core_ext/symbol/starts_ends_with"
|
6
5
|
require "active_support/file_update_checker"
|
7
6
|
require "active_support/configuration_file"
|
8
7
|
require "rails/engine/configuration"
|
@@ -24,7 +23,7 @@ module Rails
|
|
24
23
|
:require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path,
|
25
24
|
:rake_eager_load
|
26
25
|
|
27
|
-
attr_reader :encoding, :api_only, :loaded_config_version
|
26
|
+
attr_reader :encoding, :api_only, :loaded_config_version
|
28
27
|
|
29
28
|
def initialize(*)
|
30
29
|
super
|
@@ -34,11 +33,8 @@ module Rails
|
|
34
33
|
@filter_parameters = []
|
35
34
|
@filter_redirect = []
|
36
35
|
@helpers_paths = []
|
37
|
-
if Rails.env.development?
|
38
|
-
|
39
|
-
else
|
40
|
-
@hosts = []
|
41
|
-
end
|
36
|
+
@hosts = Array(([".localhost", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")] if Rails.env.development?))
|
37
|
+
@hosts.concat(ENV["RAILS_DEVELOPMENT_HOSTS"].to_s.split(",").map(&:strip)) if Rails.env.development?
|
42
38
|
@host_authorization = {}
|
43
39
|
@public_file_server = ActiveSupport::OrderedOptions.new
|
44
40
|
@public_file_server.enabled = true
|
@@ -74,7 +70,6 @@ module Rails
|
|
74
70
|
@credentials = ActiveSupport::OrderedOptions.new
|
75
71
|
@credentials.content_path = default_credentials_content_path
|
76
72
|
@credentials.key_path = default_credentials_key_path
|
77
|
-
@autoloader = :classic
|
78
73
|
@disable_sandbox = false
|
79
74
|
@add_autoload_paths_to_load_path = true
|
80
75
|
@permissions_policy = nil
|
@@ -120,7 +115,7 @@ module Rails
|
|
120
115
|
|
121
116
|
if respond_to?(:active_support)
|
122
117
|
active_support.use_authenticated_message_encryption = true
|
123
|
-
active_support.hash_digest_class = ::Digest::SHA1
|
118
|
+
active_support.hash_digest_class = OpenSSL::Digest::SHA1
|
124
119
|
end
|
125
120
|
|
126
121
|
if respond_to?(:action_controller)
|
@@ -133,8 +128,6 @@ module Rails
|
|
133
128
|
when "6.0"
|
134
129
|
load_defaults "5.2"
|
135
130
|
|
136
|
-
self.autoloader = :zeitwerk if RUBY_ENGINE == "ruby"
|
137
|
-
|
138
131
|
if respond_to?(:action_view)
|
139
132
|
action_view.default_enforce_utf8 = false
|
140
133
|
end
|
@@ -160,17 +153,11 @@ module Rails
|
|
160
153
|
when "6.1"
|
161
154
|
load_defaults "6.0"
|
162
155
|
|
163
|
-
self.autoloader = :zeitwerk if %w[ruby truffleruby].include?(RUBY_ENGINE)
|
164
|
-
|
165
156
|
if respond_to?(:active_record)
|
166
157
|
active_record.has_many_inversing = true
|
167
158
|
active_record.legacy_connection_handling = false
|
168
159
|
end
|
169
160
|
|
170
|
-
if respond_to?(:active_storage)
|
171
|
-
active_storage.track_variants = true
|
172
|
-
end
|
173
|
-
|
174
161
|
if respond_to?(:active_job)
|
175
162
|
active_job.retry_jitter = 0.15
|
176
163
|
active_job.skip_after_callbacks_if_terminated = true
|
@@ -191,6 +178,8 @@ module Rails
|
|
191
178
|
end
|
192
179
|
|
193
180
|
if respond_to?(:active_storage)
|
181
|
+
active_storage.track_variants = true
|
182
|
+
|
194
183
|
active_storage.queues.analysis = nil
|
195
184
|
active_storage.queues.purge = nil
|
196
185
|
end
|
@@ -205,6 +194,50 @@ module Rails
|
|
205
194
|
end
|
206
195
|
|
207
196
|
ActiveSupport.utc_to_local_returns_utc_offset_times = true
|
197
|
+
when "7.0"
|
198
|
+
load_defaults "6.1"
|
199
|
+
|
200
|
+
if respond_to?(:action_dispatch)
|
201
|
+
action_dispatch.return_only_request_media_type_on_content_type = false
|
202
|
+
action_dispatch.cookies_serializer = :json
|
203
|
+
end
|
204
|
+
|
205
|
+
if respond_to?(:action_controller)
|
206
|
+
action_controller.silence_disabled_session_errors = false
|
207
|
+
end
|
208
|
+
|
209
|
+
if respond_to?(:action_view)
|
210
|
+
action_view.button_to_generates_button_tag = true
|
211
|
+
action_view.apply_stylesheet_media_default = false
|
212
|
+
end
|
213
|
+
|
214
|
+
if respond_to?(:active_support)
|
215
|
+
active_support.hash_digest_class = OpenSSL::Digest::SHA256
|
216
|
+
active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256
|
217
|
+
active_support.remove_deprecated_time_with_zone_name = true
|
218
|
+
active_support.cache_format_version = 7.0
|
219
|
+
end
|
220
|
+
|
221
|
+
if respond_to?(:action_mailer)
|
222
|
+
action_mailer.smtp_timeout = 5
|
223
|
+
end
|
224
|
+
|
225
|
+
if respond_to?(:active_storage)
|
226
|
+
active_storage.video_preview_arguments =
|
227
|
+
"-vf 'select=eq(n\\,0)+eq(key\\,1)+gt(scene\\,0.015),loop=loop=-1:size=2,trim=start_frame=1'" \
|
228
|
+
" -frames:v 1 -f image2"
|
229
|
+
|
230
|
+
active_storage.variant_processor = :vips
|
231
|
+
end
|
232
|
+
|
233
|
+
if respond_to?(:active_record)
|
234
|
+
active_record.verify_foreign_keys_for_fixtures = true
|
235
|
+
active_record.partial_inserts = false
|
236
|
+
end
|
237
|
+
|
238
|
+
if respond_to?(:action_controller)
|
239
|
+
action_controller.raise_on_open_redirects = true
|
240
|
+
end
|
208
241
|
else
|
209
242
|
raise "Unknown version #{target_version.to_s.inspect}"
|
210
243
|
end
|
@@ -335,7 +368,7 @@ module Rails
|
|
335
368
|
end
|
336
369
|
end
|
337
370
|
|
338
|
-
def session_store?
|
371
|
+
def session_store? # :nodoc:
|
339
372
|
@session_store
|
340
373
|
end
|
341
374
|
|
@@ -359,18 +392,6 @@ module Rails
|
|
359
392
|
end
|
360
393
|
end
|
361
394
|
|
362
|
-
def autoloader=(autoloader)
|
363
|
-
case autoloader
|
364
|
-
when :classic
|
365
|
-
@autoloader = autoloader
|
366
|
-
when :zeitwerk
|
367
|
-
require "zeitwerk"
|
368
|
-
@autoloader = autoloader
|
369
|
-
else
|
370
|
-
raise ArgumentError, "config.autoloader may be :classic or :zeitwerk, got #{autoloader.inspect} instead"
|
371
|
-
end
|
372
|
-
end
|
373
|
-
|
374
395
|
def default_log_file
|
375
396
|
path = paths["log"].first
|
376
397
|
unless File.exist? File.dirname path
|
@@ -383,7 +404,7 @@ module Rails
|
|
383
404
|
f
|
384
405
|
end
|
385
406
|
|
386
|
-
class Custom
|
407
|
+
class Custom # :nodoc:
|
387
408
|
def initialize
|
388
409
|
@configurations = Hash.new
|
389
410
|
end
|
@@ -42,7 +42,7 @@ module Rails
|
|
42
42
|
|
43
43
|
middleware.use ::ActionDispatch::Executor, app.executor
|
44
44
|
|
45
|
-
middleware.use ::
|
45
|
+
middleware.use ::ActionDispatch::MiddlewareStack::FakeRuntime
|
46
46
|
middleware.use ::Rack::MethodOverride unless config.api_only
|
47
47
|
middleware.use ::ActionDispatch::RequestId, header: config.action_dispatch.request_id_header
|
48
48
|
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
|
@@ -50,7 +50,10 @@ module Rails
|
|
50
50
|
middleware.use ::Rails::Rack::Logger, config.log_tags
|
51
51
|
middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app
|
52
52
|
middleware.use ::ActionDispatch::DebugExceptions, app, config.debug_exception_response_format
|
53
|
-
|
53
|
+
|
54
|
+
if config.consider_all_requests_local
|
55
|
+
middleware.use ::ActionDispatch::ActionableExceptions
|
56
|
+
end
|
54
57
|
|
55
58
|
unless config.cache_classes
|
56
59
|
middleware.use ::ActionDispatch::Reloader, app.reloader
|
@@ -64,10 +67,10 @@ module Rails
|
|
64
67
|
config.session_options[:secure] = true
|
65
68
|
end
|
66
69
|
middleware.use config.session_store, config.session_options
|
67
|
-
middleware.use ::ActionDispatch::Flash
|
68
70
|
end
|
69
71
|
|
70
72
|
unless config.api_only
|
73
|
+
middleware.use ::ActionDispatch::Flash
|
71
74
|
middleware.use ::ActionDispatch::ContentSecurityPolicy::Middleware
|
72
75
|
middleware.use ::ActionDispatch::PermissionsPolicy::Middleware
|
73
76
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "zeitwerk"
|
3
4
|
require "active_support/core_ext/string/inflections"
|
4
5
|
require "active_support/core_ext/array/conversions"
|
6
|
+
require "active_support/descendants_tracker"
|
7
|
+
require "active_support/dependencies"
|
5
8
|
|
6
9
|
module Rails
|
7
10
|
class Application
|
@@ -12,88 +15,34 @@ module Rails
|
|
12
15
|
config.generators.templates.unshift(*paths["lib/templates"].existent)
|
13
16
|
end
|
14
17
|
|
15
|
-
initializer :
|
16
|
-
|
17
|
-
ActiveSupport::Dependencies.autoload_paths
|
18
|
+
initializer :setup_main_autoloader do
|
19
|
+
autoloader = Rails.autoloaders.main
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end_error
|
24
|
-
end
|
25
|
-
end
|
21
|
+
ActiveSupport::Dependencies.autoload_paths.freeze
|
22
|
+
ActiveSupport::Dependencies.autoload_paths.uniq.each do |path|
|
23
|
+
# Zeitwerk only accepts existing directories in `push_dir`.
|
24
|
+
next unless File.directory?(path)
|
26
25
|
|
27
|
-
|
28
|
-
|
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`."
|
26
|
+
autoloader.push_dir(path)
|
27
|
+
autoloader.do_not_eager_load(path) unless ActiveSupport::Dependencies.eager_load?(path)
|
49
28
|
end
|
50
29
|
|
51
|
-
|
52
|
-
|
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
|
-
In order to autoload safely at boot time, please wrap your code in a reloader
|
64
|
-
callback this way:
|
30
|
+
unless config.cache_classes
|
31
|
+
autoloader.enable_reloading
|
32
|
+
ActiveSupport::Dependencies.autoloader = autoloader
|
65
33
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
That block runs when the application boots, and every time there is a reload.
|
71
|
-
For historical reasons, it may run twice, so it has to be idempotent.
|
72
|
-
|
73
|
-
Check the "Autoloading and Reloading Constants" guide to learn more about how
|
74
|
-
Rails autoloads and reloads.
|
75
|
-
WARNING
|
76
|
-
end
|
77
|
-
|
78
|
-
initializer :let_zeitwerk_take_over do
|
79
|
-
if config.autoloader == :zeitwerk
|
80
|
-
require "active_support/dependencies/zeitwerk_integration"
|
81
|
-
ActiveSupport::Dependencies::ZeitwerkIntegration.take_over(enable_reloading: !config.cache_classes)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
initializer :add_builtin_route do |app|
|
86
|
-
if Rails.env.development?
|
87
|
-
app.routes.prepend do
|
88
|
-
get "/rails/info/properties" => "rails/info#properties", internal: true
|
89
|
-
get "/rails/info/routes" => "rails/info#routes", internal: true
|
90
|
-
get "/rails/info" => "rails/info#index", internal: true
|
34
|
+
autoloader.on_load do |_cpath, value, _abspath|
|
35
|
+
if value.is_a?(Class) && value.singleton_class < ActiveSupport::DescendantsTracker
|
36
|
+
ActiveSupport::Dependencies._autoloaded_tracked_classes << value
|
37
|
+
end
|
91
38
|
end
|
92
39
|
|
93
|
-
|
94
|
-
|
40
|
+
autoloader.on_unload do |_cpath, value, _abspath|
|
41
|
+
value.before_remove_const if value.respond_to?(:before_remove_const)
|
95
42
|
end
|
96
43
|
end
|
44
|
+
|
45
|
+
autoloader.setup
|
97
46
|
end
|
98
47
|
|
99
48
|
# Setup default session store if not already set in config/application.rb
|
@@ -127,10 +76,7 @@ module Rails
|
|
127
76
|
initializer :eager_load! do
|
128
77
|
if config.eager_load
|
129
78
|
ActiveSupport.run_load_hooks(:before_eager_load, self)
|
130
|
-
|
131
|
-
# want to eager load any dependency managed by Zeitwerk regardless of
|
132
|
-
# the autoloading mode of the application.
|
133
|
-
Zeitwerk::Loader.eager_load_all if defined?(Zeitwerk)
|
79
|
+
Zeitwerk::Loader.eager_load_all
|
134
80
|
config.eager_load_namespaces.each(&:eager_load!)
|
135
81
|
end
|
136
82
|
end
|
@@ -187,6 +133,22 @@ module Rails
|
|
187
133
|
end
|
188
134
|
end
|
189
135
|
|
136
|
+
initializer :add_internal_routes do |app|
|
137
|
+
if Rails.env.development?
|
138
|
+
app.routes.prepend do
|
139
|
+
get "/rails/info/properties" => "rails/info#properties", internal: true
|
140
|
+
get "/rails/info/routes" => "rails/info#routes", internal: true
|
141
|
+
get "/rails/info" => "rails/info#index", internal: true
|
142
|
+
end
|
143
|
+
|
144
|
+
routes_reloader.run_after_load_paths = -> do
|
145
|
+
app.routes.append do
|
146
|
+
get "/" => "rails/welcome#index", internal: true
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
190
152
|
# Set routes reload after the finisher hook to ensure routes added in
|
191
153
|
# the hook are taken into account.
|
192
154
|
initializer :set_routes_reloader_hook do |app|
|
@@ -213,7 +175,10 @@ module Rails
|
|
213
175
|
# added in the hook are taken into account.
|
214
176
|
initializer :set_clear_dependencies_hook, group: :all do |app|
|
215
177
|
callback = lambda do
|
216
|
-
|
178
|
+
# Order matters.
|
179
|
+
ActiveSupport::DescendantsTracker.clear(
|
180
|
+
only: ActiveSupport::Dependencies._autoloaded_tracked_classes
|
181
|
+
)
|
217
182
|
ActiveSupport::Dependencies.clear
|
218
183
|
end
|
219
184
|
|
@@ -251,13 +216,6 @@ module Rails
|
|
251
216
|
end
|
252
217
|
end
|
253
218
|
end
|
254
|
-
|
255
|
-
# Disable dependency loading during request cycle
|
256
|
-
initializer :disable_dependency_loading do
|
257
|
-
if config.eager_load && config.cache_classes && !config.enable_dependency_loading
|
258
|
-
ActiveSupport::Dependencies.unhook!
|
259
|
-
end
|
260
|
-
end
|
261
219
|
end
|
262
220
|
end
|
263
221
|
end
|
@@ -5,8 +5,11 @@ require "active_support/core_ext/module/delegation"
|
|
5
5
|
module Rails
|
6
6
|
class Application
|
7
7
|
class RoutesReloader
|
8
|
+
include ActiveSupport::Callbacks
|
9
|
+
|
8
10
|
attr_reader :route_sets, :paths, :external_routes
|
9
11
|
attr_accessor :eager_load
|
12
|
+
attr_writer :run_after_load_paths # :nodoc:
|
10
13
|
delegate :execute_if_updated, :execute, :updated?, to: :updater
|
11
14
|
|
12
15
|
def initialize
|
@@ -45,6 +48,11 @@ module Rails
|
|
45
48
|
|
46
49
|
def load_paths
|
47
50
|
paths.each { |path| load(path) }
|
51
|
+
run_after_load_paths.call
|
52
|
+
end
|
53
|
+
|
54
|
+
def run_after_load_paths
|
55
|
+
@run_after_load_paths ||= -> { }
|
48
56
|
end
|
49
57
|
|
50
58
|
def finalize!
|
data/lib/rails/application.rb
CHANGED
@@ -57,29 +57,6 @@ module Rails
|
|
57
57
|
# 9) Build the middleware stack and run to_prepare callbacks
|
58
58
|
# 10) Run config.before_eager_load and eager_load! if eager_load is true
|
59
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.
|
83
60
|
class Application < Engine
|
84
61
|
autoload :Bootstrap, "rails/application/bootstrap"
|
85
62
|
autoload :Configuration, "rails/application/configuration"
|
@@ -247,9 +224,11 @@ module Rails
|
|
247
224
|
config, shared = all_configs[env.to_sym], all_configs[:shared]
|
248
225
|
|
249
226
|
if shared
|
250
|
-
config = {} if config.nil?
|
251
|
-
if config.is_a?(Hash)
|
227
|
+
config = {} if config.nil? && shared.is_a?(Hash)
|
228
|
+
if config.is_a?(Hash) && shared.is_a?(Hash)
|
252
229
|
config = shared.deep_merge(config)
|
230
|
+
elsif config.nil?
|
231
|
+
config = shared
|
253
232
|
end
|
254
233
|
end
|
255
234
|
|
@@ -266,13 +245,13 @@ module Rails
|
|
266
245
|
# Stores some of the Rails initial environment parameters which
|
267
246
|
# will be used by middlewares and engines to configure themselves.
|
268
247
|
def env_config
|
269
|
-
@app_env_config ||=
|
270
|
-
super.merge(
|
248
|
+
@app_env_config ||= super.merge(
|
271
249
|
"action_dispatch.parameter_filter" => config.filter_parameters,
|
272
250
|
"action_dispatch.redirect_filter" => config.filter_redirect,
|
273
251
|
"action_dispatch.secret_key_base" => secret_key_base,
|
274
252
|
"action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
|
275
253
|
"action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
|
254
|
+
"action_dispatch.log_rescued_responses" => config.action_dispatch.log_rescued_responses,
|
276
255
|
"action_dispatch.logger" => Rails.logger,
|
277
256
|
"action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner,
|
278
257
|
"action_dispatch.key_generator" => key_generator,
|
@@ -295,7 +274,6 @@ module Rails
|
|
295
274
|
"action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives,
|
296
275
|
"action_dispatch.permissions_policy" => config.permissions_policy,
|
297
276
|
)
|
298
|
-
end
|
299
277
|
end
|
300
278
|
|
301
279
|
# If you try to define a set of Rake tasks on the instance, these will get
|
@@ -355,26 +333,26 @@ module Rails
|
|
355
333
|
# are changing config.root inside your application definition or having a custom
|
356
334
|
# Rails application, you will need to add lib to $LOAD_PATH on your own in case
|
357
335
|
# you need to load files in lib/ during the application configuration as well.
|
358
|
-
def self.add_lib_to_load_path!(root)
|
336
|
+
def self.add_lib_to_load_path!(root) # :nodoc:
|
359
337
|
path = File.join root, "lib"
|
360
338
|
if File.exist?(path) && !$LOAD_PATH.include?(path)
|
361
339
|
$LOAD_PATH.unshift(path)
|
362
340
|
end
|
363
341
|
end
|
364
342
|
|
365
|
-
def require_environment!
|
343
|
+
def require_environment! # :nodoc:
|
366
344
|
environment = paths["config/environment"].existent.first
|
367
345
|
require environment if environment
|
368
346
|
end
|
369
347
|
|
370
|
-
def routes_reloader
|
348
|
+
def routes_reloader # :nodoc:
|
371
349
|
@routes_reloader ||= RoutesReloader.new
|
372
350
|
end
|
373
351
|
|
374
352
|
# Returns an array of file paths appended with a hash of
|
375
353
|
# directories-extensions suitable for ActiveSupport::FileUpdateChecker
|
376
354
|
# API.
|
377
|
-
def watchable_args
|
355
|
+
def watchable_args # :nodoc:
|
378
356
|
files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
|
379
357
|
|
380
358
|
ActiveSupport::Dependencies.autoload_paths.each do |path|
|
@@ -386,20 +364,20 @@ module Rails
|
|
386
364
|
|
387
365
|
# Initialize the application passing the given group. By default, the
|
388
366
|
# group is :default
|
389
|
-
def initialize!(group = :default)
|
367
|
+
def initialize!(group = :default) # :nodoc:
|
390
368
|
raise "Application has been already initialized." if @initialized
|
391
369
|
run_initializers(group, self)
|
392
370
|
@initialized = true
|
393
371
|
self
|
394
372
|
end
|
395
373
|
|
396
|
-
def initializers
|
374
|
+
def initializers # :nodoc:
|
397
375
|
Bootstrap.initializers_for(self) +
|
398
376
|
railties_initializers(super) +
|
399
377
|
Finisher.initializers_for(self)
|
400
378
|
end
|
401
379
|
|
402
|
-
def config
|
380
|
+
def config # :nodoc:
|
403
381
|
@config ||= Application::Configuration.new(self.class.find_root(self.class.called_from))
|
404
382
|
end
|
405
383
|
|
@@ -487,11 +465,11 @@ module Rails
|
|
487
465
|
)
|
488
466
|
end
|
489
467
|
|
490
|
-
def to_app
|
468
|
+
def to_app # :nodoc:
|
491
469
|
self
|
492
470
|
end
|
493
471
|
|
494
|
-
def helpers_paths
|
472
|
+
def helpers_paths # :nodoc:
|
495
473
|
config.helpers_paths
|
496
474
|
end
|
497
475
|
|
@@ -513,17 +491,13 @@ module Rails
|
|
513
491
|
|
514
492
|
# Eager loads the application code.
|
515
493
|
def eager_load!
|
516
|
-
|
517
|
-
Rails.autoloaders.each(&:eager_load)
|
518
|
-
else
|
519
|
-
super
|
520
|
-
end
|
494
|
+
Rails.autoloaders.each(&:eager_load)
|
521
495
|
end
|
522
496
|
|
523
497
|
protected
|
524
498
|
alias :build_middleware_stack :app
|
525
499
|
|
526
|
-
def run_tasks_blocks(app)
|
500
|
+
def run_tasks_blocks(app) # :nodoc:
|
527
501
|
railties.each { |r| r.run_tasks_blocks(app) }
|
528
502
|
super
|
529
503
|
load "rails/tasks.rb"
|
@@ -534,28 +508,28 @@ module Rails
|
|
534
508
|
end
|
535
509
|
end
|
536
510
|
|
537
|
-
def run_generators_blocks(app)
|
511
|
+
def run_generators_blocks(app) # :nodoc:
|
538
512
|
railties.each { |r| r.run_generators_blocks(app) }
|
539
513
|
super
|
540
514
|
end
|
541
515
|
|
542
|
-
def run_runner_blocks(app)
|
516
|
+
def run_runner_blocks(app) # :nodoc:
|
543
517
|
railties.each { |r| r.run_runner_blocks(app) }
|
544
518
|
super
|
545
519
|
end
|
546
520
|
|
547
|
-
def run_console_blocks(app)
|
521
|
+
def run_console_blocks(app) # :nodoc:
|
548
522
|
railties.each { |r| r.run_console_blocks(app) }
|
549
523
|
super
|
550
524
|
end
|
551
525
|
|
552
|
-
def run_server_blocks(app)
|
526
|
+
def run_server_blocks(app) # :nodoc:
|
553
527
|
railties.each { |r| r.run_server_blocks(app) }
|
554
528
|
super
|
555
529
|
end
|
556
530
|
|
557
531
|
# Returns the ordered railties for this application considering railties_order.
|
558
|
-
def ordered_railties
|
532
|
+
def ordered_railties # :nodoc:
|
559
533
|
@ordered_railties ||= begin
|
560
534
|
order = config.railties_order.map do |railtie|
|
561
535
|
if railtie == :main_app
|
@@ -577,7 +551,7 @@ module Rails
|
|
577
551
|
end
|
578
552
|
end
|
579
553
|
|
580
|
-
def railties_initializers(current)
|
554
|
+
def railties_initializers(current) # :nodoc:
|
581
555
|
initializers = []
|
582
556
|
ordered_railties.reverse.flatten.each do |r|
|
583
557
|
if r == self
|
@@ -589,7 +563,7 @@ module Rails
|
|
589
563
|
initializers
|
590
564
|
end
|
591
565
|
|
592
|
-
def default_middleware_stack
|
566
|
+
def default_middleware_stack # :nodoc:
|
593
567
|
default_stack = DefaultMiddlewareStack.new(self, config, paths)
|
594
568
|
default_stack.build_stack
|
595
569
|
end
|