railties 6.1.7.2 → 7.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +198 -324
- data/RDOC_MAIN.rdoc +16 -16
- data/README.rdoc +1 -2
- data/lib/minitest/rails_plugin.rb +1 -1
- data/lib/rails/all.rb +0 -1
- data/lib/rails/app_updater.rb +9 -6
- data/lib/rails/application/bootstrap.rb +24 -5
- data/lib/rails/application/configuration.rb +96 -33
- data/lib/rails/application/default_middleware_stack.rb +22 -3
- data/lib/rails/application/finisher.rb +53 -95
- data/lib/rails/application/routes_reloader.rb +8 -0
- data/lib/rails/application.rb +74 -101
- data/lib/rails/application_controller.rb +3 -3
- data/lib/rails/autoloaders/inflector.rb +21 -0
- data/lib/rails/autoloaders.rb +42 -42
- 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 +9 -6
- data/lib/rails/commands/console/console_command.rb +4 -0
- 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 +7 -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 +7 -5
- data/lib/rails/configuration.rb +18 -23
- data/lib/rails/console/helpers.rb +2 -2
- data/lib/rails/engine/configuration.rb +3 -3
- data/lib/rails/engine.rb +31 -37
- data/lib/rails/gem_version.rb +5 -5
- data/lib/rails/generators/actions/create_migration.rb +2 -4
- data/lib/rails/generators/actions.rb +229 -62
- data/lib/rails/generators/app_base.rb +155 -130
- data/lib/rails/generators/app_name.rb +1 -1
- data/lib/rails/generators/base.rb +12 -16
- 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 +11 -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 +17 -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 +13 -13
- data/lib/rails/generators/rails/app/app_generator.rb +70 -91
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +42 -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 -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 +7 -13
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +12 -39
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +7 -12
- 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 +21 -28
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
- 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 +148 -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 +76 -27
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +7 -3
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +9 -31
- 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 +7 -6
- 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 +2 -7
- 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 +7 -7
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +9 -11
- data/lib/rails/generators/testing/behaviour.rb +3 -4
- data/lib/rails/generators.rb +17 -24
- 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/paths.rb +1 -1
- data/lib/rails/rack/logger.rb +7 -9
- data/lib/rails/railtie/configuration.rb +1 -2
- data/lib/rails/railtie.rb +36 -13
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/source_annotation_extractor.rb +1 -1
- data/lib/rails/tasks/framework.rake +7 -9
- 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 +64 -48
- data/lib/rails/test_help.rb +4 -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/version.rb +1 -1
- data/lib/rails/welcome_controller.rb +1 -0
- data/lib/rails.rb +13 -2
- metadata +33 -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/RDOC_MAIN.rdoc
CHANGED
@@ -15,21 +15,21 @@ application into three layers: Model, View, and Controller, each with a specific
|
|
15
15
|
The <em><b>Model layer</b></em> represents the domain model (such as Account, Product,
|
16
16
|
Person, Post, etc.) and encapsulates the business logic specific to
|
17
17
|
your application. In \Rails, database-backed model classes are derived from
|
18
|
-
<tt>ActiveRecord::Base</tt>. {Active Record}[link
|
18
|
+
<tt>ActiveRecord::Base</tt>. {Active Record}[link:/files/activerecord/README_rdoc.html] allows you to present the data from
|
19
19
|
database rows as objects and embellish these data objects with business logic
|
20
20
|
methods. Although most \Rails models are backed by a database, models can also be ordinary
|
21
21
|
Ruby classes, or Ruby classes that implement a set of interfaces as provided by
|
22
|
-
the {Active Model}[link
|
22
|
+
the {Active Model}[link:/files/activemodel/README_rdoc.html] module.
|
23
23
|
|
24
24
|
== Controller layer
|
25
25
|
|
26
26
|
The <em><b>Controller layer</b></em> is responsible for handling incoming HTTP requests and
|
27
|
-
providing a suitable response. Usually this means returning \HTML, but \Rails controllers
|
27
|
+
providing a suitable response. Usually, this means returning \HTML, but \Rails controllers
|
28
28
|
can also generate XML, JSON, PDFs, mobile-specific views, and more. Controllers load and
|
29
|
-
manipulate models
|
29
|
+
manipulate models and render view templates in order to generate the appropriate HTTP response.
|
30
30
|
In \Rails, incoming requests are routed by Action Dispatch to an appropriate controller, and
|
31
31
|
controller classes are derived from <tt>ActionController::Base</tt>. Action Dispatch and Action Controller
|
32
|
-
are bundled together in {Action Pack}[link
|
32
|
+
are bundled together in {Action Pack}[link:/files/actionpack/README_rdoc.html].
|
33
33
|
|
34
34
|
== View layer
|
35
35
|
|
@@ -37,19 +37,19 @@ The <em><b>View layer</b></em> is composed of "templates" that are responsible f
|
|
37
37
|
appropriate representations of your application's resources. Templates can
|
38
38
|
come in a variety of formats, but most view templates are \HTML with embedded
|
39
39
|
Ruby code (ERB files). Views are typically rendered to generate a controller response,
|
40
|
-
or to generate the body of an email. In \Rails, View generation is handled by {Action View}[link
|
40
|
+
or to generate the body of an email. In \Rails, View generation is handled by {Action View}[link:/files/actionview/README_rdoc.html].
|
41
41
|
|
42
42
|
== Frameworks and libraries
|
43
43
|
|
44
|
-
{Active Record}[link
|
45
|
-
{Action Pack}[link
|
46
|
-
In addition to that, \Rails also comes with {Action Mailer}[link
|
47
|
-
to generate and send emails; {Action Mailbox}[link
|
48
|
-
{Active Job}[link
|
49
|
-
backends; {Action Cable}[link
|
50
|
-
integrate WebSockets with a \Rails application; {Active Storage}[link
|
51
|
-
a library to attach cloud and local files to \Rails applications; {Action Text}[link
|
52
|
-
and {Active Support}[link
|
44
|
+
{Active Record}[link:/files/activerecord/README_rdoc.html], {Active Model}[link:/files/activemodel/README_rdoc.html],
|
45
|
+
{Action Pack}[link:/files/actionpack/README_rdoc.html], and {Action View}[link:/files/actionview/README_rdoc.html] can each be used independently outside \Rails.
|
46
|
+
In addition to that, \Rails also comes with {Action Mailer}[link:/files/actionmailer/README_rdoc.html], a library
|
47
|
+
to generate and send emails; {Action Mailbox}[link:/files/actionmailbox/README_md.html], a library to receive emails within a Rails application;
|
48
|
+
{Active Job}[link:/files/activejob/README_md.html], a framework for declaring jobs and making them run on a variety of queueing
|
49
|
+
backends; {Action Cable}[link:/files/actioncable/README_md.html], a framework to
|
50
|
+
integrate WebSockets with a \Rails application; {Active Storage}[link:/files/activestorage/README_md.html],
|
51
|
+
a library to attach cloud and local files to \Rails applications; {Action Text}[link:/files/actiontext/README_md.html], a library to handle rich text content;
|
52
|
+
and {Active Support}[link:/files/activesupport/README_rdoc.html], a collection
|
53
53
|
of utility classes and standard library extensions that are useful for \Rails,
|
54
54
|
and may also be used independently outside \Rails.
|
55
55
|
|
@@ -72,7 +72,7 @@ and may also be used independently outside \Rails.
|
|
72
72
|
|
73
73
|
Run with <tt>--help</tt> or <tt>-h</tt> for options.
|
74
74
|
|
75
|
-
4. Go to <tt>http://localhost:3000</tt
|
75
|
+
4. Go to <tt>http://localhost:3000</tt>, and you'll see: "Yay! You’re on \Rails!"
|
76
76
|
|
77
77
|
5. Follow the guidelines to start developing your application. You may find the following resources handy:
|
78
78
|
|
data/README.rdoc
CHANGED
@@ -8,14 +8,13 @@ Railties is responsible for gluing all frameworks together. Overall, it:
|
|
8
8
|
|
9
9
|
* and provides the Rails generators core.
|
10
10
|
|
11
|
-
|
12
11
|
== Download
|
13
12
|
|
14
13
|
The latest version of Railties can be installed with RubyGems:
|
15
14
|
|
16
15
|
* gem install railties
|
17
16
|
|
18
|
-
Source code can be downloaded as part of the Rails project on GitHub
|
17
|
+
Source code can be downloaded as part of the \Rails project on GitHub
|
19
18
|
|
20
19
|
* https://github.com/rails/rails/tree/main/railties
|
21
20
|
|
@@ -49,7 +49,7 @@ module Minitest
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# Owes great inspiration to test runner trailblazers like RSpec,
|
52
|
-
# minitest-reporters, maxitest and others.
|
52
|
+
# minitest-reporters, maxitest, and others.
|
53
53
|
def self.plugin_rails_init(options)
|
54
54
|
unless options[:full_backtrace] || ENV["BACKTRACE"]
|
55
55
|
# Plugin can run without Rails loaded, check before filtering.
|
data/lib/rails/all.rb
CHANGED
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,18 @@ module Rails
|
|
21
21
|
private
|
22
22
|
def generator_options
|
23
23
|
options = { api: !!Rails.application.config.api_only, update: true }
|
24
|
-
options[:
|
24
|
+
options[:skip_active_job] = !defined?(ActiveJob::Railtie)
|
25
25
|
options[:skip_active_record] = !defined?(ActiveRecord::Railtie)
|
26
|
-
options[:skip_active_storage] = !defined?(ActiveStorage::Engine)
|
26
|
+
options[:skip_active_storage] = !defined?(ActiveStorage::Engine)
|
27
27
|
options[:skip_action_mailer] = !defined?(ActionMailer::Railtie)
|
28
|
+
options[:skip_action_mailbox] = !defined?(ActionMailbox::Engine)
|
29
|
+
options[:skip_action_text] = !defined?(ActionText::Engine)
|
28
30
|
options[:skip_action_cable] = !defined?(ActionCable::Engine)
|
29
|
-
options[:
|
30
|
-
options[:
|
31
|
+
options[:skip_test] = !defined?(Rails::TestUnitRailtie)
|
32
|
+
options[:skip_system_test] = Rails.application.config.generators.system_tests.nil?
|
33
|
+
options[:skip_asset_pipeline] = !defined?(Sprockets::Railtie) && !defined?(Propshaft::Railtie)
|
31
34
|
options[:skip_bootsnap] = !defined?(Bootsnap)
|
32
|
-
options[:
|
35
|
+
options[:updating] = true
|
33
36
|
options
|
34
37
|
end
|
35
38
|
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,17 +45,23 @@ 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.
|
57
61
|
initializer :initialize_cache, group: :all do
|
62
|
+
cache_format_version = config.active_support.delete(:cache_format_version)
|
63
|
+
ActiveSupport.cache_format_version = cache_format_version if cache_format_version
|
64
|
+
|
58
65
|
unless Rails.cache
|
59
66
|
Rails.cache = ActiveSupport::Cache.lookup_store(*config.cache_store)
|
60
67
|
|
@@ -64,9 +71,21 @@ module Rails
|
|
64
71
|
end
|
65
72
|
end
|
66
73
|
|
67
|
-
#
|
68
|
-
|
69
|
-
|
74
|
+
# We setup the once autoloader this early so that engines and applications
|
75
|
+
# are able to autoload from these paths during initialization.
|
76
|
+
initializer :setup_once_autoloader, after: :set_eager_load_paths, before: :bootstrap_hook do
|
77
|
+
autoloader = Rails.autoloaders.once
|
78
|
+
|
79
|
+
ActiveSupport::Dependencies.autoload_once_paths.freeze
|
80
|
+
ActiveSupport::Dependencies.autoload_once_paths.uniq.each do |path|
|
81
|
+
# Zeitwerk only accepts existing directories in `push_dir`.
|
82
|
+
next unless File.directory?(path)
|
83
|
+
|
84
|
+
autoloader.push_dir(path)
|
85
|
+
autoloader.do_not_eager_load(path) unless ActiveSupport::Dependencies.eager_load?(path)
|
86
|
+
end
|
87
|
+
|
88
|
+
autoloader.setup
|
70
89
|
end
|
71
90
|
|
72
91
|
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,7 +34,8 @@ module Rails
|
|
35
34
|
@filter_redirect = []
|
36
35
|
@helpers_paths = []
|
37
36
|
if Rails.env.development?
|
38
|
-
@hosts = ActionDispatch::HostAuthorization::ALLOWED_HOSTS_IN_DEVELOPMENT
|
37
|
+
@hosts = ActionDispatch::HostAuthorization::ALLOWED_HOSTS_IN_DEVELOPMENT +
|
38
|
+
ENV["RAILS_DEVELOPMENT_HOSTS"].to_s.split(",").map(&:strip)
|
39
39
|
else
|
40
40
|
@hosts = []
|
41
41
|
end
|
@@ -74,20 +74,24 @@ module Rails
|
|
74
74
|
@credentials = ActiveSupport::OrderedOptions.new
|
75
75
|
@credentials.content_path = default_credentials_content_path
|
76
76
|
@credentials.key_path = default_credentials_key_path
|
77
|
-
@autoloader = :classic
|
78
77
|
@disable_sandbox = false
|
79
78
|
@add_autoload_paths_to_load_path = true
|
80
79
|
@permissions_policy = nil
|
81
80
|
@rake_eager_load = false
|
81
|
+
@server_timing = false
|
82
82
|
end
|
83
83
|
|
84
|
-
# Loads default
|
84
|
+
# Loads default configuration values for a target version. This includes
|
85
|
+
# defaults for versions prior to the target version. See the
|
86
|
+
# {configuration guide}[https://guides.rubyonrails.org/configuring.html]
|
87
|
+
# for the default values associated with a particular version.
|
85
88
|
def load_defaults(target_version)
|
86
89
|
case target_version.to_s
|
87
90
|
when "5.0"
|
88
91
|
if respond_to?(:action_controller)
|
89
92
|
action_controller.per_form_csrf_tokens = true
|
90
93
|
action_controller.forgery_protection_origin_check = true
|
94
|
+
action_controller.urlsafe_csrf_tokens = false
|
91
95
|
end
|
92
96
|
|
93
97
|
ActiveSupport.to_time_preserves_timezone = true
|
@@ -120,7 +124,7 @@ module Rails
|
|
120
124
|
|
121
125
|
if respond_to?(:active_support)
|
122
126
|
active_support.use_authenticated_message_encryption = true
|
123
|
-
active_support.hash_digest_class = ::Digest::SHA1
|
127
|
+
active_support.hash_digest_class = OpenSSL::Digest::SHA1
|
124
128
|
end
|
125
129
|
|
126
130
|
if respond_to?(:action_controller)
|
@@ -133,8 +137,6 @@ module Rails
|
|
133
137
|
when "6.0"
|
134
138
|
load_defaults "5.2"
|
135
139
|
|
136
|
-
self.autoloader = :zeitwerk if RUBY_ENGINE == "ruby"
|
137
|
-
|
138
140
|
if respond_to?(:action_view)
|
139
141
|
action_view.default_enforce_utf8 = false
|
140
142
|
end
|
@@ -160,20 +162,13 @@ module Rails
|
|
160
162
|
when "6.1"
|
161
163
|
load_defaults "6.0"
|
162
164
|
|
163
|
-
self.autoloader = :zeitwerk if %w[ruby truffleruby].include?(RUBY_ENGINE)
|
164
|
-
|
165
165
|
if respond_to?(:active_record)
|
166
166
|
active_record.has_many_inversing = true
|
167
167
|
active_record.legacy_connection_handling = false
|
168
168
|
end
|
169
169
|
|
170
|
-
if respond_to?(:active_storage)
|
171
|
-
active_storage.track_variants = true
|
172
|
-
end
|
173
|
-
|
174
170
|
if respond_to?(:active_job)
|
175
171
|
active_job.retry_jitter = 0.15
|
176
|
-
active_job.skip_after_callbacks_if_terminated = true
|
177
172
|
end
|
178
173
|
|
179
174
|
if respond_to?(:action_dispatch)
|
@@ -182,7 +177,7 @@ module Rails
|
|
182
177
|
end
|
183
178
|
|
184
179
|
if respond_to?(:action_controller)
|
185
|
-
action_controller.urlsafe_csrf_tokens
|
180
|
+
action_controller.delete(:urlsafe_csrf_tokens)
|
186
181
|
end
|
187
182
|
|
188
183
|
if respond_to?(:action_view)
|
@@ -191,6 +186,8 @@ module Rails
|
|
191
186
|
end
|
192
187
|
|
193
188
|
if respond_to?(:active_storage)
|
189
|
+
active_storage.track_variants = true
|
190
|
+
|
194
191
|
active_storage.queues.analysis = nil
|
195
192
|
active_storage.queues.purge = nil
|
196
193
|
end
|
@@ -205,6 +202,62 @@ module Rails
|
|
205
202
|
end
|
206
203
|
|
207
204
|
ActiveSupport.utc_to_local_returns_utc_offset_times = true
|
205
|
+
when "7.0"
|
206
|
+
load_defaults "6.1"
|
207
|
+
|
208
|
+
if respond_to?(:action_dispatch)
|
209
|
+
action_dispatch.default_headers = {
|
210
|
+
"X-Frame-Options" => "SAMEORIGIN",
|
211
|
+
"X-XSS-Protection" => "0",
|
212
|
+
"X-Content-Type-Options" => "nosniff",
|
213
|
+
"X-Download-Options" => "noopen",
|
214
|
+
"X-Permitted-Cross-Domain-Policies" => "none",
|
215
|
+
"Referrer-Policy" => "strict-origin-when-cross-origin"
|
216
|
+
}
|
217
|
+
action_dispatch.return_only_request_media_type_on_content_type = false
|
218
|
+
action_dispatch.cookies_serializer = :json
|
219
|
+
end
|
220
|
+
|
221
|
+
if respond_to?(:action_view)
|
222
|
+
action_view.button_to_generates_button_tag = true
|
223
|
+
action_view.apply_stylesheet_media_default = false
|
224
|
+
end
|
225
|
+
|
226
|
+
if respond_to?(:active_support)
|
227
|
+
active_support.hash_digest_class = OpenSSL::Digest::SHA256
|
228
|
+
active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256
|
229
|
+
active_support.remove_deprecated_time_with_zone_name = true
|
230
|
+
active_support.cache_format_version = 7.0
|
231
|
+
active_support.use_rfc4122_namespaced_uuids = true
|
232
|
+
active_support.executor_around_test_case = true
|
233
|
+
active_support.isolation_level = :thread
|
234
|
+
active_support.disable_to_s_conversion = true
|
235
|
+
end
|
236
|
+
|
237
|
+
if respond_to?(:action_mailer)
|
238
|
+
action_mailer.smtp_timeout = 5
|
239
|
+
end
|
240
|
+
|
241
|
+
if respond_to?(:active_storage)
|
242
|
+
active_storage.video_preview_arguments =
|
243
|
+
"-vf 'select=eq(n\\,0)+eq(key\\,1)+gt(scene\\,0.015),loop=loop=-1:size=2,trim=start_frame=1'" \
|
244
|
+
" -frames:v 1 -f image2"
|
245
|
+
|
246
|
+
active_storage.variant_processor = :vips
|
247
|
+
active_storage.multiple_file_field_include_hidden = true
|
248
|
+
end
|
249
|
+
|
250
|
+
if respond_to?(:active_record)
|
251
|
+
active_record.verify_foreign_keys_for_fixtures = true
|
252
|
+
active_record.partial_inserts = false
|
253
|
+
active_record.automatic_scope_inversing = true
|
254
|
+
end
|
255
|
+
|
256
|
+
if respond_to?(:action_controller)
|
257
|
+
action_controller.raise_on_open_redirects = true
|
258
|
+
|
259
|
+
action_controller.wrap_parameters_by_default = true
|
260
|
+
end
|
208
261
|
else
|
209
262
|
raise "Unknown version #{target_version.to_s.inspect}"
|
210
263
|
end
|
@@ -281,8 +334,14 @@ module Rails
|
|
281
334
|
config = if yaml&.exist?
|
282
335
|
loaded_yaml = ActiveSupport::ConfigurationFile.parse(yaml)
|
283
336
|
if (shared = loaded_yaml.delete("shared"))
|
284
|
-
loaded_yaml.each do |
|
285
|
-
values.
|
337
|
+
loaded_yaml.each do |env, config|
|
338
|
+
if config.is_a?(Hash) && config.values.all?(Hash)
|
339
|
+
config.map do |name, sub_config|
|
340
|
+
sub_config.reverse_merge!(shared)
|
341
|
+
end
|
342
|
+
else
|
343
|
+
config.reverse_merge!(shared)
|
344
|
+
end
|
286
345
|
end
|
287
346
|
end
|
288
347
|
Hash.new(shared).merge(loaded_yaml)
|
@@ -308,6 +367,20 @@ module Rails
|
|
308
367
|
generators.colorize_logging = val
|
309
368
|
end
|
310
369
|
|
370
|
+
# Specifies what class to use to store the session. Possible values
|
371
|
+
# are +:cookie_store+, +:mem_cache_store+, a custom store, or
|
372
|
+
# +:disabled+. +:disabled+ tells Rails not to deal with sessions.
|
373
|
+
#
|
374
|
+
# Additional options will be set as +session_options+:
|
375
|
+
#
|
376
|
+
# config.session_store :cookie_store, key: "_your_app_session"
|
377
|
+
# config.session_options # => {key: "_your_app_session"}
|
378
|
+
#
|
379
|
+
# If a custom store is specified as a symbol, it will be resolved to
|
380
|
+
# the +ActionDispatch::Session+ namespace:
|
381
|
+
#
|
382
|
+
# # use ActionDispatch::Session::MyCustomStore as the session store
|
383
|
+
# config.session_store :my_custom_store
|
311
384
|
def session_store(new_session_store = nil, **options)
|
312
385
|
if new_session_store
|
313
386
|
if new_session_store == :active_record_store
|
@@ -335,7 +408,7 @@ module Rails
|
|
335
408
|
end
|
336
409
|
end
|
337
410
|
|
338
|
-
def session_store?
|
411
|
+
def session_store? # :nodoc:
|
339
412
|
@session_store
|
340
413
|
end
|
341
414
|
|
@@ -343,6 +416,7 @@ module Rails
|
|
343
416
|
Rails::SourceAnnotationExtractor::Annotation
|
344
417
|
end
|
345
418
|
|
419
|
+
# Configures the ActionDispatch::ContentSecurityPolicy.
|
346
420
|
def content_security_policy(&block)
|
347
421
|
if block_given?
|
348
422
|
@content_security_policy = ActionDispatch::ContentSecurityPolicy.new(&block)
|
@@ -351,6 +425,7 @@ module Rails
|
|
351
425
|
end
|
352
426
|
end
|
353
427
|
|
428
|
+
# Configures the ActionDispatch::PermissionsPolicy.
|
354
429
|
def permissions_policy(&block)
|
355
430
|
if block_given?
|
356
431
|
@permissions_policy = ActionDispatch::PermissionsPolicy.new(&block)
|
@@ -359,18 +434,6 @@ module Rails
|
|
359
434
|
end
|
360
435
|
end
|
361
436
|
|
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
437
|
def default_log_file
|
375
438
|
path = paths["log"].first
|
376
439
|
unless File.exist? File.dirname path
|
@@ -383,7 +446,7 @@ module Rails
|
|
383
446
|
f
|
384
447
|
end
|
385
448
|
|
386
|
-
class Custom
|
449
|
+
class Custom # :nodoc:
|
387
450
|
def initialize
|
388
451
|
@configurations = Hash.new
|
389
452
|
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
|
@@ -77,6 +81,21 @@ module Rails
|
|
77
81
|
middleware.use ::Rack::ETag, "no-cache"
|
78
82
|
|
79
83
|
middleware.use ::Rack::TempfileReaper unless config.api_only
|
84
|
+
|
85
|
+
if config.respond_to?(:active_record)
|
86
|
+
if selector_options = config.active_record.database_selector
|
87
|
+
resolver = config.active_record.database_resolver
|
88
|
+
context = config.active_record.database_resolver_context
|
89
|
+
|
90
|
+
middleware.use ::ActiveRecord::Middleware::DatabaseSelector, resolver, context, selector_options
|
91
|
+
end
|
92
|
+
|
93
|
+
if shard_resolver = config.active_record.shard_resolver
|
94
|
+
options = config.active_record.shard_selector || {}
|
95
|
+
|
96
|
+
middleware.use ::ActiveRecord::Middleware::ShardSelector, shard_resolver, options
|
97
|
+
end
|
98
|
+
end
|
80
99
|
end
|
81
100
|
end
|
82
101
|
|