railties 6.0.0 → 7.1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +699 -245
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.md +99 -0
- data/README.rdoc +7 -8
- data/lib/minitest/rails_plugin.rb +80 -2
- data/lib/rails/all.rb +0 -1
- data/lib/rails/api/task.rb +37 -5
- data/lib/rails/app_updater.rb +9 -6
- data/lib/rails/application/bootstrap.rb +52 -14
- data/lib/rails/application/configuration.rb +327 -86
- data/lib/rails/application/default_middleware_stack.rb +33 -7
- data/lib/rails/application/dummy_config.rb +19 -0
- data/lib/rails/application/finisher.rb +94 -113
- data/lib/rails/application/routes_reloader.rb +17 -3
- data/lib/rails/application.rb +258 -201
- data/lib/rails/application_controller.rb +3 -4
- data/lib/rails/autoloaders/inflector.rb +21 -0
- data/lib/rails/autoloaders.rb +42 -42
- data/lib/rails/backtrace_cleaner.rb +13 -8
- data/lib/rails/cli.rb +5 -2
- data/lib/rails/code_statistics.rb +6 -4
- data/lib/rails/code_statistics_calculator.rb +16 -7
- data/lib/rails/command/actions.rb +10 -12
- data/lib/rails/command/base.rb +66 -46
- data/lib/rails/command/behavior.rb +3 -3
- data/lib/rails/command/environment_argument.rb +33 -17
- data/lib/rails/command/helpers/editor.rb +17 -12
- data/lib/rails/command.rb +90 -32
- data/lib/rails/commands/about/about_command.rb +14 -0
- data/lib/rails/commands/application/application_command.rb +2 -0
- data/lib/rails/commands/console/console_command.rb +17 -13
- data/lib/rails/commands/credentials/USAGE +54 -39
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +53 -0
- data/lib/rails/commands/credentials/credentials_command.rb +83 -60
- data/lib/rails/commands/db/system/change/change_command.rb +8 -2
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +39 -124
- data/lib/rails/commands/destroy/destroy_command.rb +3 -2
- data/lib/rails/commands/dev/dev_command.rb +1 -6
- 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 +3 -3
- data/lib/rails/commands/help/USAGE +15 -14
- 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 +5 -14
- data/lib/rails/commands/plugin/plugin_command.rb +2 -0
- data/lib/rails/commands/rake/rake_command.rb +27 -23
- 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 +34 -21
- data/lib/rails/commands/secret/secret_command.rb +13 -0
- data/lib/rails/commands/secrets/USAGE +44 -43
- data/lib/rails/commands/secrets/secrets_command.rb +20 -38
- data/lib/rails/commands/server/server_command.rb +40 -64
- data/lib/rails/commands/test/USAGE +14 -0
- data/lib/rails/commands/test/test_command.rb +58 -16
- 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 +53 -23
- data/lib/rails/console/app.rb +1 -4
- data/lib/rails/console/helpers.rb +2 -2
- data/lib/rails/deprecator.rb +7 -0
- data/lib/rails/engine/configuration.rb +54 -9
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +105 -81
- data/lib/rails/gem_version.rb +5 -5
- data/lib/rails/generators/actions/create_migration.rb +9 -5
- data/lib/rails/generators/actions.rb +275 -97
- data/lib/rails/generators/active_model.rb +28 -14
- data/lib/rails/generators/app_base.rb +487 -165
- data/lib/rails/generators/app_name.rb +3 -14
- data/lib/rails/generators/base.rb +42 -31
- data/lib/rails/generators/database.rb +41 -4
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +0 -1
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -1
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +11 -11
- 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 -2
- data/lib/rails/generators/generated_attribute.rb +60 -19
- data/lib/rails/generators/migration.rb +4 -8
- data/lib/rails/generators/model_helpers.rb +29 -4
- data/lib/rails/generators/named_base.rb +15 -15
- data/lib/rails/generators/rails/app/USAGE +23 -6
- data/lib/rails/generators/rails/app/app_generator.rb +151 -80
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +103 -0
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +44 -54
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- 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 +4 -9
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +2 -2
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +19 -15
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +18 -23
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +5 -6
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +17 -16
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +17 -18
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +14 -13
- data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +59 -0
- 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 +32 -14
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +42 -55
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +27 -15
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +3 -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 +3 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +6 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_1.rb.tt +284 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +13 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +13 -15
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +17 -20
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +8 -1
- data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +7 -5
- data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +10 -0
- data/lib/rails/generators/rails/app/templates/dockerignore.tt +43 -0
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +9 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +12 -9
- data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
- 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 +13 -11
- data/lib/rails/generators/rails/application_record/application_record_generator.rb +4 -0
- data/lib/rails/generators/rails/benchmark/USAGE +19 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +30 -0
- data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
- data/lib/rails/generators/rails/controller/USAGE +13 -5
- data/lib/rails/generators/rails/controller/controller_generator.rb +7 -42
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +1 -5
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +30 -25
- data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +8 -0
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +31 -1
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +6 -2
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -2
- data/lib/rails/generators/rails/generator/USAGE +2 -2
- data/lib/rails/generators/rails/generator/generator_generator.rb +0 -1
- data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
- 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 +22 -12
- 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 +86 -46
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +15 -20
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +10 -39
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
- 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/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 -22
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +10 -14
- 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/lib/%namespaced_name%.rb.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +3 -3
- 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 +6 -14
- data/lib/rails/generators/rails/resource/USAGE +4 -4
- data/lib/rails/generators/rails/resource/resource_generator.rb +6 -0
- 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/scaffold_generator.rb +2 -20
- data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +7 -2
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +2 -6
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +7 -11
- data/lib/rails/generators/rails/system_test/USAGE +2 -2
- data/lib/rails/generators/rails/task/USAGE +3 -3
- data/lib/rails/generators/resource_helpers.rb +2 -2
- data/lib/rails/generators/test_case.rb +3 -3
- 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/generator_generator.rb +0 -1
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +3 -3
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +0 -1
- 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 +3 -3
- 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/scaffold_generator.rb +4 -5
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +6 -6
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +8 -8
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +9 -11
- data/lib/rails/generators/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/{behaviour.rb → behavior.rb} +8 -7
- data/lib/rails/generators.rb +43 -45
- data/lib/rails/health_controller.rb +55 -0
- data/lib/rails/info.rb +4 -4
- data/lib/rails/info_controller.rb +30 -13
- data/lib/rails/initializable.rb +1 -1
- data/lib/rails/mailers_controller.rb +18 -9
- data/lib/rails/paths.rb +28 -19
- data/lib/rails/rack/logger.rb +17 -17
- data/lib/rails/rackup/server.rb +15 -0
- data/lib/rails/railtie/configurable.rb +0 -1
- data/lib/rails/railtie/configuration.rb +15 -3
- data/lib/rails/railtie.rb +80 -37
- data/lib/rails/ruby_version_check.rb +5 -3
- data/lib/rails/secrets.rb +14 -9
- data/lib/rails/source_annotation_extractor.rb +69 -34
- data/lib/rails/tasks/engine.rake +8 -11
- data/lib/rails/tasks/framework.rake +4 -6
- data/lib/rails/tasks/log.rake +1 -1
- data/lib/rails/tasks/misc.rake +4 -15
- data/lib/rails/tasks/statistics.rake +9 -6
- data/lib/rails/tasks/tmp.rake +13 -6
- data/lib/rails/tasks/yarn.rake +17 -6
- data/lib/rails/tasks/zeitwerk.rake +16 -41
- data/lib/rails/tasks.rb +0 -6
- data/lib/rails/templates/layouts/application.html.erb +15 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +46 -11
- 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 +65 -48
- data/lib/rails/test_help.rb +13 -14
- data/lib/rails/test_unit/line_filtering.rb +1 -1
- data/lib/rails/test_unit/railtie.rb +0 -4
- data/lib/rails/test_unit/reporter.rb +8 -3
- data/lib/rails/test_unit/runner.rb +61 -19
- data/lib/rails/test_unit/test_parser.rb +88 -0
- data/lib/rails/test_unit/testing.rake +17 -36
- data/lib/rails/testing/maintain_test_schema.rb +16 -0
- data/lib/rails/version.rb +1 -1
- data/lib/rails/welcome_controller.rb +1 -0
- data/lib/rails/zeitwerk_checker.rb +15 -0
- data/lib/rails.rb +31 -23
- metadata +89 -58
- data/RDOC_MAIN.rdoc +0 -98
- data/lib/rails/application/dummy_erb_compiler.rb +0 -18
- data/lib/rails/command/spellchecker.rb +0 -58
- 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/yarn.tt +0 -10
- 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/application_controller_renderer.rb.tt +0 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +0 -7
- 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_0.rb.tt +0 -45
- 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 -17
- 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/model/USAGE +0 -114
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
- 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/middleware.rake +0 -9
- data/lib/rails/tasks/restart.rake +0 -9
- data/lib/rails/tasks/routes.rake +0 -9
data/lib/rails/application.rb
CHANGED
@@ -4,12 +4,14 @@ require "yaml"
|
|
4
4
|
require "active_support/core_ext/hash/keys"
|
5
5
|
require "active_support/core_ext/object/blank"
|
6
6
|
require "active_support/key_generator"
|
7
|
-
require "active_support/
|
8
|
-
require "active_support/encrypted_configuration"
|
7
|
+
require "active_support/message_verifiers"
|
9
8
|
require "active_support/deprecation"
|
9
|
+
require "active_support/encrypted_configuration"
|
10
10
|
require "active_support/hash_with_indifferent_access"
|
11
|
+
require "active_support/configuration_file"
|
11
12
|
require "rails/engine"
|
12
13
|
require "rails/secrets"
|
14
|
+
require "rails/autoloaders"
|
13
15
|
|
14
16
|
module Rails
|
15
17
|
# An Engine with the responsibility of coordinating the whole boot process.
|
@@ -21,12 +23,12 @@ module Rails
|
|
21
23
|
# Rails::Application::Bootstrap) and finishing initializers, after all the others
|
22
24
|
# are executed (check Rails::Application::Finisher).
|
23
25
|
#
|
24
|
-
# == Configuration
|
26
|
+
# == \Configuration
|
25
27
|
#
|
26
28
|
# Besides providing the same configuration as Rails::Engine and Rails::Railtie,
|
27
29
|
# the application object has several specific configurations, for example
|
28
|
-
#
|
29
|
-
#
|
30
|
+
# +enable_reloading+, +consider_all_requests_local+, +filter_parameters+,
|
31
|
+
# +logger+, and so forth.
|
30
32
|
#
|
31
33
|
# Check Rails::Application::Configuration to see them all.
|
32
34
|
#
|
@@ -42,44 +44,21 @@ module Rails
|
|
42
44
|
# == Booting process
|
43
45
|
#
|
44
46
|
# The application is also responsible for setting up and executing the booting
|
45
|
-
# process. From the moment you require
|
47
|
+
# process. From the moment you require <tt>config/application.rb</tt> in your app,
|
46
48
|
# the booting process goes like this:
|
47
49
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# == Multiple Applications
|
62
|
-
#
|
63
|
-
# If you decide to define multiple applications, then the first application
|
64
|
-
# that is initialized will be set to +Rails.application+, unless you override
|
65
|
-
# it with a different application.
|
66
|
-
#
|
67
|
-
# To create a new application, you can instantiate a new instance of a class
|
68
|
-
# that has already been created:
|
69
|
-
#
|
70
|
-
# class Application < Rails::Application
|
71
|
-
# end
|
72
|
-
#
|
73
|
-
# first_application = Application.new
|
74
|
-
# second_application = Application.new(config: first_application.config)
|
75
|
-
#
|
76
|
-
# In the above example, the configuration from the first application was used
|
77
|
-
# to initialize the second application. You can also use the +initialize_copy+
|
78
|
-
# on one of the applications to create a copy of the application which shares
|
79
|
-
# the configuration.
|
80
|
-
#
|
81
|
-
# If you decide to define Rake tasks, runners, or initializers in an
|
82
|
-
# application other than +Rails.application+, then you must run them manually.
|
50
|
+
# 1. <tt>require "config/boot.rb"</tt> to set up load paths.
|
51
|
+
# 2. +require+ railties and engines.
|
52
|
+
# 3. Define +Rails.application+ as <tt>class MyApp::Application < Rails::Application</tt>.
|
53
|
+
# 4. Run +config.before_configuration+ callbacks.
|
54
|
+
# 5. Load <tt>config/environments/ENV.rb</tt>.
|
55
|
+
# 6. Run +config.before_initialize+ callbacks.
|
56
|
+
# 7. Run <tt>Railtie#initializer</tt> defined by railties, engines, and application.
|
57
|
+
# One by one, each engine sets up its load paths and routes, and runs its <tt>config/initializers/*</tt> files.
|
58
|
+
# 8. Custom <tt>Railtie#initializers</tt> added by railties, engines, and applications are executed.
|
59
|
+
# 9. Build the middleware stack and run +to_prepare+ callbacks.
|
60
|
+
# 10. Run +config.before_eager_load+ and +eager_load!+ if +eager_load+ is +true+.
|
61
|
+
# 11. Run +config.after_initialize+ callbacks.
|
83
62
|
class Application < Engine
|
84
63
|
autoload :Bootstrap, "rails/application/bootstrap"
|
85
64
|
autoload :Configuration, "rails/application/configuration"
|
@@ -92,6 +71,8 @@ module Rails
|
|
92
71
|
def inherited(base)
|
93
72
|
super
|
94
73
|
Rails.app_class = base
|
74
|
+
# lib has to be added to $LOAD_PATH unconditionally, even if it's in the
|
75
|
+
# autoload paths and config.add_autoload_paths_to_load_path is false.
|
95
76
|
add_lib_to_load_path!(find_root(base.called_from))
|
96
77
|
ActiveSupport.run_load_hooks(:before_configuration, base)
|
97
78
|
end
|
@@ -118,7 +99,7 @@ module Rails
|
|
118
99
|
|
119
100
|
attr_accessor :assets, :sandbox
|
120
101
|
alias_method :sandbox?, :sandbox
|
121
|
-
attr_reader :reloaders, :reloader, :executor
|
102
|
+
attr_reader :reloaders, :reloader, :executor, :autoloaders
|
122
103
|
|
123
104
|
delegate :default_url_options, :default_url_options=, to: :routes
|
124
105
|
|
@@ -133,13 +114,17 @@ module Rails
|
|
133
114
|
@app_env_config = nil
|
134
115
|
@ordered_railties = nil
|
135
116
|
@railties = nil
|
136
|
-
@
|
117
|
+
@key_generators = {}
|
118
|
+
@message_verifiers = nil
|
119
|
+
@deprecators = nil
|
137
120
|
@ran_load_hooks = false
|
138
121
|
|
139
122
|
@executor = Class.new(ActiveSupport::Executor)
|
140
123
|
@reloader = Class.new(ActiveSupport::Reloader)
|
141
124
|
@reloader.executor = @executor
|
142
125
|
|
126
|
+
@autoloaders = Rails::Autoloaders.new
|
127
|
+
|
143
128
|
# are these actually used?
|
144
129
|
@initial_variable_values = initial_variable_values
|
145
130
|
@block = block
|
@@ -169,15 +154,53 @@ module Rails
|
|
169
154
|
routes_reloader.reload!
|
170
155
|
end
|
171
156
|
|
172
|
-
# Returns
|
173
|
-
|
157
|
+
# Returns a key generator (ActiveSupport::CachingKeyGenerator) for a
|
158
|
+
# specified +secret_key_base+. The return value is memoized, so additional
|
159
|
+
# calls with the same +secret_key_base+ will return the same key generator
|
160
|
+
# instance.
|
161
|
+
def key_generator(secret_key_base = self.secret_key_base)
|
174
162
|
# number of iterations selected based on consultation with the google security
|
175
163
|
# team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220
|
176
|
-
@
|
164
|
+
@key_generators[secret_key_base] ||= ActiveSupport::CachingKeyGenerator.new(
|
177
165
|
ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
|
178
166
|
)
|
179
167
|
end
|
180
168
|
|
169
|
+
# Returns a message verifier factory (ActiveSupport::MessageVerifiers). This
|
170
|
+
# factory can be used as a central point to configure and create message
|
171
|
+
# verifiers (ActiveSupport::MessageVerifier) for your application.
|
172
|
+
#
|
173
|
+
# By default, message verifiers created by this factory will generate
|
174
|
+
# messages using the default ActiveSupport::MessageVerifier options. You can
|
175
|
+
# override these options with a combination of
|
176
|
+
# ActiveSupport::MessageVerifiers#clear_rotations and
|
177
|
+
# ActiveSupport::MessageVerifiers#rotate. However, this must be done prior
|
178
|
+
# to building any message verifier instances. For example, in a
|
179
|
+
# +before_initialize+ block:
|
180
|
+
#
|
181
|
+
# # Use `url_safe: true` when generating messages
|
182
|
+
# config.before_initialize do |app|
|
183
|
+
# app.message_verifiers.clear_rotations
|
184
|
+
# app.message_verifiers.rotate(url_safe: true)
|
185
|
+
# end
|
186
|
+
#
|
187
|
+
# Message verifiers created by this factory will always use a secret derived
|
188
|
+
# from #secret_key_base when generating messages. +clear_rotations+ will not
|
189
|
+
# affect this behavior. However, older +secret_key_base+ values can be
|
190
|
+
# rotated for verifying messages:
|
191
|
+
#
|
192
|
+
# # Fall back to old `secret_key_base` when verifying messages
|
193
|
+
# config.before_initialize do |app|
|
194
|
+
# app.message_verifiers.rotate(secret_key_base: "old secret_key_base")
|
195
|
+
# end
|
196
|
+
#
|
197
|
+
def message_verifiers
|
198
|
+
@message_verifiers ||=
|
199
|
+
ActiveSupport::MessageVerifiers.new do |salt, secret_key_base: self.secret_key_base|
|
200
|
+
key_generator(secret_key_base).generate_key(salt)
|
201
|
+
end.rotate_defaults
|
202
|
+
end
|
203
|
+
|
181
204
|
# Returns a message verifier object.
|
182
205
|
#
|
183
206
|
# This verifier can be used to generate and verify signed messages in the application.
|
@@ -195,64 +218,97 @@ module Rails
|
|
195
218
|
# Rails.application.message_verifier('sensitive_data').verify(message)
|
196
219
|
# # => 'my sensible data'
|
197
220
|
#
|
198
|
-
# See the
|
221
|
+
# See the ActiveSupport::MessageVerifier documentation for more information.
|
199
222
|
def message_verifier(verifier_name)
|
200
|
-
|
201
|
-
|
202
|
-
|
223
|
+
message_verifiers[verifier_name]
|
224
|
+
end
|
225
|
+
|
226
|
+
# A managed collection of deprecators (ActiveSupport::Deprecation::Deprecators).
|
227
|
+
# The collection's configuration methods affect all deprecators in the
|
228
|
+
# collection. Additionally, the collection's +silence+ method silences all
|
229
|
+
# deprecators in the collection for the duration of a given block.
|
230
|
+
def deprecators
|
231
|
+
@deprecators ||= ActiveSupport::Deprecation::Deprecators.new.tap do |deprecators|
|
232
|
+
deprecators[:railties] = Rails.deprecator
|
203
233
|
end
|
204
234
|
end
|
205
235
|
|
206
|
-
# Convenience for loading config/foo.yml for the current Rails env.
|
207
|
-
#
|
236
|
+
# Convenience for loading config/foo.yml for the current \Rails env.
|
208
237
|
# Example:
|
209
238
|
#
|
210
239
|
# # config/exception_notification.yml:
|
211
240
|
# production:
|
212
241
|
# url: http://127.0.0.1:8080
|
213
242
|
# namespace: my_app_production
|
243
|
+
#
|
214
244
|
# development:
|
215
245
|
# url: http://localhost:3001
|
216
246
|
# namespace: my_app_development
|
217
247
|
#
|
248
|
+
# <code></code>
|
249
|
+
#
|
218
250
|
# # config/environments/production.rb
|
219
251
|
# Rails.application.configure do
|
220
252
|
# config.middleware.use ExceptionNotifier, config_for(:exception_notification)
|
221
253
|
# end
|
254
|
+
#
|
255
|
+
# You can also store configurations in a shared section which will be merged
|
256
|
+
# with the environment configuration
|
257
|
+
#
|
258
|
+
# # config/example.yml
|
259
|
+
# shared:
|
260
|
+
# foo:
|
261
|
+
# bar:
|
262
|
+
# baz: 1
|
263
|
+
#
|
264
|
+
# development:
|
265
|
+
# foo:
|
266
|
+
# bar:
|
267
|
+
# qux: 2
|
268
|
+
#
|
269
|
+
# <code></code>
|
270
|
+
#
|
271
|
+
# # development environment
|
272
|
+
# Rails.application.config_for(:example)[:foo][:bar]
|
273
|
+
# # => { baz: 1, qux: 2 }
|
222
274
|
def config_for(name, env: Rails.env)
|
223
|
-
|
224
|
-
yaml = name
|
225
|
-
else
|
226
|
-
yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
|
227
|
-
end
|
275
|
+
yaml = name.is_a?(Pathname) ? name : Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
|
228
276
|
|
229
277
|
if yaml.exist?
|
230
278
|
require "erb"
|
231
|
-
|
232
|
-
config =
|
279
|
+
all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
|
280
|
+
config, shared = all_configs[env.to_sym], all_configs[:shared]
|
281
|
+
|
282
|
+
if shared
|
283
|
+
config = {} if config.nil? && shared.is_a?(Hash)
|
284
|
+
if config.is_a?(Hash) && shared.is_a?(Hash)
|
285
|
+
config = shared.deep_merge(config)
|
286
|
+
elsif config.nil?
|
287
|
+
config = shared
|
288
|
+
end
|
289
|
+
end
|
233
290
|
|
234
|
-
|
235
|
-
|
291
|
+
if config.is_a?(Hash)
|
292
|
+
config = ActiveSupport::OrderedOptions.new.update(config)
|
236
293
|
end
|
294
|
+
|
295
|
+
config
|
237
296
|
else
|
238
297
|
raise "Could not load configuration. No such file - #{yaml}"
|
239
298
|
end
|
240
|
-
rescue Psych::SyntaxError => e
|
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: #{e.message}"
|
244
299
|
end
|
245
300
|
|
246
|
-
# Stores some of the Rails initial environment parameters which
|
301
|
+
# Stores some of the \Rails initial environment parameters which
|
247
302
|
# will be used by middlewares and engines to configure themselves.
|
248
303
|
def env_config
|
249
|
-
@app_env_config ||=
|
250
|
-
|
251
|
-
"action_dispatch.parameter_filter" => config.filter_parameters,
|
304
|
+
@app_env_config ||= super.merge(
|
305
|
+
"action_dispatch.parameter_filter" => filter_parameters,
|
252
306
|
"action_dispatch.redirect_filter" => config.filter_redirect,
|
253
307
|
"action_dispatch.secret_key_base" => secret_key_base,
|
254
308
|
"action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
|
255
309
|
"action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
|
310
|
+
"action_dispatch.log_rescued_responses" => config.action_dispatch.log_rescued_responses,
|
311
|
+
"action_dispatch.debug_exception_log_level" => ActiveSupport::Logger.const_get(config.action_dispatch.debug_exception_log_level.to_s.upcase),
|
256
312
|
"action_dispatch.logger" => Rails.logger,
|
257
313
|
"action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner,
|
258
314
|
"action_dispatch.key_generator" => key_generator,
|
@@ -267,13 +323,14 @@ module Rails
|
|
267
323
|
"action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer,
|
268
324
|
"action_dispatch.cookies_digest" => config.action_dispatch.cookies_digest,
|
269
325
|
"action_dispatch.cookies_rotations" => config.action_dispatch.cookies_rotations,
|
326
|
+
"action_dispatch.cookies_same_site_protection" => coerce_same_site_protection(config.action_dispatch.cookies_same_site_protection),
|
270
327
|
"action_dispatch.use_cookies_with_metadata" => config.action_dispatch.use_cookies_with_metadata,
|
271
328
|
"action_dispatch.content_security_policy" => config.content_security_policy,
|
272
329
|
"action_dispatch.content_security_policy_report_only" => config.content_security_policy_report_only,
|
273
330
|
"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
|
331
|
+
"action_dispatch.content_security_policy_nonce_directives" => config.content_security_policy_nonce_directives,
|
332
|
+
"action_dispatch.permissions_policy" => config.permissions_policy,
|
275
333
|
)
|
276
|
-
end
|
277
334
|
end
|
278
335
|
|
279
336
|
# If you try to define a set of Rake tasks on the instance, these will get
|
@@ -307,6 +364,12 @@ module Rails
|
|
307
364
|
self.class.generators(&blk)
|
308
365
|
end
|
309
366
|
|
367
|
+
# Sends any server called in the instance of a new application up
|
368
|
+
# to the +server+ method defined in Rails::Railtie.
|
369
|
+
def server(&blk)
|
370
|
+
self.class.server(&blk)
|
371
|
+
end
|
372
|
+
|
310
373
|
# Sends the +isolate_namespace+ method up to the class method.
|
311
374
|
def isolate_namespace(mod)
|
312
375
|
self.class.isolate_namespace(mod)
|
@@ -327,30 +390,30 @@ module Rails
|
|
327
390
|
# are changing config.root inside your application definition or having a custom
|
328
391
|
# Rails application, you will need to add lib to $LOAD_PATH on your own in case
|
329
392
|
# you need to load files in lib/ during the application configuration as well.
|
330
|
-
def self.add_lib_to_load_path!(root)
|
331
|
-
path = File.join
|
393
|
+
def self.add_lib_to_load_path!(root) # :nodoc:
|
394
|
+
path = File.join(root, "lib")
|
332
395
|
if File.exist?(path) && !$LOAD_PATH.include?(path)
|
333
396
|
$LOAD_PATH.unshift(path)
|
334
397
|
end
|
335
398
|
end
|
336
399
|
|
337
|
-
def require_environment!
|
400
|
+
def require_environment! # :nodoc:
|
338
401
|
environment = paths["config/environment"].existent.first
|
339
402
|
require environment if environment
|
340
403
|
end
|
341
404
|
|
342
|
-
def routes_reloader
|
405
|
+
def routes_reloader # :nodoc:
|
343
406
|
@routes_reloader ||= RoutesReloader.new
|
344
407
|
end
|
345
408
|
|
346
409
|
# Returns an array of file paths appended with a hash of
|
347
410
|
# directories-extensions suitable for ActiveSupport::FileUpdateChecker
|
348
411
|
# API.
|
349
|
-
def watchable_args
|
412
|
+
def watchable_args # :nodoc:
|
350
413
|
files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
|
351
414
|
|
352
415
|
ActiveSupport::Dependencies.autoload_paths.each do |path|
|
353
|
-
dirs[path.to_s] = [:rb]
|
416
|
+
File.file?(path) ? files << path.to_s : dirs[path.to_s] = [:rb]
|
354
417
|
end
|
355
418
|
|
356
419
|
[files, dirs]
|
@@ -358,40 +421,29 @@ module Rails
|
|
358
421
|
|
359
422
|
# Initialize the application passing the given group. By default, the
|
360
423
|
# group is :default
|
361
|
-
def initialize!(group = :default)
|
424
|
+
def initialize!(group = :default) # :nodoc:
|
362
425
|
raise "Application has been already initialized." if @initialized
|
363
426
|
run_initializers(group, self)
|
364
427
|
@initialized = true
|
365
428
|
self
|
366
429
|
end
|
367
430
|
|
368
|
-
def initializers
|
431
|
+
def initializers # :nodoc:
|
369
432
|
Bootstrap.initializers_for(self) +
|
370
433
|
railties_initializers(super) +
|
371
434
|
Finisher.initializers_for(self)
|
372
435
|
end
|
373
436
|
|
374
|
-
def config
|
437
|
+
def config # :nodoc:
|
375
438
|
@config ||= Application::Configuration.new(self.class.find_root(self.class.called_from))
|
376
439
|
end
|
377
440
|
|
378
441
|
attr_writer :config
|
379
442
|
|
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
443
|
def secrets
|
444
|
+
Rails.deprecator.warn(<<~MSG.squish)
|
445
|
+
`Rails.application.secrets` is deprecated in favor of `Rails.application.credentials` and will be removed in Rails 7.2.
|
446
|
+
MSG
|
395
447
|
@secrets ||= begin
|
396
448
|
secrets = ActiveSupport::OrderedOptions.new
|
397
449
|
files = config.paths["config/secrets"].existent
|
@@ -405,65 +457,81 @@ module Rails
|
|
405
457
|
end
|
406
458
|
end
|
407
459
|
|
408
|
-
attr_writer :secrets
|
460
|
+
attr_writer :secrets, :credentials
|
409
461
|
|
410
462
|
# The secret_key_base is used as the input secret to the application's key generator, which in turn
|
411
|
-
# is used to create all
|
463
|
+
# is used to create all ActiveSupport::MessageVerifier and ActiveSupport::MessageEncryptor instances,
|
464
|
+
# including the ones that sign and encrypt cookies.
|
412
465
|
#
|
413
466
|
# In development and test, this is randomly generated and stored in a
|
414
|
-
# temporary file in <tt>tmp/
|
467
|
+
# temporary file in <tt>tmp/local_secret.txt</tt>.
|
415
468
|
#
|
416
|
-
#
|
417
|
-
#
|
469
|
+
# You can also set <tt>ENV["SECRET_KEY_BASE_DUMMY"]</tt> to trigger the use of a randomly generated
|
470
|
+
# secret_key_base that's stored in a temporary file. This is useful when precompiling assets for
|
471
|
+
# production as part of a build step that otherwise does not need access to the production secrets.
|
472
|
+
#
|
473
|
+
# Dockerfile example: <tt>RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile</tt>.
|
474
|
+
#
|
475
|
+
# In all other environments, we look for it first in <tt>ENV["SECRET_KEY_BASE"]</tt>,
|
476
|
+
# then +credentials.secret_key_base+, and finally +secrets.secret_key_base+. For most applications,
|
418
477
|
# the correct place to store it is in the encrypted credentials file.
|
419
478
|
def secret_key_base
|
420
|
-
if Rails.env.
|
421
|
-
|
479
|
+
if Rails.env.local? || ENV["SECRET_KEY_BASE_DUMMY"]
|
480
|
+
config.secret_key_base ||= generate_local_secret
|
422
481
|
else
|
423
482
|
validate_secret_key_base(
|
424
|
-
ENV["SECRET_KEY_BASE"] || credentials.secret_key_base ||
|
483
|
+
ENV["SECRET_KEY_BASE"] || credentials.secret_key_base || begin
|
484
|
+
secret_skb = secrets_secret_key_base
|
485
|
+
|
486
|
+
if secret_skb.equal?(config.secret_key_base)
|
487
|
+
config.secret_key_base
|
488
|
+
else
|
489
|
+
Rails.deprecator.warn(<<~MSG.squish)
|
490
|
+
Your `secret_key_base` is configured in `Rails.application.secrets`,
|
491
|
+
which is deprecated in favor of `Rails.application.credentials` and
|
492
|
+
will be removed in Rails 7.2.
|
493
|
+
MSG
|
494
|
+
|
495
|
+
secret_skb
|
496
|
+
end
|
497
|
+
end
|
425
498
|
)
|
426
499
|
end
|
427
500
|
end
|
428
501
|
|
429
|
-
#
|
430
|
-
#
|
431
|
-
#
|
432
|
-
#
|
433
|
-
#
|
434
|
-
#
|
435
|
-
#
|
502
|
+
# Returns an ActiveSupport::EncryptedConfiguration instance for the
|
503
|
+
# credentials file specified by +config.credentials.content_path+.
|
504
|
+
#
|
505
|
+
# By default, +config.credentials.content_path+ will point to either
|
506
|
+
# <tt>config/credentials/#{environment}.yml.enc</tt> for the current
|
507
|
+
# environment (for example, +config/credentials/production.yml.enc+ for the
|
508
|
+
# +production+ environment), or +config/credentials.yml.enc+ if that file
|
509
|
+
# does not exist.
|
510
|
+
#
|
511
|
+
# The encryption key is taken from either <tt>ENV["RAILS_MASTER_KEY"]</tt>,
|
512
|
+
# or from the file specified by +config.credentials.key_path+. By default,
|
513
|
+
# +config.credentials.key_path+ will point to either
|
514
|
+
# <tt>config/credentials/#{environment}.key</tt> for the current
|
515
|
+
# environment, or +config/master.key+ if that file does not exist.
|
436
516
|
def credentials
|
437
517
|
@credentials ||= encrypted(config.credentials.content_path, key_path: config.credentials.key_path)
|
438
518
|
end
|
439
519
|
|
440
|
-
#
|
441
|
-
#
|
442
|
-
#
|
443
|
-
# the file with the master key.
|
444
|
-
# The master key is either stored in +config/master.key+ or <tt>ENV["RAILS_MASTER_KEY"]</tt>.
|
445
|
-
#
|
446
|
-
# Rails.application.encrypted("config/mystery_man.txt.enc").read
|
447
|
-
# # => "We've met before, haven't we?"
|
448
|
-
#
|
449
|
-
# It's also possible to interpret encrypted YAML files with +config+.
|
450
|
-
#
|
451
|
-
# Rails.application.encrypted("config/credentials.yml.enc").config
|
452
|
-
# # => { next_guys_line: "I don't think so. Where was it you think we met?" }
|
453
|
-
#
|
454
|
-
# Any top-level configs are also accessible directly on the return value:
|
455
|
-
#
|
456
|
-
# Rails.application.encrypted("config/credentials.yml.enc").next_guys_line
|
457
|
-
# # => "I don't think so. Where was it you think we met?"
|
520
|
+
# Returns an ActiveSupport::EncryptedConfiguration instance for an encrypted
|
521
|
+
# file. By default, the encryption key is taken from either
|
522
|
+
# <tt>ENV["RAILS_MASTER_KEY"]</tt>, or from the +config/master.key+ file.
|
458
523
|
#
|
459
|
-
#
|
460
|
-
# a key in the +ENV+, use:
|
524
|
+
# my_config = Rails.application.encrypted("config/my_config.enc")
|
461
525
|
#
|
462
|
-
#
|
526
|
+
# my_config.read
|
527
|
+
# # => "foo:\n bar: 123\n"
|
463
528
|
#
|
464
|
-
#
|
529
|
+
# my_config.foo.bar
|
530
|
+
# # => 123
|
465
531
|
#
|
466
|
-
#
|
532
|
+
# Encrypted files can be edited with the <tt>bin/rails encrypted:edit</tt>
|
533
|
+
# command. (See the output of <tt>bin/rails encrypted:edit --help</tt> for
|
534
|
+
# more information.)
|
467
535
|
def encrypted(path, key_path: "config/master.key", env_key: "RAILS_MASTER_KEY")
|
468
536
|
ActiveSupport::EncryptedConfiguration.new(
|
469
537
|
config_path: Rails.root.join(path),
|
@@ -473,18 +541,14 @@ module Rails
|
|
473
541
|
)
|
474
542
|
end
|
475
543
|
|
476
|
-
def to_app
|
544
|
+
def to_app # :nodoc:
|
477
545
|
self
|
478
546
|
end
|
479
547
|
|
480
|
-
def helpers_paths
|
548
|
+
def helpers_paths # :nodoc:
|
481
549
|
config.helpers_paths
|
482
550
|
end
|
483
551
|
|
484
|
-
console do
|
485
|
-
require "pp"
|
486
|
-
end
|
487
|
-
|
488
552
|
console do
|
489
553
|
unless ::Kernel.private_method_defined?(:y)
|
490
554
|
require "psych/y"
|
@@ -501,38 +565,52 @@ module Rails
|
|
501
565
|
ordered_railties.flatten - [self]
|
502
566
|
end
|
503
567
|
|
504
|
-
|
568
|
+
def load_generators(app = self) # :nodoc:
|
569
|
+
app.ensure_generator_templates_added
|
570
|
+
super
|
571
|
+
end
|
505
572
|
|
573
|
+
# Eager loads the application code.
|
574
|
+
def eager_load!
|
575
|
+
Rails.autoloaders.each(&:eager_load)
|
576
|
+
end
|
577
|
+
|
578
|
+
protected
|
506
579
|
alias :build_middleware_stack :app
|
507
580
|
|
508
|
-
def run_tasks_blocks(app)
|
581
|
+
def run_tasks_blocks(app) # :nodoc:
|
509
582
|
railties.each { |r| r.run_tasks_blocks(app) }
|
510
583
|
super
|
511
|
-
|
584
|
+
load "rails/tasks.rb"
|
512
585
|
task :environment do
|
513
|
-
ActiveSupport.on_load(:before_initialize) { config.eager_load =
|
586
|
+
ActiveSupport.on_load(:before_initialize) { config.eager_load = config.rake_eager_load }
|
514
587
|
|
515
588
|
require_environment!
|
516
589
|
end
|
517
590
|
end
|
518
591
|
|
519
|
-
def run_generators_blocks(app)
|
592
|
+
def run_generators_blocks(app) # :nodoc:
|
520
593
|
railties.each { |r| r.run_generators_blocks(app) }
|
521
594
|
super
|
522
595
|
end
|
523
596
|
|
524
|
-
def run_runner_blocks(app)
|
597
|
+
def run_runner_blocks(app) # :nodoc:
|
525
598
|
railties.each { |r| r.run_runner_blocks(app) }
|
526
599
|
super
|
527
600
|
end
|
528
601
|
|
529
|
-
def run_console_blocks(app)
|
602
|
+
def run_console_blocks(app) # :nodoc:
|
530
603
|
railties.each { |r| r.run_console_blocks(app) }
|
531
604
|
super
|
532
605
|
end
|
533
606
|
|
607
|
+
def run_server_blocks(app) # :nodoc:
|
608
|
+
railties.each { |r| r.run_server_blocks(app) }
|
609
|
+
super
|
610
|
+
end
|
611
|
+
|
534
612
|
# Returns the ordered railties for this application considering railties_order.
|
535
|
-
def ordered_railties
|
613
|
+
def ordered_railties # :nodoc:
|
536
614
|
@ordered_railties ||= begin
|
537
615
|
order = config.railties_order.map do |railtie|
|
538
616
|
if railtie == :main_app
|
@@ -554,7 +632,7 @@ module Rails
|
|
554
632
|
end
|
555
633
|
end
|
556
634
|
|
557
|
-
def railties_initializers(current)
|
635
|
+
def railties_initializers(current) # :nodoc:
|
558
636
|
initializers = []
|
559
637
|
ordered_railties.reverse.flatten.each do |r|
|
560
638
|
if r == self
|
@@ -566,7 +644,7 @@ module Rails
|
|
566
644
|
initializers
|
567
645
|
end
|
568
646
|
|
569
|
-
def default_middleware_stack
|
647
|
+
def default_middleware_stack # :nodoc:
|
570
648
|
default_stack = DefaultMiddlewareStack.new(self, config, paths)
|
571
649
|
default_stack.build_stack
|
572
650
|
end
|
@@ -577,26 +655,39 @@ module Rails
|
|
577
655
|
elsif secret_key_base
|
578
656
|
raise ArgumentError, "`secret_key_base` for #{Rails.env} environment must be a type of String`"
|
579
657
|
else
|
580
|
-
raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `rails credentials:edit`"
|
658
|
+
raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
|
581
659
|
end
|
582
660
|
end
|
583
661
|
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
key_file = Rails.root.join("tmp/development_secret.txt")
|
662
|
+
def ensure_generator_templates_added
|
663
|
+
configured_paths = config.generators.templates
|
664
|
+
configured_paths.unshift(*(paths["lib/templates"].existent - configured_paths))
|
665
|
+
end
|
589
666
|
|
590
|
-
|
667
|
+
private
|
668
|
+
def generate_local_secret
|
669
|
+
if config.secret_key_base.nil?
|
670
|
+
key_file = Rails.root.join("tmp/local_secret.txt")
|
671
|
+
|
672
|
+
if File.exist?(key_file)
|
673
|
+
config.secret_key_base = File.binread(key_file)
|
674
|
+
elsif secrets_secret_key_base
|
675
|
+
config.secret_key_base = secrets_secret_key_base
|
676
|
+
else
|
591
677
|
random_key = SecureRandom.hex(64)
|
592
678
|
FileUtils.mkdir_p(key_file.dirname)
|
593
679
|
File.binwrite(key_file, random_key)
|
680
|
+
config.secret_key_base = File.binread(key_file)
|
594
681
|
end
|
595
|
-
|
596
|
-
secrets.secret_key_base = File.binread(key_file)
|
597
682
|
end
|
598
683
|
|
599
|
-
|
684
|
+
config.secret_key_base
|
685
|
+
end
|
686
|
+
|
687
|
+
def secrets_secret_key_base
|
688
|
+
Rails.deprecator.silence do
|
689
|
+
secrets.secret_key_base
|
690
|
+
end
|
600
691
|
end
|
601
692
|
|
602
693
|
def build_request(env)
|
@@ -610,51 +701,17 @@ module Rails
|
|
610
701
|
config.app_middleware + super
|
611
702
|
end
|
612
703
|
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
value.each_pair { |k, v| self[k] = v }
|
617
|
-
else
|
618
|
-
super
|
619
|
-
end
|
620
|
-
end
|
704
|
+
def coerce_same_site_protection(protection)
|
705
|
+
protection.respond_to?(:call) ? protection : proc { protection }
|
706
|
+
end
|
621
707
|
|
622
|
-
|
623
|
-
|
708
|
+
def filter_parameters
|
709
|
+
if config.precompile_filter_parameters
|
710
|
+
config.filter_parameters.replace(
|
711
|
+
ActiveSupport::ParameterFilter.precompile_filters(config.filter_parameters)
|
712
|
+
)
|
624
713
|
end
|
625
|
-
|
626
|
-
private
|
627
|
-
|
628
|
-
def convert_key(key)
|
629
|
-
unless key.kind_of?(Symbol)
|
630
|
-
ActiveSupport::Deprecation.warn(<<~MESSAGE.squish)
|
631
|
-
Accessing hashes returned from config_for by non-symbol keys
|
632
|
-
is deprecated and will be removed in Rails 6.1.
|
633
|
-
Use symbols for access instead.
|
634
|
-
MESSAGE
|
635
|
-
|
636
|
-
key = key.to_sym
|
637
|
-
end
|
638
|
-
|
639
|
-
key
|
640
|
-
end
|
641
|
-
|
642
|
-
def convert_value(value, options = {}) # :doc:
|
643
|
-
if value.is_a? Hash
|
644
|
-
if options[:for] == :to_hash
|
645
|
-
value.to_hash
|
646
|
-
else
|
647
|
-
self.class.new(value)
|
648
|
-
end
|
649
|
-
elsif value.is_a?(Array)
|
650
|
-
if options[:for] != :assignment || value.frozen?
|
651
|
-
value = value.dup
|
652
|
-
end
|
653
|
-
value.map! { |e| convert_value(e, options) }
|
654
|
-
else
|
655
|
-
value
|
656
|
-
end
|
657
|
-
end
|
714
|
+
config.filter_parameters
|
658
715
|
end
|
659
716
|
end
|
660
717
|
end
|