railties 7.0.8.7 → 7.2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +210 -272
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.md +99 -0
- data/README.rdoc +4 -4
- data/lib/minitest/rails_plugin.rb +67 -1
- data/lib/rails/all.rb +1 -3
- data/lib/rails/api/task.rb +39 -6
- data/lib/rails/application/bootstrap.rb +28 -10
- data/lib/rails/application/configuration.rb +228 -72
- data/lib/rails/application/default_middleware_stack.rb +8 -2
- data/lib/rails/application/dummy_config.rb +19 -0
- data/lib/rails/application/finisher.rb +50 -33
- data/lib/rails/application.rb +117 -76
- data/lib/rails/backtrace_cleaner.rb +19 -4
- data/lib/rails/cli.rb +5 -3
- data/lib/rails/command/actions.rb +10 -12
- data/lib/rails/command/base.rb +55 -53
- data/lib/rails/command/environment_argument.rb +32 -16
- data/lib/rails/command/helpers/editor.rb +17 -12
- data/lib/rails/command.rb +84 -33
- data/lib/rails/commands/about/about_command.rb +14 -0
- data/lib/rails/commands/app/update_command.rb +102 -0
- data/lib/rails/commands/application/application_command.rb +2 -0
- data/lib/rails/commands/boot/boot_command.rb +14 -0
- data/lib/rails/commands/console/console_command.rb +11 -30
- data/lib/rails/commands/console/irb_console.rb +146 -0
- data/lib/rails/commands/credentials/USAGE +53 -55
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +5 -3
- data/lib/rails/commands/credentials/credentials_command.rb +64 -70
- data/lib/rails/commands/db/system/change/change_command.rb +2 -1
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +32 -131
- data/lib/rails/commands/destroy/destroy_command.rb +3 -2
- data/lib/rails/commands/dev/dev_command.rb +1 -6
- data/lib/rails/commands/devcontainer/devcontainer_command.rb +39 -0
- data/lib/rails/commands/encrypted/USAGE +15 -20
- data/lib/rails/commands/encrypted/encrypted_command.rb +46 -35
- data/lib/rails/commands/gem_help/USAGE +16 -0
- data/lib/rails/commands/gem_help/gem_help_command.rb +13 -0
- data/lib/rails/commands/generate/generate_command.rb +2 -2
- data/lib/rails/commands/help/USAGE +13 -13
- data/lib/rails/commands/help/help_command.rb +21 -2
- data/lib/rails/commands/initializers/initializers_command.rb +1 -4
- data/lib/rails/commands/middleware/middleware_command.rb +17 -0
- data/lib/rails/commands/new/new_command.rb +2 -0
- data/lib/rails/commands/notes/notes_command.rb +2 -1
- data/lib/rails/commands/plugin/plugin_command.rb +2 -0
- data/lib/rails/commands/rake/rake_command.rb +25 -22
- data/lib/rails/commands/restart/restart_command.rb +14 -0
- data/lib/rails/commands/routes/routes_command.rb +13 -1
- data/lib/rails/commands/runner/USAGE +14 -12
- data/lib/rails/commands/runner/runner_command.rb +42 -19
- data/lib/rails/commands/secret/secret_command.rb +13 -0
- data/lib/rails/commands/server/server_command.rb +37 -34
- data/lib/rails/commands/test/USAGE +14 -0
- data/lib/rails/commands/test/test_command.rb +58 -14
- data/lib/rails/commands/unused_routes/unused_routes_command.rb +75 -0
- data/lib/rails/commands/version/version_command.rb +1 -0
- data/lib/rails/configuration.rb +15 -6
- data/lib/rails/console/app.rb +5 -35
- data/lib/rails/console/helpers.rb +5 -16
- data/lib/rails/console/methods.rb +23 -0
- data/lib/rails/deprecator.rb +7 -0
- data/lib/rails/engine/configuration.rb +50 -6
- data/lib/rails/engine.rb +53 -25
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions.rb +6 -15
- data/lib/rails/generators/active_model.rb +28 -14
- data/lib/rails/generators/app_base.rb +382 -88
- data/lib/rails/generators/app_name.rb +3 -14
- data/lib/rails/generators/base.rb +21 -9
- data/lib/rails/generators/database.rb +231 -35
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +2 -0
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +2 -0
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +2 -0
- data/lib/rails/generators/generated_attribute.rb +38 -1
- data/lib/rails/generators/migration.rb +4 -5
- data/lib/rails/generators/model_helpers.rb +2 -1
- data/lib/rails/generators/rails/app/USAGE +22 -6
- data/lib/rails/generators/rails/app/app_generator.rb +135 -86
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +110 -0
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +19 -21
- data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +4 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +8 -1
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/views/pwa/manifest.json.erb.tt +22 -0
- data/lib/rails/generators/rails/app/templates/app/views/pwa/service-worker.js +26 -0
- data/lib/rails/generators/rails/app/templates/bin/brakeman.tt +6 -0
- data/lib/rails/generators/rails/app/templates/bin/rubocop.tt +7 -0
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +15 -2
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +6 -17
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -6
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +10 -3
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbcmysql.yml.tt → trilogy.yml.tt} +12 -7
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +25 -8
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +40 -28
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +20 -13
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.tt +70 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -9
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +11 -13
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +25 -34
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +11 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +6 -4
- data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +15 -0
- data/lib/rails/generators/rails/app/templates/dockerignore.tt +56 -0
- data/lib/rails/generators/rails/app/templates/github/ci.yml.tt +138 -0
- data/lib/rails/generators/rails/app/templates/github/dependabot.yml +12 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +7 -11
- data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
- data/lib/rails/generators/rails/app/templates/public/406-unsupported-browser.html +66 -0
- data/lib/rails/generators/rails/app/templates/public/icon.png +0 -0
- data/lib/rails/generators/rails/app/templates/public/icon.svg +3 -0
- data/lib/rails/generators/rails/app/templates/rubocop.yml.tt +8 -0
- data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +10 -8
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +9 -7
- data/lib/rails/generators/rails/application_record/application_record_generator.rb +4 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +2 -1
- data/lib/rails/generators/rails/controller/USAGE +12 -4
- data/lib/rails/generators/rails/controller/controller_generator.rb +6 -1
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +1 -1
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +29 -24
- data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +8 -0
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +146 -5
- data/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb +166 -0
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/Dockerfile.tt +3 -0
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/compose.yaml.tt +47 -0
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/devcontainer.json.tt +37 -0
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -2
- data/lib/rails/generators/rails/migration/USAGE +21 -11
- data/lib/rails/generators/rails/migration/migration_generator.rb +4 -0
- data/lib/rails/generators/rails/model/model_generator.rb +4 -0
- data/lib/rails/generators/rails/plugin/USAGE +17 -6
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +45 -22
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +7 -3
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +2 -0
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -17
- data/lib/rails/generators/rails/plugin/templates/bin/rubocop.tt +7 -0
- data/lib/rails/generators/rails/plugin/templates/github/ci.yml.tt +103 -0
- data/lib/rails/generators/rails/plugin/templates/github/dependabot.yml +12 -0
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -2
- data/lib/rails/generators/rails/plugin/templates/rubocop.yml.tt +8 -0
- data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +5 -5
- data/lib/rails/generators/rails/resource/resource_generator.rb +6 -0
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -1
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
- data/lib/rails/generators/test_case.rb +2 -2
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +6 -4
- data/lib/rails/generators/test_unit/mailer/templates/preview.rb.tt +3 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +16 -2
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +2 -2
- 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 +2 -0
- data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb.tt +1 -1
- data/lib/rails/generators/testing/assertions.rb +20 -0
- data/lib/rails/generators/testing/{behaviour.rb → behavior.rb} +8 -4
- data/lib/rails/generators.rb +12 -16
- data/lib/rails/health_controller.rb +55 -0
- data/lib/rails/info.rb +3 -3
- data/lib/rails/info_controller.rb +33 -11
- data/lib/rails/mailers_controller.rb +29 -6
- data/lib/rails/paths.rb +15 -12
- data/lib/rails/pwa_controller.rb +15 -0
- data/lib/rails/rack/logger.rb +27 -16
- data/lib/rails/rackup/server.rb +15 -0
- data/lib/rails/railtie/configurable.rb +2 -2
- data/lib/rails/railtie/configuration.rb +14 -1
- data/lib/rails/railtie.rb +33 -34
- data/lib/rails/source_annotation_extractor.rb +67 -18
- data/lib/rails/tasks/engine.rake +8 -8
- data/lib/rails/tasks/framework.rake +2 -34
- data/lib/rails/tasks/log.rake +1 -1
- data/lib/rails/tasks/misc.rake +3 -14
- data/lib/rails/tasks/statistics.rake +5 -4
- data/lib/rails/tasks/tmp.rake +6 -6
- data/lib/rails/tasks/zeitwerk.rake +15 -35
- data/lib/rails/tasks.rb +0 -2
- data/lib/rails/templates/layouts/application.html.erb +1 -1
- data/lib/rails/templates/rails/mailers/email.html.erb +44 -8
- data/lib/rails/templates/rails/mailers/index.html.erb +14 -7
- data/lib/rails/templates/rails/mailers/mailer.html.erb +11 -5
- data/lib/rails/templates/rails/welcome/index.html.erb +5 -2
- data/lib/rails/test_help.rb +11 -18
- data/lib/rails/test_unit/line_filtering.rb +1 -1
- data/lib/rails/test_unit/reporter.rb +14 -4
- data/lib/rails/test_unit/runner.rb +62 -20
- data/lib/rails/test_unit/test_parser.rb +133 -0
- data/lib/rails/test_unit/testing.rake +13 -33
- data/lib/rails/testing/maintain_test_schema.rb +16 -0
- data/lib/rails/version.rb +1 -1
- data/lib/rails/zeitwerk_checker.rb +15 -0
- data/lib/rails.rb +20 -17
- metadata +87 -40
- data/RDOC_MAIN.rdoc +0 -97
- data/lib/rails/app_updater.rb +0 -40
- data/lib/rails/application/dummy_erb_compiler.rb +0 -18
- data/lib/rails/commands/secrets/USAGE +0 -66
- data/lib/rails/commands/secrets/secrets_command.rb +0 -65
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +0 -68
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +0 -70
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +0 -24
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +0 -62
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +0 -53
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +0 -143
- data/lib/rails/generators/rails/app/templates/public/apple-touch-icon-precomposed.png +0 -0
- data/lib/rails/generators/rails/app/templates/public/apple-touch-icon.png +0 -0
- data/lib/rails/generators/rails/app/templates/public/favicon.ico +0 -0
- data/lib/rails/generators/rails/model/USAGE +0 -113
- data/lib/rails/ruby_version_check.rb +0 -15
- data/lib/rails/secrets.rb +0 -110
- data/lib/rails/tasks/middleware.rake +0 -9
- data/lib/rails/tasks/restart.rake +0 -9
@@ -121,6 +121,26 @@ module Rails
|
|
121
121
|
assert_equal(value, create_generated_attribute(attribute_type).default)
|
122
122
|
end
|
123
123
|
end
|
124
|
+
|
125
|
+
# Asserts a given initializer exists. You need to supply a path relative
|
126
|
+
# to the `config/initializers/` directory.
|
127
|
+
#
|
128
|
+
# assert_initializer "mail_interceptors.rb"
|
129
|
+
#
|
130
|
+
# You can also give extra arguments. If the argument is a regexp, it will check if the
|
131
|
+
# regular expression matches the given file content. If it's a string, it compares the
|
132
|
+
# file with the given string:
|
133
|
+
#
|
134
|
+
# assert_initializer "mail_interceptors.rb", /SandboxEmailInterceptor/
|
135
|
+
#
|
136
|
+
# Finally, when a block is given, it yields the file content:
|
137
|
+
#
|
138
|
+
# assert_initializer "mail_interceptors.rb" do |initializer|
|
139
|
+
# assert_match(/SandboxEmailInterceptor/, initializer)
|
140
|
+
# end
|
141
|
+
def assert_initializer(name, *contents, &block)
|
142
|
+
assert_file("config/initializers/#{name}", *contents, &block)
|
143
|
+
end
|
124
144
|
end
|
125
145
|
end
|
126
146
|
end
|
@@ -11,7 +11,7 @@ require "rails/generators"
|
|
11
11
|
module Rails
|
12
12
|
module Generators
|
13
13
|
module Testing
|
14
|
-
module
|
14
|
+
module Behavior
|
15
15
|
extend ActiveSupport::Concern
|
16
16
|
include ActiveSupport::Testing::Stream
|
17
17
|
|
@@ -65,11 +65,15 @@ module Rails
|
|
65
65
|
# You can provide a configuration hash as second argument. This method returns the output
|
66
66
|
# printed by the generator.
|
67
67
|
def run_generator(args = default_arguments, config = {})
|
68
|
-
|
69
|
-
|
70
|
-
args += ["--skip-bootsnap"] unless args.include?("--no-skip-bootsnap") || args.include?("--skip-bootsnap")
|
68
|
+
args += ["--skip-bundle"] unless args.include?("--no-skip-bundle") || args.include?("--dev")
|
69
|
+
args += ["--skip-bootsnap"] unless args.include?("--no-skip-bootsnap") || args.include?("--skip-bootsnap")
|
71
70
|
|
71
|
+
if ENV["RAILS_LOG_TO_STDOUT"] == "true"
|
72
72
|
generator_class.start(args, config.reverse_merge(destination_root: destination_root))
|
73
|
+
else
|
74
|
+
capture(:stdout) do
|
75
|
+
generator_class.start(args, config.reverse_merge(destination_root: destination_root))
|
76
|
+
end
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
data/lib/rails/generators.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
activesupport_path = File.expand_path("../../../activesupport/lib", __dir__)
|
4
|
-
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
|
5
|
-
|
6
3
|
require "thor/group"
|
7
4
|
require "rails/command"
|
8
5
|
|
@@ -33,7 +30,7 @@ module Rails
|
|
33
30
|
rails: {
|
34
31
|
actions: "-a",
|
35
32
|
orm: "-o",
|
36
|
-
javascripts: "-j",
|
33
|
+
javascripts: ["-j", "--js"],
|
37
34
|
resource_controller: "-c",
|
38
35
|
scaffold_controller: "-c",
|
39
36
|
stylesheets: "-y",
|
@@ -63,6 +60,10 @@ module Rails
|
|
63
60
|
}
|
64
61
|
}
|
65
62
|
|
63
|
+
# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
|
64
|
+
# can change when we FileUtils.cd.
|
65
|
+
RAILS_DEV_PATH = File.expand_path("../../..", __dir__) # :nodoc:
|
66
|
+
|
66
67
|
class << self
|
67
68
|
def configure!(config) # :nodoc:
|
68
69
|
api_only! if config.api_only
|
@@ -93,7 +94,7 @@ module Rails
|
|
93
94
|
end
|
94
95
|
|
95
96
|
# Hold configured generators fallbacks. If a plugin developer wants a
|
96
|
-
# generator group to
|
97
|
+
# generator group to fall back to another group in case of missing generators,
|
97
98
|
# they can add a fallback.
|
98
99
|
#
|
99
100
|
# For example, shoulda is considered a test_framework and is an extension
|
@@ -154,7 +155,8 @@ module Rails
|
|
154
155
|
"#{template}:scaffold",
|
155
156
|
"#{template}:mailer",
|
156
157
|
"action_text:install",
|
157
|
-
"action_mailbox:install"
|
158
|
+
"action_mailbox:install",
|
159
|
+
"devcontainer"
|
158
160
|
]
|
159
161
|
end
|
160
162
|
end
|
@@ -166,7 +168,8 @@ module Rails
|
|
166
168
|
|
167
169
|
# Show help message with available generators.
|
168
170
|
def help(command = "generate")
|
169
|
-
puts "Usage:
|
171
|
+
puts "Usage:"
|
172
|
+
puts " bin/rails #{command} GENERATOR [args] [options]"
|
170
173
|
puts
|
171
174
|
puts "General options:"
|
172
175
|
puts " -h, [--help] # Print generator's options and usage"
|
@@ -204,7 +207,6 @@ module Rails
|
|
204
207
|
rails.map! { |n| n.delete_prefix("rails:") }
|
205
208
|
rails.delete("app")
|
206
209
|
rails.delete("plugin")
|
207
|
-
rails.delete("encrypted_secrets")
|
208
210
|
rails.delete("encrypted_file")
|
209
211
|
rails.delete("encryption_key_file")
|
210
212
|
rails.delete("master_key")
|
@@ -264,16 +266,10 @@ module Rails
|
|
264
266
|
run_after_generate_callback if config[:behavior] == :invoke
|
265
267
|
else
|
266
268
|
options = sorted_groups.flat_map(&:last)
|
267
|
-
error
|
268
|
-
|
269
|
-
if error.respond_to?(:detailed_message)
|
270
|
-
formatted_message = error.detailed_message
|
271
|
-
else
|
272
|
-
formatted_message = error.message
|
273
|
-
end
|
269
|
+
error = Command::CorrectableNameError.new("Could not find generator '#{namespace}'.", namespace, options)
|
274
270
|
|
275
271
|
puts <<~MSG
|
276
|
-
#{
|
272
|
+
#{error.detailed_message}
|
277
273
|
Run `bin/rails generate --help` for more options.
|
278
274
|
MSG
|
279
275
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
# Built-in Health Check Endpoint
|
5
|
+
#
|
6
|
+
# \Rails also comes with a built-in health check endpoint that is reachable at
|
7
|
+
# the +/up+ path. This endpoint will return a 200 status code if the app has
|
8
|
+
# booted with no exceptions, and a 500 status code otherwise.
|
9
|
+
#
|
10
|
+
# In production, many applications are required to report their status upstream,
|
11
|
+
# whether it's to an uptime monitor that will page an engineer when things go
|
12
|
+
# wrong, or a load balancer or Kubernetes controller used to determine a pod's
|
13
|
+
# health. This health check is designed to be a one-size fits all that will work
|
14
|
+
# in many situations.
|
15
|
+
#
|
16
|
+
# While any newly generated \Rails applications will have the health check at
|
17
|
+
# +/up+, you can configure the path to be anything you'd like in your
|
18
|
+
# <tt>"config/routes.rb"</tt>:
|
19
|
+
#
|
20
|
+
# Rails.application.routes.draw do
|
21
|
+
# get "healthz" => "rails/health#show", as: :rails_health_check
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# The health check will now be accessible via the +/healthz+ path.
|
25
|
+
#
|
26
|
+
# NOTE: This endpoint does not reflect the status of all of your application's
|
27
|
+
# dependencies, such as the database or Redis cluster. Replace
|
28
|
+
# <tt>"rails/health#show"</tt> with your own controller action if you have
|
29
|
+
# application specific needs.
|
30
|
+
#
|
31
|
+
# Think carefully about what you want to check as it can lead to situations
|
32
|
+
# where your application is being restarted due to a third-party service going
|
33
|
+
# bad. Ideally, you should design your application to handle those outages
|
34
|
+
# gracefully.
|
35
|
+
class HealthController < ActionController::Base
|
36
|
+
rescue_from(Exception) { render_down }
|
37
|
+
|
38
|
+
def show
|
39
|
+
render_up
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def render_up
|
44
|
+
render html: html_status(color: "green")
|
45
|
+
end
|
46
|
+
|
47
|
+
def render_down
|
48
|
+
render html: html_status(color: "red"), status: 500
|
49
|
+
end
|
50
|
+
|
51
|
+
def html_status(color:)
|
52
|
+
%(<!DOCTYPE html><html><body style="background-color: #{color}"></body></html>).html_safe
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/rails/info.rb
CHANGED
@@ -4,7 +4,7 @@ require "cgi"
|
|
4
4
|
|
5
5
|
module Rails
|
6
6
|
# This module helps build the runtime properties that are displayed in
|
7
|
-
# Rails::InfoController responses. These include the active Rails version,
|
7
|
+
# Rails::InfoController responses. These include the active \Rails version,
|
8
8
|
# Ruby version, Rack version, and so on.
|
9
9
|
module Info
|
10
10
|
mattr_accessor :properties, default: []
|
@@ -95,11 +95,11 @@ module Rails
|
|
95
95
|
|
96
96
|
# The name of the database adapter for the current environment.
|
97
97
|
property "Database adapter" do
|
98
|
-
ActiveRecord::Base.
|
98
|
+
ActiveRecord::Base.connection_pool.db_config.adapter
|
99
99
|
end
|
100
100
|
|
101
101
|
property "Database schema version" do
|
102
|
-
ActiveRecord::Base.
|
102
|
+
ActiveRecord::Base.connection_pool.migration_context.current_version rescue nil
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -4,9 +4,11 @@ require "rails/application_controller"
|
|
4
4
|
require "action_dispatch/routing/inspector"
|
5
5
|
|
6
6
|
class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
7
|
-
prepend_view_path ActionDispatch::DebugView::
|
7
|
+
prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATHS
|
8
8
|
layout -> { request.xhr? ? false : "application" }
|
9
9
|
|
10
|
+
RFC2396_PARSER = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::RFC2396_Parser.new
|
11
|
+
|
10
12
|
before_action :require_local!
|
11
13
|
|
12
14
|
def index
|
@@ -19,12 +21,12 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def routes
|
22
|
-
if
|
23
|
-
|
24
|
-
|
24
|
+
if query = params[:query]
|
25
|
+
query = RFC2396_PARSER.escape query
|
26
|
+
|
25
27
|
render json: {
|
26
|
-
exact:
|
27
|
-
fuzzy:
|
28
|
+
exact: matching_routes(query: query, exact_match: true),
|
29
|
+
fuzzy: matching_routes(query: query, exact_match: false)
|
28
30
|
}
|
29
31
|
else
|
30
32
|
@routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
|
@@ -33,11 +35,31 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
33
35
|
end
|
34
36
|
|
35
37
|
private
|
36
|
-
def
|
37
|
-
|
38
|
-
|
38
|
+
def matching_routes(query:, exact_match:)
|
39
|
+
return [] if query.blank?
|
40
|
+
|
41
|
+
normalized_path = ("/" + query).squeeze("/")
|
42
|
+
query_without_url_or_path_suffix = query.gsub(/(\w)(_path$)/, '\1').gsub(/(\w)(_url$)/, '\1')
|
43
|
+
|
44
|
+
_routes.routes.filter_map do |route|
|
45
|
+
route_wrapper = ActionDispatch::Routing::RouteWrapper.new(route)
|
46
|
+
|
47
|
+
if exact_match
|
48
|
+
match = route.path.match(normalized_path)
|
49
|
+
match ||= (query_without_url_or_path_suffix === route_wrapper.name)
|
50
|
+
else
|
51
|
+
match = route_wrapper.path.match(query)
|
52
|
+
match ||= route_wrapper.name.include?(query_without_url_or_path_suffix)
|
53
|
+
end
|
54
|
+
|
55
|
+
match ||= (query === route_wrapper.verb)
|
56
|
+
|
57
|
+
unless match
|
58
|
+
controller_action = RFC2396_PARSER.escape(route_wrapper.reqs)
|
59
|
+
match = exact_match ? (query === controller_action) : controller_action.include?(query)
|
60
|
+
end
|
39
61
|
|
40
|
-
|
41
|
-
|
62
|
+
route_wrapper.path if match
|
63
|
+
end
|
42
64
|
end
|
43
65
|
end
|
@@ -1,26 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rails/application_controller"
|
4
|
+
require "active_support/core_ext/enumerable"
|
4
5
|
|
5
6
|
class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
6
|
-
prepend_view_path ActionDispatch::DebugView::
|
7
|
+
prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATHS
|
7
8
|
|
8
|
-
around_action :set_locale, only: :preview
|
9
|
-
before_action :find_preview, only: :preview
|
9
|
+
around_action :set_locale, only: [:preview, :download]
|
10
|
+
before_action :find_preview, only: [:preview, :download]
|
10
11
|
before_action :require_local!, unless: :show_previews?
|
11
12
|
|
12
|
-
helper_method :part_query, :locale_query
|
13
|
+
helper_method :attachment_url, :part_query, :locale_query
|
13
14
|
|
14
15
|
content_security_policy(false)
|
15
16
|
|
16
17
|
def index
|
17
18
|
@previews = ActionMailer::Preview.all
|
18
|
-
@page_title = "Mailer Previews"
|
19
|
+
@page_title = "Action Mailer Previews"
|
20
|
+
end
|
21
|
+
|
22
|
+
def download
|
23
|
+
@email_action = File.basename(params[:path])
|
24
|
+
if @preview.email_exists?(@email_action)
|
25
|
+
@email = @preview.call(@email_action, params)
|
26
|
+
send_data @email.to_s, filename: "#{@email_action}.eml"
|
27
|
+
else
|
28
|
+
raise AbstractController::ActionNotFound, "Email '#{@email_action}' not found in #{@preview.name}"
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
32
|
def preview
|
22
33
|
if params[:path] == @preview.preview_name
|
23
|
-
@page_title = "Mailer Previews for #{@preview.preview_name}"
|
34
|
+
@page_title = "Action Mailer Previews for #{@preview.preview_name}"
|
24
35
|
render action: "mailer"
|
25
36
|
else
|
26
37
|
@email_action = File.basename(params[:path])
|
@@ -28,6 +39,8 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
|
28
39
|
if @preview.email_exists?(@email_action)
|
29
40
|
@page_title = "Mailer Preview for #{@preview.preview_name}##{@email_action}"
|
30
41
|
@email = @preview.call(@email_action, params)
|
42
|
+
@attachments = attachments_for(@email).reject { |filename, attachment| attachment.inline? }
|
43
|
+
@inline_attachments = attachments_for(@email).select { |filename, attachment| attachment.inline? }
|
31
44
|
|
32
45
|
if params[:part]
|
33
46
|
part_type = Mime::Type.lookup(params[:part])
|
@@ -85,6 +98,16 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
|
85
98
|
end
|
86
99
|
end
|
87
100
|
|
101
|
+
def attachments_for(email)
|
102
|
+
email.all_parts.to_a.select(&:attachment?).index_by do |attachment|
|
103
|
+
attachment.respond_to?(:original_filename) ? attachment.original_filename : attachment.filename
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def attachment_url(attachment)
|
108
|
+
"data:application/octet-stream;charset=utf-8;base64,#{Base64.encode64(attachment.body.to_s)}"
|
109
|
+
end
|
110
|
+
|
88
111
|
def part_query(mime_type)
|
89
112
|
request.query_parameters.merge(part: mime_type).to_query
|
90
113
|
end
|
data/lib/rails/paths.rb
CHANGED
@@ -4,9 +4,9 @@ require "pathname"
|
|
4
4
|
|
5
5
|
module Rails
|
6
6
|
module Paths
|
7
|
-
# This object is an extended hash that behaves as root of the
|
7
|
+
# This object is an extended hash that behaves as root of the Rails::Paths system.
|
8
8
|
# It allows you to collect information about how you want to structure your application
|
9
|
-
# paths through a Hash-like API. It requires you to give a physical path on initialization.
|
9
|
+
# paths through a Hash-like \API. It requires you to give a physical path on initialization.
|
10
10
|
#
|
11
11
|
# root = Root.new "/rails"
|
12
12
|
# root.add "app/controllers", eager_load: true
|
@@ -18,7 +18,8 @@ module Rails
|
|
18
18
|
# path.eager_load? # => true
|
19
19
|
# path.is_a?(Rails::Paths::Path) # => true
|
20
20
|
#
|
21
|
-
# The
|
21
|
+
# The Path[rdoc-ref:Rails::Paths::Path] object is simply an enumerable and
|
22
|
+
# allows you to easily add extra paths:
|
22
23
|
#
|
23
24
|
# path.is_a?(Enumerable) # => true
|
24
25
|
# path.to_ary.inspect # => ["app/controllers"]
|
@@ -26,17 +27,19 @@ module Rails
|
|
26
27
|
# path << "lib/controllers"
|
27
28
|
# path.to_ary.inspect # => ["app/controllers", "lib/controllers"]
|
28
29
|
#
|
29
|
-
# Notice that when you add a path using
|
30
|
-
#
|
31
|
-
#
|
30
|
+
# Notice that when you add a path using #add, the
|
31
|
+
# Path[rdoc-ref:Rails::Paths::Path] object created already contains the path
|
32
|
+
# with the same path value given to #add. In some situations, you may not
|
33
|
+
# want this behavior, so you can give <tt>:with</tt> as option.
|
32
34
|
#
|
33
35
|
# root.add "config/routes", with: "config/routes.rb"
|
34
36
|
# root["config/routes"].inspect # => ["config/routes.rb"]
|
35
37
|
#
|
36
|
-
# The
|
37
|
-
# eager_load
|
38
|
+
# The #add method accepts the following options as arguments:
|
39
|
+
# +eager_load+, +autoload+, +autoload_once+, and +glob+.
|
38
40
|
#
|
39
|
-
# Finally, the
|
41
|
+
# Finally, the Path[rdoc-ref:Rails::Paths::Path] object also provides a few
|
42
|
+
# helpers:
|
40
43
|
#
|
41
44
|
# root = Root.new "/rails"
|
42
45
|
# root.add "app/controllers"
|
@@ -44,7 +47,7 @@ module Rails
|
|
44
47
|
# root["app/controllers"].expanded # => ["/rails/app/controllers"]
|
45
48
|
# root["app/controllers"].existent # => ["/rails/app/controllers"]
|
46
49
|
#
|
47
|
-
# Check the
|
50
|
+
# Check the Rails::Paths::Path documentation for more information.
|
48
51
|
class Root
|
49
52
|
attr_accessor :path
|
50
53
|
|
@@ -102,8 +105,8 @@ module Rails
|
|
102
105
|
private
|
103
106
|
def filter_by(&block)
|
104
107
|
all_paths.find_all(&block).flat_map { |path|
|
105
|
-
paths = path.
|
106
|
-
paths - path.children.flat_map { |p| yield(p) ? [] : p.
|
108
|
+
paths = path.existent_directories
|
109
|
+
paths - path.children.flat_map { |p| yield(p) ? [] : p.existent_directories }
|
107
110
|
}.uniq
|
108
111
|
end
|
109
112
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/application_controller"
|
4
|
+
|
5
|
+
class Rails::PwaController < Rails::ApplicationController # :nodoc:
|
6
|
+
skip_forgery_protection
|
7
|
+
|
8
|
+
def service_worker
|
9
|
+
render template: "pwa/service-worker", layout: false
|
10
|
+
end
|
11
|
+
|
12
|
+
def manifest
|
13
|
+
render template: "pwa/manifest", layout: false
|
14
|
+
end
|
15
|
+
end
|
data/lib/rails/rack/logger.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/core_ext/time/conversions"
|
4
|
-
require "active_support/core_ext/object/blank"
|
5
4
|
require "active_support/log_subscriber"
|
6
5
|
require "rack/body_proxy"
|
7
6
|
|
@@ -21,39 +20,45 @@ module Rails
|
|
21
20
|
def call(env)
|
22
21
|
request = ActionDispatch::Request.new(env)
|
23
22
|
|
24
|
-
if logger.respond_to?(:
|
25
|
-
logger.
|
23
|
+
env["rails.rack_logger_tag_count"] = if logger.respond_to?(:push_tags)
|
24
|
+
logger.push_tags(*compute_tags(request)).size
|
26
25
|
else
|
27
|
-
|
26
|
+
0
|
28
27
|
end
|
28
|
+
|
29
|
+
call_app(request, env)
|
29
30
|
end
|
30
31
|
|
31
32
|
private
|
32
33
|
def call_app(request, env) # :doc:
|
34
|
+
logger_tag_pop_count = env["rails.rack_logger_tag_count"]
|
35
|
+
|
33
36
|
instrumenter = ActiveSupport::Notifications.instrumenter
|
34
|
-
|
35
|
-
|
36
|
-
instrumenter.finish_with_state(instrumenter_state, "request.action_dispatch", request: request)
|
37
|
-
}
|
37
|
+
handle = instrumenter.build_handle("request.action_dispatch", { request: request })
|
38
|
+
handle.start
|
38
39
|
|
39
40
|
logger.info { started_request_message(request) }
|
40
|
-
status, headers, body = @app.call(env)
|
41
|
-
body = ::Rack::BodyProxy.new(body,
|
42
|
-
|
41
|
+
status, headers, body = response = @app.call(env)
|
42
|
+
body = ::Rack::BodyProxy.new(body) { finish_request_instrumentation(handle, logger_tag_pop_count) }
|
43
|
+
|
44
|
+
if response.frozen?
|
45
|
+
[status, headers, body]
|
46
|
+
else
|
47
|
+
response[2] = body
|
48
|
+
response
|
49
|
+
end
|
43
50
|
rescue Exception
|
44
|
-
|
51
|
+
finish_request_instrumentation(handle, logger_tag_pop_count)
|
45
52
|
raise
|
46
|
-
ensure
|
47
|
-
ActiveSupport::LogSubscriber.flush_all!
|
48
53
|
end
|
49
54
|
|
50
55
|
# Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700
|
51
56
|
def started_request_message(request) # :doc:
|
52
|
-
'Started %s "%s" for %s at %s'
|
57
|
+
sprintf('Started %s "%s" for %s at %s',
|
53
58
|
request.raw_request_method,
|
54
59
|
request.filtered_path,
|
55
60
|
request.remote_ip,
|
56
|
-
Time.now
|
61
|
+
Time.now)
|
57
62
|
end
|
58
63
|
|
59
64
|
def compute_tags(request) # :doc:
|
@@ -72,6 +77,12 @@ module Rails
|
|
72
77
|
def logger
|
73
78
|
Rails.logger
|
74
79
|
end
|
80
|
+
|
81
|
+
def finish_request_instrumentation(handle, logger_tag_pop_count)
|
82
|
+
handle.finish
|
83
|
+
logger.pop_tags(logger_tag_pop_count) if logger.respond_to?(:pop_tags) && logger_tag_pop_count > 0
|
84
|
+
ActiveSupport::LogSubscriber.flush_all!
|
85
|
+
end
|
75
86
|
end
|
76
87
|
end
|
77
88
|
end
|
@@ -71,6 +71,11 @@ module Rails
|
|
71
71
|
ActiveSupport.on_load(:after_initialize, yield: true, &block)
|
72
72
|
end
|
73
73
|
|
74
|
+
# Called after application routes have been loaded.
|
75
|
+
def after_routes_loaded(&block)
|
76
|
+
ActiveSupport.on_load(:after_routes_loaded, yield: true, &block)
|
77
|
+
end
|
78
|
+
|
74
79
|
# Array of callbacks defined by #to_prepare.
|
75
80
|
def to_prepare_blocks
|
76
81
|
@@to_prepare_blocks ||= []
|
@@ -87,9 +92,17 @@ module Rails
|
|
87
92
|
end
|
88
93
|
|
89
94
|
private
|
95
|
+
def actual_method?(key)
|
96
|
+
!@@options.key?(key) && respond_to?(key)
|
97
|
+
end
|
98
|
+
|
90
99
|
def method_missing(name, *args, &blk)
|
91
100
|
if name.end_with?("=")
|
92
|
-
|
101
|
+
key = name[0..-2].to_sym
|
102
|
+
if actual_method?(key)
|
103
|
+
raise NoMethodError.new("Cannot assign to `#{key}`, it is a configuration method")
|
104
|
+
end
|
105
|
+
@@options[key] = args.first
|
93
106
|
elsif @@options.key?(name)
|
94
107
|
@@options[name]
|
95
108
|
else
|