railties 6.0.4.3 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +234 -420
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +1 -1
- data/README.rdoc +1 -1
- data/lib/minitest/rails_plugin.rb +16 -1
- data/lib/rails/api/task.rb +1 -1
- data/lib/rails/application/bootstrap.rb +5 -5
- data/lib/rails/application/configuration.rb +72 -22
- data/lib/rails/application/default_middleware_stack.rb +5 -3
- data/lib/rails/application/finisher.rb +15 -2
- data/lib/rails/application/routes_reloader.rb +9 -2
- data/lib/rails/application.rb +45 -79
- data/lib/rails/backtrace_cleaner.rb +12 -7
- data/lib/rails/code_statistics.rb +3 -3
- data/lib/rails/code_statistics_calculator.rb +6 -6
- data/lib/rails/command/base.rb +1 -1
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +1 -1
- data/lib/rails/command.rb +7 -1
- data/lib/rails/commands/credentials/USAGE +17 -2
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/credentials/credentials_command.rb +28 -4
- data/lib/rails/commands/db/system/change/change_command.rb +6 -1
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +61 -58
- data/lib/rails/commands/encrypted/encrypted_command.rb +4 -4
- data/lib/rails/commands/generate/generate_command.rb +1 -1
- data/lib/rails/commands/notes/notes_command.rb +3 -13
- data/lib/rails/commands/rake/rake_command.rb +9 -8
- data/lib/rails/commands/secrets/USAGE +9 -3
- data/lib/rails/commands/server/server_command.rb +14 -41
- data/lib/rails/commands/test/test_command.rb +2 -2
- data/lib/rails/configuration.rb +40 -10
- data/lib/rails/engine/configuration.rb +1 -0
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +35 -32
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators/actions/create_migration.rb +5 -0
- data/lib/rails/generators/actions.rb +50 -29
- data/lib/rails/generators/app_base.rb +39 -22
- data/lib/rails/generators/base.rb +14 -11
- data/lib/rails/generators/database.rb +3 -4
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +3 -3
- data/lib/rails/generators/generated_attribute.rb +3 -9
- data/lib/rails/generators/migration.rb +2 -1
- data/lib/rails/generators/model_helpers.rb +26 -2
- data/lib/rails/generators/named_base.rb +1 -1
- data/lib/rails/generators/rails/app/USAGE +2 -1
- data/lib/rails/generators/rails/app/app_generator.rb +89 -15
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +11 -11
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +1 -1
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +11 -11
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +2 -1
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -4
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +13 -0
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +9 -3
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +14 -7
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +3 -4
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +17 -3
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +15 -5
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
- 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/new_framework_defaults_6_1.rb.tt +67 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +6 -1
- data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
- data/lib/rails/generators/rails/app/templates/package.json.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +5 -5
- data/lib/rails/generators/rails/assets/USAGE +2 -3
- data/lib/rails/generators/rails/benchmark/USAGE +19 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
- data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
- data/lib/rails/generators/rails/controller/USAGE +2 -2
- data/lib/rails/generators/rails/controller/controller_generator.rb +2 -40
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +1 -1
- data/lib/rails/generators/rails/generator/USAGE +2 -2
- data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
- data/lib/rails/generators/rails/helper/USAGE +2 -3
- data/lib/rails/generators/rails/integration_test/USAGE +2 -2
- data/lib/rails/generators/rails/migration/USAGE +4 -4
- data/lib/rails/generators/rails/model/USAGE +15 -16
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +25 -23
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +10 -19
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +0 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +13 -11
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
- data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -3
- data/lib/rails/generators/rails/resource/USAGE +4 -4
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
- data/lib/rails/generators/rails/scaffold/USAGE +5 -5
- data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +6 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
- data/lib/rails/generators/rails/system_test/USAGE +2 -2
- data/lib/rails/generators/rails/task/USAGE +3 -3
- data/lib/rails/generators/test_case.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/behaviour.rb +1 -1
- data/lib/rails/generators.rb +29 -15
- data/lib/rails/info.rb +1 -1
- data/lib/rails/info_controller.rb +1 -1
- data/lib/rails/mailers_controller.rb +1 -0
- data/lib/rails/paths.rb +14 -6
- data/lib/rails/railtie/configuration.rb +3 -2
- data/lib/rails/railtie.rb +31 -10
- data/lib/rails/source_annotation_extractor.rb +1 -15
- data/lib/rails/tasks/engine.rake +1 -4
- data/lib/rails/tasks/framework.rake +7 -1
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/statistics.rake +1 -1
- data/lib/rails/tasks/yarn.rake +14 -2
- data/lib/rails/tasks.rb +0 -4
- data/lib/rails/templates/rails/mailers/email.html.erb +1 -0
- data/lib/rails/templates/rails/welcome/index.html.erb +1 -1
- data/lib/rails/test_unit/reporter.rb +2 -1
- data/lib/rails/test_unit/runner.rb +12 -3
- data/lib/rails/test_unit/testing.rake +6 -0
- data/lib/rails.rb +5 -8
- metadata +24 -30
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +0 -45
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
- data/lib/rails/tasks/annotations.rake +0 -22
- data/lib/rails/tasks/dev.rake +0 -11
- data/lib/rails/tasks/initializers.rake +0 -9
- data/lib/rails/tasks/routes.rake +0 -9
data/MIT-LICENSE
CHANGED
data/RDOC_MAIN.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -17,7 +17,7 @@ The latest version of Railties can be installed with RubyGems:
|
|
17
17
|
|
18
18
|
Source code can be downloaded as part of the Rails project on GitHub
|
19
19
|
|
20
|
-
* https://github.com/rails/rails/tree/
|
20
|
+
* https://github.com/rails/rails/tree/master/railties
|
21
21
|
|
22
22
|
== License
|
23
23
|
|
@@ -5,6 +5,19 @@ require "rails/test_unit/reporter"
|
|
5
5
|
require "rails/test_unit/runner"
|
6
6
|
|
7
7
|
module Minitest
|
8
|
+
class BacktraceFilterWithFallback
|
9
|
+
def initialize(preferred, fallback)
|
10
|
+
@preferred = preferred
|
11
|
+
@fallback = fallback
|
12
|
+
end
|
13
|
+
|
14
|
+
def filter(backtrace)
|
15
|
+
filtered = @preferred.filter(backtrace)
|
16
|
+
filtered = @fallback.filter(backtrace) if filtered.empty?
|
17
|
+
filtered
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
8
21
|
class SuppressedSummaryReporter < SummaryReporter
|
9
22
|
# Disable extra failure output after a run if output is inline.
|
10
23
|
def aggregated_results(*)
|
@@ -40,7 +53,9 @@ module Minitest
|
|
40
53
|
def self.plugin_rails_init(options)
|
41
54
|
unless options[:full_backtrace] || ENV["BACKTRACE"]
|
42
55
|
# Plugin can run without Rails loaded, check before filtering.
|
43
|
-
|
56
|
+
if ::Rails.respond_to?(:backtrace_cleaner)
|
57
|
+
Minitest.backtrace_filter = BacktraceFilterWithFallback.new(::Rails.backtrace_cleaner, Minitest.backtrace_filter)
|
58
|
+
end
|
44
59
|
end
|
45
60
|
|
46
61
|
# Suppress summary reports when outputting inline rerun snippets.
|
data/lib/rails/api/task.rb
CHANGED
@@ -19,12 +19,12 @@ module Rails
|
|
19
19
|
|
20
20
|
initializer :set_eager_load, group: :all do
|
21
21
|
if config.eager_load.nil?
|
22
|
-
warn
|
23
|
-
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
|
22
|
+
warn <<~INFO
|
23
|
+
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
* development - set it to false
|
26
|
+
* test - set it to false (unless you use a tool that preloads your test environment)
|
27
|
+
* production - set it to true
|
28
28
|
|
29
29
|
INFO
|
30
30
|
config.eager_load = config.cache_classes
|
@@ -2,7 +2,9 @@
|
|
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"
|
5
6
|
require "active_support/file_update_checker"
|
7
|
+
require "active_support/configuration_file"
|
6
8
|
require "rails/engine/configuration"
|
7
9
|
require "rails/source_annotation_extractor"
|
8
10
|
|
@@ -12,14 +14,15 @@ module Rails
|
|
12
14
|
attr_accessor :allow_concurrency, :asset_host, :autoflush_log,
|
13
15
|
:cache_classes, :cache_store, :consider_all_requests_local, :console,
|
14
16
|
:eager_load, :exceptions_app, :file_watcher, :filter_parameters,
|
15
|
-
:force_ssl, :helpers_paths, :hosts, :
|
16
|
-
:railties_order, :relative_url_root, :secret_key_base,
|
17
|
+
:force_ssl, :helpers_paths, :hosts, :host_authorization, :logger, :log_formatter,
|
18
|
+
:log_tags, :railties_order, :relative_url_root, :secret_key_base,
|
17
19
|
:ssl_options, :public_file_server,
|
18
20
|
:session_options, :time_zone, :reload_classes_only_on_change,
|
19
21
|
:beginning_of_week, :filter_redirect, :x, :enable_dependency_loading,
|
20
22
|
:read_encrypted_secrets, :log_level, :content_security_policy_report_only,
|
21
23
|
:content_security_policy_nonce_generator, :content_security_policy_nonce_directives,
|
22
|
-
:require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path
|
24
|
+
:require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path,
|
25
|
+
:rake_eager_load
|
23
26
|
|
24
27
|
attr_reader :encoding, :api_only, :loaded_config_version, :autoloader
|
25
28
|
|
@@ -31,7 +34,8 @@ module Rails
|
|
31
34
|
@filter_parameters = []
|
32
35
|
@filter_redirect = []
|
33
36
|
@helpers_paths = []
|
34
|
-
@hosts = Rails.env.development?
|
37
|
+
@hosts = Array(([".localhost", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")] if Rails.env.development?))
|
38
|
+
@host_authorization = {}
|
35
39
|
@public_file_server = ActiveSupport::OrderedOptions.new
|
36
40
|
@public_file_server.enabled = true
|
37
41
|
@public_file_server.index_name = "index"
|
@@ -69,6 +73,8 @@ module Rails
|
|
69
73
|
@autoloader = :classic
|
70
74
|
@disable_sandbox = false
|
71
75
|
@add_autoload_paths_to_load_path = true
|
76
|
+
@permissions_policy = nil
|
77
|
+
@rake_eager_load = false
|
72
78
|
end
|
73
79
|
|
74
80
|
# Loads default configurations. See {the result of the method for each version}[https://guides.rubyonrails.org/configuring.html#results-of-config-load-defaults].
|
@@ -110,7 +116,7 @@ module Rails
|
|
110
116
|
|
111
117
|
if respond_to?(:active_support)
|
112
118
|
active_support.use_authenticated_message_encryption = true
|
113
|
-
active_support.
|
119
|
+
active_support.hash_digest_class = ::Digest::SHA1
|
114
120
|
end
|
115
121
|
|
116
122
|
if respond_to?(:action_controller)
|
@@ -131,17 +137,12 @@ module Rails
|
|
131
137
|
|
132
138
|
if respond_to?(:action_dispatch)
|
133
139
|
action_dispatch.use_cookies_with_metadata = true
|
134
|
-
action_dispatch.return_only_media_type_on_content_type = false
|
135
140
|
end
|
136
141
|
|
137
142
|
if respond_to?(:action_mailer)
|
138
143
|
action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
|
139
144
|
end
|
140
145
|
|
141
|
-
if respond_to?(:active_job)
|
142
|
-
active_job.return_false_on_aborted_enqueue = true
|
143
|
-
end
|
144
|
-
|
145
146
|
if respond_to?(:active_storage)
|
146
147
|
active_storage.queues.analysis = :active_storage_analysis
|
147
148
|
active_storage.queues.purge = :active_storage_purge
|
@@ -152,6 +153,54 @@ module Rails
|
|
152
153
|
if respond_to?(:active_record)
|
153
154
|
active_record.collection_cache_versioning = true
|
154
155
|
end
|
156
|
+
when "6.1"
|
157
|
+
load_defaults "6.0"
|
158
|
+
|
159
|
+
self.autoloader = :zeitwerk if %w[ruby truffleruby].include?(RUBY_ENGINE)
|
160
|
+
|
161
|
+
if respond_to?(:active_record)
|
162
|
+
active_record.has_many_inversing = true
|
163
|
+
active_record.legacy_connection_handling = false
|
164
|
+
end
|
165
|
+
|
166
|
+
if respond_to?(:active_storage)
|
167
|
+
active_storage.track_variants = true
|
168
|
+
end
|
169
|
+
|
170
|
+
if respond_to?(:active_job)
|
171
|
+
active_job.retry_jitter = 0.15
|
172
|
+
active_job.skip_after_callbacks_if_terminated = true
|
173
|
+
end
|
174
|
+
|
175
|
+
if respond_to?(:action_dispatch)
|
176
|
+
action_dispatch.cookies_same_site_protection = :lax
|
177
|
+
action_dispatch.ssl_default_redirect_status = 308
|
178
|
+
end
|
179
|
+
|
180
|
+
if respond_to?(:action_controller)
|
181
|
+
action_controller.urlsafe_csrf_tokens = true
|
182
|
+
end
|
183
|
+
|
184
|
+
if respond_to?(:action_view)
|
185
|
+
action_view.form_with_generates_remote_forms = false
|
186
|
+
action_view.preload_links_header = true
|
187
|
+
end
|
188
|
+
|
189
|
+
if respond_to?(:active_storage)
|
190
|
+
active_storage.queues.analysis = nil
|
191
|
+
active_storage.queues.purge = nil
|
192
|
+
end
|
193
|
+
|
194
|
+
if respond_to?(:action_mailbox)
|
195
|
+
action_mailbox.queues.incineration = nil
|
196
|
+
action_mailbox.queues.routing = nil
|
197
|
+
end
|
198
|
+
|
199
|
+
if respond_to?(:action_mailer)
|
200
|
+
action_mailer.deliver_later_queue_name = nil
|
201
|
+
end
|
202
|
+
|
203
|
+
ActiveSupport.utc_to_local_returns_utc_offset_times = true
|
155
204
|
else
|
156
205
|
raise "Unknown version #{target_version.to_s.inspect}"
|
157
206
|
end
|
@@ -222,12 +271,9 @@ module Rails
|
|
222
271
|
path = paths["config/database"].existent.first
|
223
272
|
yaml = Pathname.new(path) if path
|
224
273
|
|
225
|
-
config = if yaml
|
226
|
-
|
227
|
-
|
228
|
-
loaded_yaml = YAML.load(ERB.new(yaml.read).result) || {}
|
229
|
-
shared = loaded_yaml.delete("shared")
|
230
|
-
if shared
|
274
|
+
config = if yaml&.exist?
|
275
|
+
loaded_yaml = ActiveSupport::ConfigurationFile.parse(yaml)
|
276
|
+
if (shared = loaded_yaml.delete("shared"))
|
231
277
|
loaded_yaml.each do |_k, values|
|
232
278
|
values.reverse_merge!(shared)
|
233
279
|
end
|
@@ -242,10 +288,6 @@ module Rails
|
|
242
288
|
end
|
243
289
|
|
244
290
|
config
|
245
|
-
rescue Psych::SyntaxError => e
|
246
|
-
raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \
|
247
|
-
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
248
|
-
"Error: #{e.message}"
|
249
291
|
rescue => e
|
250
292
|
raise e, "Cannot load database configuration:\n#{e.message}", e.backtrace
|
251
293
|
end
|
@@ -302,6 +344,14 @@ module Rails
|
|
302
344
|
end
|
303
345
|
end
|
304
346
|
|
347
|
+
def permissions_policy(&block)
|
348
|
+
if block_given?
|
349
|
+
@permissions_policy = ActionDispatch::PermissionsPolicy.new(&block)
|
350
|
+
else
|
351
|
+
@permissions_policy
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
305
355
|
def autoloader=(autoloader)
|
306
356
|
case autoloader
|
307
357
|
when :classic
|
@@ -332,8 +382,8 @@ module Rails
|
|
332
382
|
end
|
333
383
|
|
334
384
|
def method_missing(method, *args)
|
335
|
-
if method
|
336
|
-
@configurations[
|
385
|
+
if method.end_with?("=")
|
386
|
+
@configurations[:"#{method[0..-2]}"] = args.first
|
337
387
|
else
|
338
388
|
@configurations.fetch(method) {
|
339
389
|
@configurations[method] = ActiveSupport::OrderedOptions.new
|
@@ -13,10 +13,11 @@ module Rails
|
|
13
13
|
|
14
14
|
def build_stack
|
15
15
|
ActionDispatch::MiddlewareStack.new do |middleware|
|
16
|
-
middleware.use ::ActionDispatch::HostAuthorization, config.hosts, config.action_dispatch.hosts_response_app
|
16
|
+
middleware.use ::ActionDispatch::HostAuthorization, config.hosts, config.action_dispatch.hosts_response_app, **config.host_authorization
|
17
17
|
|
18
18
|
if config.force_ssl
|
19
|
-
middleware.use ::ActionDispatch::SSL, **config.ssl_options
|
19
|
+
middleware.use ::ActionDispatch::SSL, **config.ssl_options,
|
20
|
+
ssl_default_redirect_status: config.action_dispatch.ssl_default_redirect_status
|
20
21
|
end
|
21
22
|
|
22
23
|
middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
|
@@ -43,7 +44,7 @@ module Rails
|
|
43
44
|
|
44
45
|
middleware.use ::Rack::Runtime
|
45
46
|
middleware.use ::Rack::MethodOverride unless config.api_only
|
46
|
-
middleware.use ::ActionDispatch::RequestId
|
47
|
+
middleware.use ::ActionDispatch::RequestId, header: config.action_dispatch.request_id_header
|
47
48
|
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
|
48
49
|
|
49
50
|
middleware.use ::Rails::Rack::Logger, config.log_tags
|
@@ -68,6 +69,7 @@ module Rails
|
|
68
69
|
|
69
70
|
unless config.api_only
|
70
71
|
middleware.use ::ActionDispatch::ContentSecurityPolicy::Middleware
|
72
|
+
middleware.use ::ActionDispatch::PermissionsPolicy::Middleware
|
71
73
|
end
|
72
74
|
|
73
75
|
middleware.use ::Rack::Head
|
@@ -60,7 +60,18 @@ module Rails
|
|
60
60
|
|
61
61
|
#{unload_message}
|
62
62
|
|
63
|
-
|
63
|
+
In order to autoload safely at boot time, please wrap your code in a reloader
|
64
|
+
callback this way:
|
65
|
+
|
66
|
+
Rails.application.reloader.to_prepare do
|
67
|
+
# Autoload classes and modules needed at boot time here.
|
68
|
+
end
|
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.
|
64
75
|
WARNING
|
65
76
|
end
|
66
77
|
|
@@ -216,7 +227,9 @@ module Rails
|
|
216
227
|
app.reloader.check = lambda { true }
|
217
228
|
end
|
218
229
|
|
219
|
-
if config.
|
230
|
+
if config.cache_classes
|
231
|
+
# No reloader
|
232
|
+
elsif config.reload_classes_only_on_change
|
220
233
|
reloader = config.file_watcher.new(*watchable_args, &callback)
|
221
234
|
reloaders << reloader
|
222
235
|
|
@@ -5,13 +5,14 @@ require "active_support/core_ext/module/delegation"
|
|
5
5
|
module Rails
|
6
6
|
class Application
|
7
7
|
class RoutesReloader
|
8
|
-
attr_reader :route_sets, :paths
|
8
|
+
attr_reader :route_sets, :paths, :external_routes
|
9
9
|
attr_accessor :eager_load
|
10
10
|
delegate :execute_if_updated, :execute, :updated?, to: :updater
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@paths = []
|
14
14
|
@route_sets = []
|
15
|
+
@external_routes = []
|
15
16
|
@eager_load = false
|
16
17
|
end
|
17
18
|
|
@@ -26,7 +27,13 @@ module Rails
|
|
26
27
|
|
27
28
|
private
|
28
29
|
def updater
|
29
|
-
@updater ||=
|
30
|
+
@updater ||= begin
|
31
|
+
dirs = @external_routes.each_with_object({}) do |dir, hash|
|
32
|
+
hash[dir.to_s] = %w(rb)
|
33
|
+
end
|
34
|
+
|
35
|
+
ActiveSupport::FileUpdateChecker.new(paths, dirs) { reload! }
|
36
|
+
end
|
30
37
|
end
|
31
38
|
|
32
39
|
def clear!
|
data/lib/rails/application.rb
CHANGED
@@ -6,8 +6,8 @@ require "active_support/core_ext/object/blank"
|
|
6
6
|
require "active_support/key_generator"
|
7
7
|
require "active_support/message_verifier"
|
8
8
|
require "active_support/encrypted_configuration"
|
9
|
-
require "active_support/deprecation"
|
10
9
|
require "active_support/hash_with_indifferent_access"
|
10
|
+
require "active_support/configuration_file"
|
11
11
|
require "rails/engine"
|
12
12
|
require "rails/secrets"
|
13
13
|
|
@@ -45,7 +45,7 @@ module Rails
|
|
45
45
|
# process. From the moment you require "config/application.rb" in your app,
|
46
46
|
# the booting process goes like this:
|
47
47
|
#
|
48
|
-
# 1) require "config/boot.rb" to
|
48
|
+
# 1) require "config/boot.rb" to set up load paths
|
49
49
|
# 2) require railties and engines
|
50
50
|
# 3) Define Rails.application as "class MyApp::Application < Rails::Application"
|
51
51
|
# 4) Run config.before_configuration callbacks
|
@@ -205,12 +205,13 @@ module Rails
|
|
205
205
|
|
206
206
|
# Convenience for loading config/foo.yml for the current Rails env.
|
207
207
|
#
|
208
|
-
#
|
208
|
+
# Examples:
|
209
209
|
#
|
210
210
|
# # config/exception_notification.yml:
|
211
211
|
# production:
|
212
212
|
# url: http://127.0.0.1:8080
|
213
213
|
# namespace: my_app_production
|
214
|
+
#
|
214
215
|
# development:
|
215
216
|
# url: http://localhost:3001
|
216
217
|
# namespace: my_app_development
|
@@ -219,28 +220,40 @@ module Rails
|
|
219
220
|
# Rails.application.configure do
|
220
221
|
# config.middleware.use ExceptionNotifier, config_for(:exception_notification)
|
221
222
|
# end
|
223
|
+
#
|
224
|
+
# # You can also store configurations in a shared section which will be
|
225
|
+
# # merged with the environment configuration
|
226
|
+
#
|
227
|
+
# # config/example.yml
|
228
|
+
# shared:
|
229
|
+
# foo:
|
230
|
+
# bar:
|
231
|
+
# baz: 1
|
232
|
+
#
|
233
|
+
# development:
|
234
|
+
# foo:
|
235
|
+
# bar:
|
236
|
+
# qux: 2
|
237
|
+
#
|
238
|
+
# # development environment
|
239
|
+
# Rails.application.config_for(:example)[:foo][:bar]
|
240
|
+
# # => { baz: 1, qux: 2 }
|
222
241
|
def config_for(name, env: Rails.env)
|
223
242
|
yaml = name.is_a?(Pathname) ? name : Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
|
224
243
|
|
225
244
|
if yaml.exist?
|
226
245
|
require "erb"
|
227
|
-
all_configs =
|
228
|
-
config, shared = all_configs[env], all_configs[
|
229
|
-
|
230
|
-
config ||= {} if shared.nil? || shared.is_a?(Hash)
|
246
|
+
all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
|
247
|
+
config, shared = all_configs[env.to_sym], all_configs[:shared]
|
231
248
|
|
232
249
|
if config.is_a?(Hash)
|
233
|
-
ActiveSupport::OrderedOptions.new.update(
|
250
|
+
ActiveSupport::OrderedOptions.new.update(shared&.deep_merge(config) || config)
|
234
251
|
else
|
235
252
|
config || shared
|
236
253
|
end
|
237
254
|
else
|
238
255
|
raise "Could not load configuration. No such file - #{yaml}"
|
239
256
|
end
|
240
|
-
rescue Psych::SyntaxError => error
|
241
|
-
raise "YAML syntax error occurred while parsing #{yaml}. " \
|
242
|
-
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
243
|
-
"Error: #{error.message}"
|
244
257
|
end
|
245
258
|
|
246
259
|
# Stores some of the Rails initial environment parameters which
|
@@ -267,11 +280,13 @@ module Rails
|
|
267
280
|
"action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer,
|
268
281
|
"action_dispatch.cookies_digest" => config.action_dispatch.cookies_digest,
|
269
282
|
"action_dispatch.cookies_rotations" => config.action_dispatch.cookies_rotations,
|
283
|
+
"action_dispatch.cookies_same_site_protection" => coerce_same_site_protection(config.action_dispatch.cookies_same_site_protection),
|
270
284
|
"action_dispatch.use_cookies_with_metadata" => config.action_dispatch.use_cookies_with_metadata,
|
271
285
|
"action_dispatch.content_security_policy" => config.content_security_policy,
|
272
286
|
"action_dispatch.content_security_policy_report_only" => config.content_security_policy_report_only,
|
273
287
|
"action_dispatch.content_security_policy_nonce_generator" => config.content_security_policy_nonce_generator,
|
274
|
-
"action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives
|
288
|
+
"action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives,
|
289
|
+
"action_dispatch.permissions_policy" => config.permissions_policy,
|
275
290
|
)
|
276
291
|
end
|
277
292
|
end
|
@@ -307,6 +322,12 @@ module Rails
|
|
307
322
|
self.class.generators(&blk)
|
308
323
|
end
|
309
324
|
|
325
|
+
# Sends any server called in the instance of a new application up
|
326
|
+
# to the +server+ method defined in Rails::Railtie.
|
327
|
+
def server(&blk)
|
328
|
+
self.class.server(&blk)
|
329
|
+
end
|
330
|
+
|
310
331
|
# Sends the +isolate_namespace+ method up to the class method.
|
311
332
|
def isolate_namespace(mod)
|
312
333
|
self.class.isolate_namespace(mod)
|
@@ -377,20 +398,6 @@ module Rails
|
|
377
398
|
|
378
399
|
attr_writer :config
|
379
400
|
|
380
|
-
# Returns secrets added to config/secrets.yml.
|
381
|
-
#
|
382
|
-
# Example:
|
383
|
-
#
|
384
|
-
# development:
|
385
|
-
# secret_key_base: 836fa3665997a860728bcb9e9a1e704d427cfc920e79d847d79c8a9a907b9e965defa4154b2b86bdec6930adbe33f21364523a6f6ce363865724549fdfc08553
|
386
|
-
# test:
|
387
|
-
# secret_key_base: 5a37811464e7d378488b0f073e2193b093682e4e21f5d6f3ae0a4e1781e61a351fdc878a843424e81c73fb484a40d23f92c8dafac4870e74ede6e5e174423010
|
388
|
-
# production:
|
389
|
-
# secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
390
|
-
# namespace: my_app_production
|
391
|
-
#
|
392
|
-
# +Rails.application.secrets.namespace+ returns +my_app_production+ in the
|
393
|
-
# production environment.
|
394
401
|
def secrets
|
395
402
|
@secrets ||= begin
|
396
403
|
secrets = ActiveSupport::OrderedOptions.new
|
@@ -405,7 +412,7 @@ module Rails
|
|
405
412
|
end
|
406
413
|
end
|
407
414
|
|
408
|
-
attr_writer :secrets
|
415
|
+
attr_writer :secrets, :credentials
|
409
416
|
|
410
417
|
# The secret_key_base is used as the input secret to the application's key generator, which in turn
|
411
418
|
# is used to create all MessageVerifiers/MessageEncryptors, including the ones that sign and encrypt cookies.
|
@@ -481,10 +488,6 @@ module Rails
|
|
481
488
|
config.helpers_paths
|
482
489
|
end
|
483
490
|
|
484
|
-
console do
|
485
|
-
require "pp"
|
486
|
-
end
|
487
|
-
|
488
491
|
console do
|
489
492
|
unless ::Kernel.private_method_defined?(:y)
|
490
493
|
require "psych/y"
|
@@ -516,9 +519,9 @@ module Rails
|
|
516
519
|
def run_tasks_blocks(app) #:nodoc:
|
517
520
|
railties.each { |r| r.run_tasks_blocks(app) }
|
518
521
|
super
|
519
|
-
|
522
|
+
load "rails/tasks.rb"
|
520
523
|
task :environment do
|
521
|
-
ActiveSupport.on_load(:before_initialize) { config.eager_load =
|
524
|
+
ActiveSupport.on_load(:before_initialize) { config.eager_load = config.rake_eager_load }
|
522
525
|
|
523
526
|
require_environment!
|
524
527
|
end
|
@@ -539,6 +542,11 @@ module Rails
|
|
539
542
|
super
|
540
543
|
end
|
541
544
|
|
545
|
+
def run_server_blocks(app) #:nodoc:
|
546
|
+
railties.each { |r| r.run_server_blocks(app) }
|
547
|
+
super
|
548
|
+
end
|
549
|
+
|
542
550
|
# Returns the ordered railties for this application considering railties_order.
|
543
551
|
def ordered_railties #:nodoc:
|
544
552
|
@ordered_railties ||= begin
|
@@ -585,7 +593,7 @@ module Rails
|
|
585
593
|
elsif secret_key_base
|
586
594
|
raise ArgumentError, "`secret_key_base` for #{Rails.env} environment must be a type of String`"
|
587
595
|
else
|
588
|
-
raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `rails credentials:edit`"
|
596
|
+
raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
|
589
597
|
end
|
590
598
|
end
|
591
599
|
|
@@ -617,50 +625,8 @@ module Rails
|
|
617
625
|
config.app_middleware + super
|
618
626
|
end
|
619
627
|
|
620
|
-
|
621
|
-
|
622
|
-
if value.is_a?(Hash)
|
623
|
-
value.each_pair { |k, v| self[k] = v }
|
624
|
-
else
|
625
|
-
super
|
626
|
-
end
|
627
|
-
end
|
628
|
-
|
629
|
-
def []=(key, value)
|
630
|
-
regular_writer(key.to_sym, convert_value(value, for: :assignment))
|
631
|
-
end
|
632
|
-
|
633
|
-
private
|
634
|
-
def convert_key(key)
|
635
|
-
unless key.kind_of?(Symbol)
|
636
|
-
ActiveSupport::Deprecation.warn(<<~MESSAGE.squish)
|
637
|
-
Accessing hashes returned from config_for by non-symbol keys
|
638
|
-
is deprecated and will be removed in Rails 6.1.
|
639
|
-
Use symbols for access instead.
|
640
|
-
MESSAGE
|
641
|
-
|
642
|
-
key = key.to_sym
|
643
|
-
end
|
644
|
-
|
645
|
-
key
|
646
|
-
end
|
647
|
-
|
648
|
-
def convert_value(value, options = {}) # :doc:
|
649
|
-
if value.is_a? Hash
|
650
|
-
if options[:for] == :to_hash
|
651
|
-
value.to_hash
|
652
|
-
else
|
653
|
-
self.class.new(value)
|
654
|
-
end
|
655
|
-
elsif value.is_a?(Array)
|
656
|
-
if options[:for] != :assignment || value.frozen?
|
657
|
-
value = value.dup
|
658
|
-
end
|
659
|
-
value.map! { |e| convert_value(e, options) }
|
660
|
-
else
|
661
|
-
value
|
662
|
-
end
|
663
|
-
end
|
628
|
+
def coerce_same_site_protection(protection)
|
629
|
+
protection.respond_to?(:call) ? protection : proc { protection }
|
664
630
|
end
|
665
631
|
end
|
666
632
|
end
|
@@ -1,21 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/backtrace_cleaner"
|
4
|
+
require "active_support/core_ext/string/access"
|
4
5
|
|
5
6
|
module Rails
|
6
7
|
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
|
7
|
-
APP_DIRS_PATTERN =
|
8
|
+
APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w*\))/
|
8
9
|
RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/
|
9
|
-
EMPTY_STRING = ""
|
10
|
-
SLASH = "/"
|
11
|
-
DOT_SLASH = "./"
|
12
10
|
|
13
11
|
def initialize
|
14
12
|
super
|
15
13
|
@root = "#{Rails.root}/"
|
16
|
-
add_filter
|
17
|
-
|
18
|
-
|
14
|
+
add_filter do |line|
|
15
|
+
line.start_with?(@root) ? line.from(@root.size) : line
|
16
|
+
end
|
17
|
+
add_filter do |line|
|
18
|
+
if RENDER_TEMPLATE_PATTERN.match?(line)
|
19
|
+
line.sub(RENDER_TEMPLATE_PATTERN, "")
|
20
|
+
else
|
21
|
+
line
|
22
|
+
end
|
23
|
+
end
|
19
24
|
add_silencer { |line| !APP_DIRS_PATTERN.match?(line) }
|
20
25
|
end
|
21
26
|
end
|
@@ -40,13 +40,13 @@ class CodeStatistics #:nodoc:
|
|
40
40
|
Hash[@pairs.map { |pair| [pair.first, calculate_directory_statistics(pair.last)] }]
|
41
41
|
end
|
42
42
|
|
43
|
-
def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|coffee|rake)$/)
|
43
|
+
def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|ts|coffee|rake)$/)
|
44
44
|
stats = CodeStatisticsCalculator.new
|
45
45
|
|
46
46
|
Dir.foreach(directory) do |file_name|
|
47
47
|
path = "#{directory}/#{file_name}"
|
48
48
|
|
49
|
-
if File.directory?(path) && (
|
49
|
+
if File.directory?(path) && !file_name.start_with?(".")
|
50
50
|
stats.add(calculate_directory_statistics(path, pattern))
|
51
51
|
elsif file_name&.match?(pattern)
|
52
52
|
stats.add_by_file_path(path)
|
@@ -75,7 +75,7 @@ class CodeStatistics #:nodoc:
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def width_for(label)
|
78
|
-
[@statistics.values.sum { |s| s.
|
78
|
+
[@statistics.values.sum { |s| s.public_send(label) }.to_s.size, HEADERS[label].length].max
|
79
79
|
end
|
80
80
|
|
81
81
|
def print_header
|