railties 6.1.4.1 → 7.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +113 -344
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +16 -16
- data/README.rdoc +0 -1
- data/lib/rails/all.rb +0 -1
- data/lib/rails/app_updater.rb +3 -5
- data/lib/rails/application/bootstrap.rb +21 -5
- data/lib/rails/application/configuration.rb +64 -28
- data/lib/rails/application/default_middleware_stack.rb +7 -3
- data/lib/rails/application/finisher.rb +42 -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 +8 -3
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +10 -11
- 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 +3 -3
- data/lib/rails/engine.rb +18 -24
- 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 +99 -105
- 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/_form.html.erb.tt +8 -8
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +6 -28
- 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 +8 -17
- data/lib/rails/generators/erb.rb +1 -1
- data/lib/rails/generators/generated_attribute.rb +45 -9
- 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 +53 -91
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +44 -50
- 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 -9
- 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/application.rb.tt +0 -1
- 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 +6 -12
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +21 -17
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -11
- 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 +19 -25
- 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 +121 -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 +4 -1
- 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 +3 -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 +7 -3
- 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/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +4 -5
- 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 +9 -11
- 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 +27 -10
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +4 -1
- 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 +8 -9
- 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 +13 -11
- 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 +16 -9
- data/lib/rails/test_unit/testing.rake +4 -9
- data/lib/rails/welcome_controller.rb +1 -0
- data/lib/rails.rb +5 -0
- metadata +34 -37
- 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/backtrace_silencers.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/mime_types.rb.tt +0 -4
- 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/initializers/wrap_parameters.rb.tt +0 -16
- 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
|
-
options[:
|
30
|
-
options[:skip_puma] = !defined?(Puma)
|
28
|
+
options[:skip_asset_pipeline] = !defined?(Sprockets::Railtie) && !defined?(Propshaft::Railtie)
|
31
29
|
options[:skip_bootsnap] = !defined?(Bootsnap)
|
32
|
-
options[:
|
30
|
+
options[:updating] = true
|
33
31
|
options
|
34
32
|
end
|
35
33
|
end
|
@@ -14,6 +14,7 @@ module Rails
|
|
14
14
|
initializer :load_environment_hook, group: :all do end
|
15
15
|
|
16
16
|
initializer :load_active_support, group: :all do
|
17
|
+
ENV["RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION"] = "true" if config.active_support.disable_to_s_conversion
|
17
18
|
require "active_support/all" unless config.active_support.bare
|
18
19
|
end
|
19
20
|
|
@@ -44,13 +45,16 @@ module Rails
|
|
44
45
|
logger.level = ActiveSupport::Logger::WARN
|
45
46
|
logger.warn(
|
46
47
|
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is writable " \
|
47
|
-
"(
|
48
|
+
"(i.e. make it writable for user and group: chmod 0664 #{path}). " \
|
48
49
|
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
|
49
50
|
)
|
50
51
|
logger
|
51
52
|
end
|
52
|
-
|
53
53
|
Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase)
|
54
|
+
|
55
|
+
unless config.consider_all_requests_local
|
56
|
+
Rails.error.logger = Rails.logger
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
60
|
# Initialize cache early in the stack so railties can make use of it.
|
@@ -64,9 +68,21 @@ module Rails
|
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
67
|
-
#
|
68
|
-
|
69
|
-
|
71
|
+
# We setup the once autoloader this early so that engines and applications
|
72
|
+
# are able to autoload from these paths during initialization.
|
73
|
+
initializer :setup_once_autoloader, after: :set_eager_load_paths, before: :bootstrap_hook do
|
74
|
+
autoloader = Rails.autoloaders.once
|
75
|
+
|
76
|
+
ActiveSupport::Dependencies.autoload_once_paths.freeze
|
77
|
+
ActiveSupport::Dependencies.autoload_once_paths.uniq.each do |path|
|
78
|
+
# Zeitwerk only accepts existing directories in `push_dir`.
|
79
|
+
next unless File.directory?(path)
|
80
|
+
|
81
|
+
autoloader.push_dir(path)
|
82
|
+
autoloader.do_not_eager_load(path) unless ActiveSupport::Dependencies.eager_load?(path)
|
83
|
+
end
|
84
|
+
|
85
|
+
autoloader.setup
|
70
86
|
end
|
71
87
|
|
72
88
|
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"
|
@@ -22,9 +21,9 @@ module Rails
|
|
22
21
|
:read_encrypted_secrets, :log_level, :content_security_policy_report_only,
|
23
22
|
:content_security_policy_nonce_generator, :content_security_policy_nonce_directives,
|
24
23
|
:require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path,
|
25
|
-
:rake_eager_load
|
24
|
+
:rake_eager_load, :server_timing
|
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
|
@@ -35,6 +34,7 @@ module Rails
|
|
35
34
|
@filter_redirect = []
|
36
35
|
@helpers_paths = []
|
37
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?
|
38
38
|
@host_authorization = {}
|
39
39
|
@public_file_server = ActiveSupport::OrderedOptions.new
|
40
40
|
@public_file_server.enabled = true
|
@@ -70,11 +70,11 @@ module Rails
|
|
70
70
|
@credentials = ActiveSupport::OrderedOptions.new
|
71
71
|
@credentials.content_path = default_credentials_content_path
|
72
72
|
@credentials.key_path = default_credentials_key_path
|
73
|
-
@autoloader = :classic
|
74
73
|
@disable_sandbox = false
|
75
74
|
@add_autoload_paths_to_load_path = true
|
76
75
|
@permissions_policy = nil
|
77
76
|
@rake_eager_load = false
|
77
|
+
@server_timing = false
|
78
78
|
end
|
79
79
|
|
80
80
|
# Loads default configurations. See {the result of the method for each version}[https://guides.rubyonrails.org/configuring.html#results-of-config-load-defaults].
|
@@ -116,7 +116,7 @@ module Rails
|
|
116
116
|
|
117
117
|
if respond_to?(:active_support)
|
118
118
|
active_support.use_authenticated_message_encryption = true
|
119
|
-
active_support.hash_digest_class = ::Digest::SHA1
|
119
|
+
active_support.hash_digest_class = OpenSSL::Digest::SHA1
|
120
120
|
end
|
121
121
|
|
122
122
|
if respond_to?(:action_controller)
|
@@ -129,8 +129,6 @@ module Rails
|
|
129
129
|
when "6.0"
|
130
130
|
load_defaults "5.2"
|
131
131
|
|
132
|
-
self.autoloader = :zeitwerk if RUBY_ENGINE == "ruby"
|
133
|
-
|
134
132
|
if respond_to?(:action_view)
|
135
133
|
action_view.default_enforce_utf8 = false
|
136
134
|
end
|
@@ -156,20 +154,13 @@ module Rails
|
|
156
154
|
when "6.1"
|
157
155
|
load_defaults "6.0"
|
158
156
|
|
159
|
-
self.autoloader = :zeitwerk if %w[ruby truffleruby].include?(RUBY_ENGINE)
|
160
|
-
|
161
157
|
if respond_to?(:active_record)
|
162
158
|
active_record.has_many_inversing = true
|
163
159
|
active_record.legacy_connection_handling = false
|
164
160
|
end
|
165
161
|
|
166
|
-
if respond_to?(:active_storage)
|
167
|
-
active_storage.track_variants = true
|
168
|
-
end
|
169
|
-
|
170
162
|
if respond_to?(:active_job)
|
171
163
|
active_job.retry_jitter = 0.15
|
172
|
-
active_job.skip_after_callbacks_if_terminated = true
|
173
164
|
end
|
174
165
|
|
175
166
|
if respond_to?(:action_dispatch)
|
@@ -187,6 +178,8 @@ module Rails
|
|
187
178
|
end
|
188
179
|
|
189
180
|
if respond_to?(:active_storage)
|
181
|
+
active_storage.track_variants = true
|
182
|
+
|
190
183
|
active_storage.queues.analysis = nil
|
191
184
|
active_storage.queues.purge = nil
|
192
185
|
end
|
@@ -201,6 +194,61 @@ module Rails
|
|
201
194
|
end
|
202
195
|
|
203
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.default_headers = {
|
202
|
+
"X-Frame-Options" => "SAMEORIGIN",
|
203
|
+
"X-XSS-Protection" => "0",
|
204
|
+
"X-Content-Type-Options" => "nosniff",
|
205
|
+
"X-Download-Options" => "noopen",
|
206
|
+
"X-Permitted-Cross-Domain-Policies" => "none",
|
207
|
+
"Referrer-Policy" => "strict-origin-when-cross-origin"
|
208
|
+
}
|
209
|
+
action_dispatch.return_only_request_media_type_on_content_type = false
|
210
|
+
action_dispatch.cookies_serializer = :json
|
211
|
+
end
|
212
|
+
|
213
|
+
if respond_to?(:action_view)
|
214
|
+
action_view.button_to_generates_button_tag = true
|
215
|
+
action_view.apply_stylesheet_media_default = false
|
216
|
+
end
|
217
|
+
|
218
|
+
if respond_to?(:active_support)
|
219
|
+
active_support.hash_digest_class = OpenSSL::Digest::SHA256
|
220
|
+
active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256
|
221
|
+
active_support.remove_deprecated_time_with_zone_name = true
|
222
|
+
active_support.cache_format_version = 7.0
|
223
|
+
active_support.use_rfc4122_namespaced_uuids = true
|
224
|
+
active_support.executor_around_test_case = true
|
225
|
+
active_support.isolation_level = :thread
|
226
|
+
active_support.disable_to_s_conversion = true
|
227
|
+
end
|
228
|
+
|
229
|
+
if respond_to?(:action_mailer)
|
230
|
+
action_mailer.smtp_timeout = 5
|
231
|
+
end
|
232
|
+
|
233
|
+
if respond_to?(:active_storage)
|
234
|
+
active_storage.video_preview_arguments =
|
235
|
+
"-vf 'select=eq(n\\,0)+eq(key\\,1)+gt(scene\\,0.015),loop=loop=-1:size=2,trim=start_frame=1'" \
|
236
|
+
" -frames:v 1 -f image2"
|
237
|
+
|
238
|
+
active_storage.variant_processor = :vips
|
239
|
+
end
|
240
|
+
|
241
|
+
if respond_to?(:active_record)
|
242
|
+
active_record.verify_foreign_keys_for_fixtures = true
|
243
|
+
active_record.partial_inserts = false
|
244
|
+
active_record.automatic_scope_inversing = true
|
245
|
+
end
|
246
|
+
|
247
|
+
if respond_to?(:action_controller)
|
248
|
+
action_controller.raise_on_open_redirects = true
|
249
|
+
|
250
|
+
action_controller.wrap_parameters_by_default = true
|
251
|
+
end
|
204
252
|
else
|
205
253
|
raise "Unknown version #{target_version.to_s.inspect}"
|
206
254
|
end
|
@@ -331,7 +379,7 @@ module Rails
|
|
331
379
|
end
|
332
380
|
end
|
333
381
|
|
334
|
-
def session_store?
|
382
|
+
def session_store? # :nodoc:
|
335
383
|
@session_store
|
336
384
|
end
|
337
385
|
|
@@ -355,18 +403,6 @@ module Rails
|
|
355
403
|
end
|
356
404
|
end
|
357
405
|
|
358
|
-
def autoloader=(autoloader)
|
359
|
-
case autoloader
|
360
|
-
when :classic
|
361
|
-
@autoloader = autoloader
|
362
|
-
when :zeitwerk
|
363
|
-
require "zeitwerk"
|
364
|
-
@autoloader = autoloader
|
365
|
-
else
|
366
|
-
raise ArgumentError, "config.autoloader may be :classic or :zeitwerk, got #{autoloader.inspect} instead"
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
406
|
def default_log_file
|
371
407
|
path = paths["log"].first
|
372
408
|
unless File.exist? File.dirname path
|
@@ -379,7 +415,7 @@ module Rails
|
|
379
415
|
f
|
380
416
|
end
|
381
417
|
|
382
|
-
class Custom
|
418
|
+
class Custom # :nodoc:
|
383
419
|
def initialize
|
384
420
|
@configurations = Hash.new
|
385
421
|
end
|
@@ -13,7 +13,7 @@ module Rails
|
|
13
13
|
|
14
14
|
def build_stack
|
15
15
|
ActionDispatch::MiddlewareStack.new do |middleware|
|
16
|
-
middleware.use ::ActionDispatch::HostAuthorization, config.hosts,
|
16
|
+
middleware.use ::ActionDispatch::HostAuthorization, config.hosts, **config.host_authorization
|
17
17
|
|
18
18
|
if config.force_ssl
|
19
19
|
middleware.use ::ActionDispatch::SSL, **config.ssl_options,
|
@@ -42,6 +42,7 @@ module Rails
|
|
42
42
|
|
43
43
|
middleware.use ::ActionDispatch::Executor, app.executor
|
44
44
|
|
45
|
+
middleware.use ::ActionDispatch::ServerTiming if config.server_timing
|
45
46
|
middleware.use ::Rack::Runtime
|
46
47
|
middleware.use ::Rack::MethodOverride unless config.api_only
|
47
48
|
middleware.use ::ActionDispatch::RequestId, header: config.action_dispatch.request_id_header
|
@@ -50,7 +51,10 @@ module Rails
|
|
50
51
|
middleware.use ::Rails::Rack::Logger, config.log_tags
|
51
52
|
middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app
|
52
53
|
middleware.use ::ActionDispatch::DebugExceptions, app, config.debug_exception_response_format
|
53
|
-
|
54
|
+
|
55
|
+
if config.consider_all_requests_local
|
56
|
+
middleware.use ::ActionDispatch::ActionableExceptions
|
57
|
+
end
|
54
58
|
|
55
59
|
unless config.cache_classes
|
56
60
|
middleware.use ::ActionDispatch::Reloader, app.reloader
|
@@ -64,10 +68,10 @@ module Rails
|
|
64
68
|
config.session_options[:secure] = true
|
65
69
|
end
|
66
70
|
middleware.use config.session_store, config.session_options
|
67
|
-
middleware.use ::ActionDispatch::Flash
|
68
71
|
end
|
69
72
|
|
70
73
|
unless config.api_only
|
74
|
+
middleware.use ::ActionDispatch::Flash
|
71
75
|
middleware.use ::ActionDispatch::ContentSecurityPolicy::Middleware
|
72
76
|
middleware.use ::ActionDispatch::PermissionsPolicy::Middleware
|
73
77
|
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,8 @@ 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(ActiveSupport::Dependencies._autoloaded_tracked_classes)
|
217
180
|
ActiveSupport::Dependencies.clear
|
218
181
|
end
|
219
182
|
|
@@ -229,6 +192,7 @@ module Rails
|
|
229
192
|
|
230
193
|
if config.cache_classes
|
231
194
|
# No reloader
|
195
|
+
ActiveSupport::DescendantsTracker.disable_clear!
|
232
196
|
elsif config.reload_classes_only_on_change
|
233
197
|
reloader = config.file_watcher.new(*watchable_args, &callback)
|
234
198
|
reloaders << reloader
|
@@ -251,13 +215,6 @@ module Rails
|
|
251
215
|
end
|
252
216
|
end
|
253
217
|
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
218
|
end
|
262
219
|
end
|
263
220
|
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!
|