railties 5.1.7 → 5.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +77 -241
- data/RDOC_MAIN.rdoc +61 -43
- data/README.rdoc +1 -2
- data/exe/rails +3 -2
- data/lib/minitest/rails_plugin.rb +9 -13
- data/lib/rails.rb +4 -2
- data/lib/rails/all.rb +3 -0
- data/lib/rails/api/generator.rb +10 -1
- data/lib/rails/api/task.rb +11 -1
- data/lib/rails/app_loader.rb +18 -5
- data/lib/rails/app_updater.rb +34 -0
- data/lib/rails/application.rb +90 -18
- data/lib/rails/application/bootstrap.rb +2 -0
- data/lib/rails/application/configuration.rb +79 -36
- data/lib/rails/application/default_middleware_stack.rb +7 -1
- data/lib/rails/application/finisher.rb +3 -1
- data/lib/rails/application/routes_reloader.rb +21 -3
- data/lib/rails/application_controller.rb +3 -1
- data/lib/rails/backtrace_cleaner.rb +3 -1
- data/lib/rails/cli.rb +2 -0
- data/lib/rails/code_statistics.rb +2 -0
- data/lib/rails/code_statistics_calculator.rb +2 -0
- data/lib/rails/command.rb +3 -1
- data/lib/rails/command/actions.rb +6 -4
- data/lib/rails/command/base.rb +5 -3
- data/lib/rails/command/behavior.rb +2 -0
- data/lib/rails/command/environment_argument.rb +14 -1
- data/lib/rails/command/helpers/editor.rb +35 -0
- data/lib/rails/commands.rb +2 -0
- data/lib/rails/commands/application/application_command.rb +2 -0
- data/lib/rails/commands/console/console_command.rb +2 -3
- data/lib/rails/commands/credentials/USAGE +40 -0
- data/lib/rails/commands/credentials/credentials_command.rb +72 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +18 -7
- data/lib/rails/commands/destroy/destroy_command.rb +2 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +77 -0
- data/lib/rails/commands/generate/generate_command.rb +2 -0
- data/lib/rails/commands/help/help_command.rb +2 -0
- data/lib/rails/commands/new/new_command.rb +2 -0
- data/lib/rails/commands/plugin/plugin_command.rb +2 -0
- data/lib/rails/commands/rake/rake_command.rb +2 -0
- data/lib/rails/commands/runner/USAGE +3 -0
- data/lib/rails/commands/runner/runner_command.rb +7 -3
- data/lib/rails/commands/secrets/secrets_command.rb +15 -10
- data/lib/rails/commands/server/server_command.rb +24 -3
- data/lib/rails/commands/test/test_command.rb +18 -23
- data/lib/rails/commands/version/version_command.rb +2 -0
- data/lib/rails/configuration.rb +2 -0
- data/lib/rails/console/app.rb +2 -0
- data/lib/rails/console/helpers.rb +2 -0
- data/lib/rails/dev_caching.rb +2 -1
- data/lib/rails/engine.rb +3 -1
- data/lib/rails/engine/commands.rb +2 -0
- data/lib/rails/engine/configuration.rb +2 -0
- data/lib/rails/engine/railties.rb +2 -0
- data/lib/rails/engine/updater.rb +3 -1
- data/lib/rails/gem_version.rb +5 -3
- data/lib/rails/generators.rb +8 -3
- data/lib/rails/generators/actions.rb +53 -24
- data/lib/rails/generators/actions/create_migration.rb +2 -0
- data/lib/rails/generators/active_model.rb +2 -0
- data/lib/rails/generators/app_base.rb +94 -57
- data/lib/rails/generators/base.rb +40 -1
- data/lib/rails/generators/css/assets/assets_generator.rb +3 -1
- data/lib/rails/generators/css/scaffold/scaffold_generator.rb +5 -3
- data/lib/rails/generators/erb.rb +2 -0
- data/lib/rails/generators/erb/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/erb/controller/templates/{view.html.erb → view.html.erb.tt} +0 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +2 -0
- data/lib/rails/generators/erb/mailer/templates/{view.html.erb → view.html.erb.tt} +0 -0
- data/lib/rails/generators/erb/mailer/templates/{view.text.erb → view.text.erb.tt} +0 -0
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
- data/lib/rails/generators/erb/scaffold/templates/{_form.html.erb → _form.html.erb.tt} +4 -4
- data/lib/rails/generators/erb/scaffold/templates/{edit.html.erb → edit.html.erb.tt} +0 -0
- data/lib/rails/generators/erb/scaffold/templates/{index.html.erb → index.html.erb.tt} +4 -4
- data/lib/rails/generators/erb/scaffold/templates/{new.html.erb → new.html.erb.tt} +0 -0
- data/lib/rails/generators/erb/scaffold/templates/{show.html.erb → show.html.erb.tt} +0 -0
- data/lib/rails/generators/generated_attribute.rb +3 -1
- data/lib/rails/generators/js/assets/assets_generator.rb +3 -1
- data/lib/rails/generators/migration.rb +2 -0
- data/lib/rails/generators/model_helpers.rb +2 -0
- data/lib/rails/generators/named_base.rb +35 -45
- data/lib/rails/generators/rails/app/app_generator.rb +64 -23
- data/lib/rails/generators/rails/app/templates/{Gemfile → Gemfile.tt} +17 -6
- data/lib/rails/generators/rails/app/templates/{README.md → README.md.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/{Rakefile → Rakefile.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +3 -0
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/{cable.js → cable.js.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/{application.css → application.css.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/{channel.rb → channel.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/{connection.rb → connection.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +1 -4
- data/lib/rails/generators/rails/app/templates/app/helpers/{application_helper.rb → application_helper.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/jobs/{application_job.rb → application_job.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/mailers/{application_mailer.rb → application_mailer.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/models/{application_record.rb → application_record.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/bin/bundle.tt +2 -0
- data/lib/rails/generators/rails/app/templates/bin/{rails → rails.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/bin/{rake → rake.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +5 -5
- data/lib/rails/generators/rails/app/templates/bin/update.tt +7 -3
- data/lib/rails/generators/rails/app/templates/bin/{yarn → yarn.tt} +3 -3
- data/lib/rails/generators/rails/app/templates/{config.ru → config.ru.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/{application.rb → application.rb.tt} +2 -1
- data/lib/rails/generators/rails/app/templates/config/{boot.rb → boot.rb.tt} +1 -0
- data/lib/rails/generators/rails/app/templates/config/{cable.yml → cable.yml.tt} +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/{frontbase.yml → frontbase.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{ibm_db.yml → ibm_db.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbc.yml → jdbc.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbcmysql.yml → jdbcmysql.yml.tt} +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbcpostgresql.yml → jdbcpostgresql.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbcsqlite3.yml → jdbcsqlite3.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{mysql.yml → mysql.yml.tt} +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/{oracle.yml → oracle.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{postgresql.yml → postgresql.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{sqlite3.yml → sqlite3.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{sqlserver.yml → sqlserver.yml.tt} +2 -2
- data/lib/rails/generators/rails/app/templates/config/{environment.rb → environment.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +7 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +12 -7
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +8 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/{application_controller_renderer.rb → application_controller_renderer.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{backtrace_silencers.rb → backtrace_silencers.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +20 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{cookies_serializer.rb → cookies_serializer.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{cors.rb → cors.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{filter_parameter_logging.rb → filter_parameter_logging.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{inflections.rb → inflections.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{mime_types.rb → mime_types.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +27 -0
- data/lib/rails/generators/rails/app/templates/config/{puma.rb → puma.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/{routes.rb → routes.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/{spring.rb → spring.rb.tt} +2 -2
- data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +35 -0
- data/lib/rails/generators/rails/app/templates/{gitignore → gitignore.tt} +9 -1
- data/lib/rails/generators/rails/app/templates/{package.json → package.json.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -0
- data/lib/rails/generators/rails/app/templates/test/{application_system_test_case.rb → application_system_test_case.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/test/{test_helper.rb → test_helper.rb.tt} +1 -2
- data/lib/rails/generators/rails/application_record/application_record_generator.rb +9 -0
- data/lib/rails/generators/rails/assets/assets_generator.rb +2 -0
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +1 -1
- data/lib/rails/generators/rails/controller/controller_generator.rb +11 -9
- data/lib/rails/generators/rails/controller/templates/{controller.rb → controller.rb.tt} +0 -0
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +48 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +38 -0
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +57 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -0
- data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
- data/lib/rails/generators/rails/helper/helper_generator.rb +2 -0
- data/lib/rails/generators/rails/helper/templates/{helper.rb → helper.rb.tt} +0 -0
- data/lib/rails/generators/rails/integration_test/integration_test_generator.rb +2 -0
- data/lib/rails/generators/rails/master_key/master_key_generator.rb +51 -0
- data/lib/rails/generators/rails/migration/migration_generator.rb +2 -0
- data/lib/rails/generators/rails/model/model_generator.rb +2 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +18 -9
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +24 -0
- data/lib/rails/generators/rails/plugin/templates/{Gemfile → Gemfile.tt} +1 -0
- data/lib/rails/generators/rails/plugin/templates/{MIT-LICENSE → MIT-LICENSE.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/{README.md → README.md.tt} +1 -1
- data/lib/rails/generators/rails/plugin/templates/{Rakefile → Rakefile.tt} +6 -7
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +21 -4
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/config/{routes.rb → routes.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +18 -0
- data/lib/rails/generators/rails/plugin/templates/lib/{%namespaced_name%.rb → %namespaced_name%.rb.tt} +3 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/{engine.rb → engine.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/{version.rb → version.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/lib/tasks/{%namespaced_name%_tasks.rake → %namespaced_name%_tasks.rake.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/rails/{application.rb → application.rb.tt} +6 -3
- data/lib/rails/generators/rails/plugin/templates/rails/{boot.rb → boot.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/rails/{dummy_manifest.js → dummy_manifest.js.tt} +0 -1
- data/lib/rails/generators/rails/plugin/templates/rails/{engine_manifest.js → engine_manifest.js.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/rails/{javascripts.js → javascripts.js.tt} +3 -0
- data/lib/rails/generators/rails/plugin/templates/rails/{routes.rb → routes.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/test/{%namespaced_name%_test.rb → %namespaced_name%_test.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/test/{application_system_test_case.rb → application_system_test_case.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/test/integration/{navigation_test.rb → navigation_test.rb.tt} +0 -1
- data/lib/rails/generators/rails/plugin/templates/test/{test_helper.rb → test_helper.rb.tt} +7 -6
- data/lib/rails/generators/rails/resource/USAGE +1 -1
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -0
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +21 -24
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -3
- data/lib/rails/generators/rails/scaffold_controller/USAGE +1 -1
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/{api_controller.rb → api_controller.rb.tt} +0 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/{controller.rb → controller.rb.tt} +2 -2
- data/lib/rails/generators/rails/system_test/system_test_generator.rb +2 -0
- data/lib/rails/generators/rails/task/task_generator.rb +2 -0
- data/lib/rails/generators/rails/task/templates/{task.rb → task.rb.tt} +0 -0
- data/lib/rails/generators/resource_helpers.rb +2 -0
- data/lib/rails/generators/test_case.rb +4 -2
- data/lib/rails/generators/test_unit.rb +2 -0
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/test_unit/controller/templates/{functional_test.rb → functional_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +2 -0
- data/lib/rails/generators/test_unit/generator/templates/{generator_test.rb → generator_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/helper/helper_generator.rb +2 -0
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -0
- data/lib/rails/generators/test_unit/integration/templates/{integration_test.rb → integration_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/job/job_generator.rb +3 -1
- data/lib/rails/generators/test_unit/job/templates/{unit_test.rb.erb → unit_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +2 -0
- data/lib/rails/generators/test_unit/mailer/templates/{functional_test.rb → functional_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/model/model_generator.rb +2 -0
- data/lib/rails/generators/test_unit/model/templates/{fixtures.yml → fixtures.yml.tt} +0 -0
- data/lib/rails/generators/test_unit/model/templates/{unit_test.rb → unit_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -0
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +17 -4
- data/lib/rails/generators/test_unit/scaffold/templates/{api_functional_test.rb → api_functional_test.rb.tt} +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/{functional_test.rb → functional_test.rb.tt} +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +49 -0
- data/lib/rails/generators/test_unit/system/system_generator.rb +3 -1
- data/lib/rails/generators/test_unit/system/templates/{application_system_test_case.rb → application_system_test_case.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/system/templates/{system_test.rb → system_test.rb.tt} +0 -0
- data/lib/rails/generators/testing/assertions.rb +7 -1
- data/lib/rails/generators/testing/behaviour.rb +8 -6
- data/lib/rails/generators/testing/setup_and_teardown.rb +2 -0
- data/lib/rails/info.rb +6 -3
- data/lib/rails/info_controller.rb +2 -0
- data/lib/rails/initializable.rb +2 -0
- data/lib/rails/mailers_controller.rb +9 -1
- data/lib/rails/paths.rb +2 -0
- data/lib/rails/plugin/test.rb +4 -2
- data/lib/rails/rack.rb +2 -0
- data/lib/rails/rack/logger.rb +5 -3
- data/lib/rails/railtie.rb +9 -4
- data/lib/rails/railtie/configurable.rb +2 -0
- data/lib/rails/railtie/configuration.rb +2 -0
- data/lib/rails/ruby_version_check.rb +3 -1
- data/lib/rails/secrets.rb +2 -17
- data/lib/rails/source_annotation_extractor.rb +4 -2
- data/lib/rails/tasks.rb +2 -0
- data/lib/rails/tasks/annotations.rake +2 -0
- data/lib/rails/tasks/dev.rake +2 -0
- data/lib/rails/tasks/engine.rake +7 -2
- data/lib/rails/tasks/framework.rake +9 -24
- data/lib/rails/tasks/initializers.rake +2 -0
- data/lib/rails/tasks/log.rake +2 -0
- data/lib/rails/tasks/middleware.rake +2 -0
- data/lib/rails/tasks/misc.rake +2 -0
- data/lib/rails/tasks/restart.rake +2 -1
- data/lib/rails/tasks/routes.rake +2 -0
- data/lib/rails/tasks/statistics.rake +2 -0
- data/lib/rails/tasks/tmp.rake +11 -2
- data/lib/rails/tasks/yarn.rake +3 -1
- data/lib/rails/templates/rails/mailers/email.html.erb +3 -3
- data/lib/rails/templates/rails/welcome/index.html.erb +14 -4
- data/lib/rails/test_help.rb +2 -0
- data/lib/rails/test_unit/line_filtering.rb +2 -1
- data/lib/rails/test_unit/railtie.rb +2 -0
- data/lib/rails/test_unit/reporter.rb +5 -10
- data/lib/rails/test_unit/runner.rb +3 -3
- data/lib/rails/test_unit/testing.rake +3 -1
- data/lib/rails/version.rb +2 -0
- data/lib/rails/welcome_controller.rb +2 -0
- metadata +121 -107
- data/lib/rails/generators/rails/app/templates/bin/bundle +0 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt +0 -16
- data/lib/rails/generators/rails/app/templates/config/secrets.yml +0 -32
- data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +0 -70
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +0 -33
- data/lib/rails/generators/rails/plugin/templates/gitignore +0 -9
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rails
|
2
4
|
class Application
|
3
5
|
class DefaultMiddlewareStack
|
@@ -10,7 +12,7 @@ module Rails
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def build_stack
|
13
|
-
ActionDispatch::MiddlewareStack.new
|
15
|
+
ActionDispatch::MiddlewareStack.new do |middleware|
|
14
16
|
if config.force_ssl
|
15
17
|
middleware.use ::ActionDispatch::SSL, config.ssl_options
|
16
18
|
end
|
@@ -61,6 +63,10 @@ module Rails
|
|
61
63
|
middleware.use ::ActionDispatch::Flash
|
62
64
|
end
|
63
65
|
|
66
|
+
unless config.api_only
|
67
|
+
middleware.use ::ActionDispatch::ContentSecurityPolicy::Middleware
|
68
|
+
end
|
69
|
+
|
64
70
|
middleware.use ::Rack::Head
|
65
71
|
middleware.use ::Rack::ConditionalGet
|
66
72
|
middleware.use ::Rack::ETag, "no-cache"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rails
|
2
4
|
class Application
|
3
5
|
module Finisher
|
@@ -125,7 +127,7 @@ module Rails
|
|
125
127
|
initializer :set_routes_reloader_hook do |app|
|
126
128
|
reloader = routes_reloader
|
127
129
|
reloader.eager_load = app.config.eager_load
|
128
|
-
reloader.
|
130
|
+
reloader.execute_if_updated
|
129
131
|
reloaders << reloader
|
130
132
|
app.reloader.to_run do
|
131
133
|
# We configure #execute rather than #execute_if_updated because if
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/module/delegation"
|
2
4
|
|
3
5
|
module Rails
|
@@ -5,7 +7,7 @@ module Rails
|
|
5
7
|
class RoutesReloader
|
6
8
|
attr_reader :route_sets, :paths
|
7
9
|
attr_accessor :eager_load
|
8
|
-
delegate :
|
10
|
+
delegate :updated?, to: :updater
|
9
11
|
|
10
12
|
def initialize
|
11
13
|
@paths = []
|
@@ -17,15 +19,31 @@ module Rails
|
|
17
19
|
clear!
|
18
20
|
load_paths
|
19
21
|
finalize!
|
20
|
-
route_sets.each(&:eager_load!) if eager_load
|
21
22
|
ensure
|
22
23
|
revert
|
23
24
|
end
|
24
25
|
|
26
|
+
def execute
|
27
|
+
ret = updater.execute
|
28
|
+
route_sets.each(&:eager_load!) if eager_load
|
29
|
+
ret
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute_if_updated
|
33
|
+
if updated = updater.execute_if_updated
|
34
|
+
route_sets.each(&:eager_load!) if eager_load
|
35
|
+
end
|
36
|
+
updated
|
37
|
+
end
|
38
|
+
|
25
39
|
private
|
26
40
|
|
27
41
|
def updater
|
28
|
-
@updater ||=
|
42
|
+
@updater ||= begin
|
43
|
+
updater = ActiveSupport::FileUpdateChecker.new(paths) { reload! }
|
44
|
+
updater.execute
|
45
|
+
updater
|
46
|
+
end
|
29
47
|
end
|
30
48
|
|
31
49
|
def clear!
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/backtrace_cleaner"
|
2
4
|
|
3
5
|
module Rails
|
@@ -16,7 +18,7 @@ module Rails
|
|
16
18
|
add_filter { |line| line.sub(DOT_SLASH, SLASH) } # for tests
|
17
19
|
|
18
20
|
add_gem_filters
|
19
|
-
add_silencer { |line| line
|
21
|
+
add_silencer { |line| !APP_DIRS_PATTERN.match?(line) }
|
20
22
|
end
|
21
23
|
|
22
24
|
private
|
data/lib/rails/cli.rb
CHANGED
data/lib/rails/command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support"
|
2
4
|
require "active_support/dependencies/autoload"
|
3
5
|
require "active_support/core_ext/enumerable"
|
@@ -23,7 +25,7 @@ module Rails
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def environment # :nodoc:
|
26
|
-
ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
28
|
+
ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development"
|
27
29
|
end
|
28
30
|
|
29
31
|
# Receives a namespace, arguments and the behavior to invoke the command.
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rails
|
2
4
|
module Command
|
3
5
|
module Actions
|
4
|
-
# Change to the application's path if there is no config.ru file in current directory.
|
5
|
-
# This allows us to run
|
6
|
-
# the main config.ru and properly set the tmp directory.
|
6
|
+
# Change to the application's path if there is no <tt>config.ru</tt> file in current directory.
|
7
|
+
# This allows us to run <tt>rails server</tt> from other directories, but still get
|
8
|
+
# the main <tt>config.ru</tt> and properly set the <tt>tmp</tt> directory.
|
7
9
|
def set_application_directory!
|
8
|
-
Dir.chdir(File.expand_path("
|
10
|
+
Dir.chdir(File.expand_path("../..", APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
|
9
11
|
end
|
10
12
|
|
11
13
|
def require_application_and_environment!
|
data/lib/rails/command/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "thor"
|
2
4
|
require "erb"
|
3
5
|
|
@@ -73,7 +75,7 @@ module Rails
|
|
73
75
|
|
74
76
|
# Use Rails' default banner.
|
75
77
|
def banner(*)
|
76
|
-
"#{executable} #{arguments.map(&:usage).join(' ')} [options]".squish
|
78
|
+
"#{executable} #{arguments.map(&:usage).join(' ')} [options]".squish
|
77
79
|
end
|
78
80
|
|
79
81
|
# Sets the base_name taking into account the current class namespace.
|
@@ -110,8 +112,8 @@ module Rails
|
|
110
112
|
# Default file root to place extra files a command might need, placed
|
111
113
|
# one folder above the command file.
|
112
114
|
#
|
113
|
-
# For a
|
114
|
-
# would return
|
115
|
+
# For a Rails::Command::TestCommand placed in <tt>rails/command/test_command.rb</tt>
|
116
|
+
# would return <tt>rails/test</tt>.
|
115
117
|
def default_command_root
|
116
118
|
path = File.expand_path(File.join("../commands", command_root_namespace), __dir__)
|
117
119
|
path if File.exist?(path)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support"
|
2
4
|
|
3
5
|
module Rails
|
@@ -7,13 +9,24 @@ module Rails
|
|
7
9
|
|
8
10
|
included do
|
9
11
|
argument :environment, optional: true, banner: "environment"
|
12
|
+
|
13
|
+
class_option :environment, aliases: "-e", type: :string,
|
14
|
+
desc: "Specifies the environment to run this console under (test/development/production)."
|
10
15
|
end
|
11
16
|
|
12
17
|
private
|
13
18
|
def extract_environment_option_from_argument
|
14
19
|
if environment
|
15
20
|
self.options = options.merge(environment: acceptable_environment(environment))
|
16
|
-
|
21
|
+
|
22
|
+
ActiveSupport::Deprecation.warn "Passing the environment's name as a " \
|
23
|
+
"regular argument is deprecated and " \
|
24
|
+
"will be removed in the next Rails " \
|
25
|
+
"version. Please, use the -e option " \
|
26
|
+
"instead."
|
27
|
+
elsif options[:environment]
|
28
|
+
self.options = options.merge(environment: acceptable_environment(options[:environment]))
|
29
|
+
else
|
17
30
|
self.options = options.merge(environment: Rails::Command.environment)
|
18
31
|
end
|
19
32
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/encrypted_file"
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
module Command
|
7
|
+
module Helpers
|
8
|
+
module Editor
|
9
|
+
private
|
10
|
+
def ensure_editor_available(command:)
|
11
|
+
if ENV["EDITOR"].to_s.empty?
|
12
|
+
say "No $EDITOR to open file in. Assign one like this:"
|
13
|
+
say ""
|
14
|
+
say %(EDITOR="mate --wait" #{command})
|
15
|
+
say ""
|
16
|
+
say "For editors that fork and exit immediately, it's important to pass a wait flag,"
|
17
|
+
say "otherwise the credentials will be saved immediately with no chance to edit."
|
18
|
+
|
19
|
+
false
|
20
|
+
else
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def catch_editing_exceptions
|
26
|
+
yield
|
27
|
+
rescue Interrupt
|
28
|
+
say "Aborted changing file: nothing saved."
|
29
|
+
rescue ActiveSupport::EncryptedFile::MissingKeyError => error
|
30
|
+
say error.message
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rails/commands.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "irb"
|
2
4
|
require "irb/completion"
|
3
5
|
|
@@ -70,9 +72,6 @@ module Rails
|
|
70
72
|
class_option :sandbox, aliases: "-s", type: :boolean, default: false,
|
71
73
|
desc: "Rollback database modifications on exit."
|
72
74
|
|
73
|
-
class_option :environment, aliases: "-e", type: :string,
|
74
|
-
desc: "Specifies the environment to run this console under (test/development/production)."
|
75
|
-
|
76
75
|
def initialize(args = [], local_options = {}, config = {})
|
77
76
|
console_options = []
|
78
77
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
=== Storing Encrypted Credentials in Source Control
|
2
|
+
|
3
|
+
The Rails `credentials` commands provide access to encrypted credentials,
|
4
|
+
so you can safely store access tokens, database passwords, and the like
|
5
|
+
safely inside the app without relying on a mess of ENVs.
|
6
|
+
|
7
|
+
This also allows for atomic deploys: no need to coordinate key changes
|
8
|
+
to get everything working as the keys are shipped with the code.
|
9
|
+
|
10
|
+
=== Setup
|
11
|
+
|
12
|
+
Applications after Rails 5.2 automatically have a basic credentials file generated
|
13
|
+
that just contains the secret_key_base used by MessageVerifiers/MessageEncryptors, like the ones
|
14
|
+
signing and encrypting cookies.
|
15
|
+
|
16
|
+
For applications created prior to Rails 5.2, we'll automatically generate a new
|
17
|
+
credentials file in `config/credentials.yml.enc` the first time you run `bin/rails credentials:edit`.
|
18
|
+
If you didn't have a master key saved in `config/master.key`, that'll be created too.
|
19
|
+
|
20
|
+
Don't lose this master key! Put it in a password manager your team can access.
|
21
|
+
Should you lose it no one, including you, will be able to access any encrypted
|
22
|
+
credentials.
|
23
|
+
|
24
|
+
Don't commit the key! Add `config/master.key` to your source control's
|
25
|
+
ignore file. If you use Git, Rails handles this for you.
|
26
|
+
|
27
|
+
Rails also looks for the master key in `ENV["RAILS_MASTER_KEY"]`, if that's easier to manage.
|
28
|
+
|
29
|
+
You could prepend that to your server's start command like this:
|
30
|
+
|
31
|
+
RAILS_MASTER_KEY="very-secret-and-secure" server.start
|
32
|
+
|
33
|
+
=== Editing Credentials
|
34
|
+
|
35
|
+
This will open a temporary file in `$EDITOR` with the decrypted contents to edit
|
36
|
+
the encrypted credentials.
|
37
|
+
|
38
|
+
When the temporary file is next saved the contents are encrypted and written to
|
39
|
+
`config/credentials.yml.enc` while the file itself is destroyed to prevent credentials
|
40
|
+
from leaking.
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require "rails/command/helpers/editor"
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
module Command
|
8
|
+
class CredentialsCommand < Rails::Command::Base # :nodoc:
|
9
|
+
include Helpers::Editor
|
10
|
+
|
11
|
+
no_commands do
|
12
|
+
def help
|
13
|
+
say "Usage:\n #{self.class.banner}"
|
14
|
+
say ""
|
15
|
+
say self.class.desc
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def edit
|
20
|
+
require_application_and_environment!
|
21
|
+
|
22
|
+
ensure_editor_available(command: "bin/rails credentials:edit") || (return)
|
23
|
+
ensure_master_key_has_been_added
|
24
|
+
ensure_credentials_have_been_added
|
25
|
+
|
26
|
+
catch_editing_exceptions do
|
27
|
+
change_credentials_in_system_editor
|
28
|
+
end
|
29
|
+
|
30
|
+
say "New credentials encrypted and saved."
|
31
|
+
end
|
32
|
+
|
33
|
+
def show
|
34
|
+
require_application_and_environment!
|
35
|
+
|
36
|
+
say Rails.application.credentials.read.presence ||
|
37
|
+
"No credentials have been added yet. Use bin/rails credentials:edit to change that."
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def ensure_master_key_has_been_added
|
42
|
+
master_key_generator.add_master_key_file
|
43
|
+
master_key_generator.ignore_master_key_file
|
44
|
+
end
|
45
|
+
|
46
|
+
def ensure_credentials_have_been_added
|
47
|
+
credentials_generator.add_credentials_file_silently
|
48
|
+
end
|
49
|
+
|
50
|
+
def change_credentials_in_system_editor
|
51
|
+
Rails.application.credentials.change do |tmp_path|
|
52
|
+
system("#{ENV["EDITOR"]} #{tmp_path}")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def master_key_generator
|
58
|
+
require "rails/generators"
|
59
|
+
require "rails/generators/rails/master_key/master_key_generator"
|
60
|
+
|
61
|
+
Rails::Generators::MasterKeyGenerator.new
|
62
|
+
end
|
63
|
+
|
64
|
+
def credentials_generator
|
65
|
+
require "rails/generators"
|
66
|
+
require "rails/generators/rails/credentials/credentials_generator"
|
67
|
+
|
68
|
+
Rails::Generators::CredentialsGenerator.new
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rails/command/environment_argument"
|
2
4
|
|
3
5
|
module Rails
|
@@ -58,7 +60,7 @@ module Rails
|
|
58
60
|
logon = ""
|
59
61
|
|
60
62
|
if config["username"]
|
61
|
-
logon = config["username"]
|
63
|
+
logon = config["username"].dup
|
62
64
|
logon << "/#{config['password']}" if config["password"] && @options["include_password"]
|
63
65
|
logon << "@#{config['database']}" if config["database"]
|
64
66
|
end
|
@@ -73,7 +75,7 @@ module Rails
|
|
73
75
|
args += ["-P", "#{config['password']}"] if config["password"]
|
74
76
|
|
75
77
|
if config["host"]
|
76
|
-
host_arg = "#{config['host']}"
|
78
|
+
host_arg = "#{config['host']}".dup
|
77
79
|
host_arg << ":#{config['port']}" if config["port"]
|
78
80
|
args += ["-S", host_arg]
|
79
81
|
end
|
@@ -87,10 +89,15 @@ module Rails
|
|
87
89
|
|
88
90
|
def config
|
89
91
|
@config ||= begin
|
90
|
-
|
92
|
+
# We need to check whether the user passed the connection the
|
93
|
+
# first time around to show a consistent error message to people
|
94
|
+
# relying on 2-level database configuration.
|
95
|
+
if @options["connection"] && configurations[connection].blank?
|
96
|
+
raise ActiveRecord::AdapterNotSpecified, "'#{connection}' connection is not configured. Available configuration: #{configurations.inspect}"
|
97
|
+
elsif configurations[environment].blank? && configurations[connection].blank?
|
91
98
|
raise ActiveRecord::AdapterNotSpecified, "'#{environment}' database is not configured. Available configuration: #{configurations.inspect}"
|
92
99
|
else
|
93
|
-
configurations[environment]
|
100
|
+
configurations[environment].presence || configurations[connection]
|
94
101
|
end
|
95
102
|
end
|
96
103
|
end
|
@@ -99,6 +106,10 @@ module Rails
|
|
99
106
|
Rails.respond_to?(:env) ? Rails.env : Rails::Command.environment
|
100
107
|
end
|
101
108
|
|
109
|
+
def connection
|
110
|
+
@options.fetch(:connection, "primary")
|
111
|
+
end
|
112
|
+
|
102
113
|
private
|
103
114
|
def configurations # :doc:
|
104
115
|
require APP_PATH
|
@@ -140,10 +151,10 @@ module Rails
|
|
140
151
|
class_option :mode, enum: %w( html list line column ), type: :string,
|
141
152
|
desc: "Automatically put the sqlite3 database in the specified mode (html, list, line, column)."
|
142
153
|
|
143
|
-
class_option :header, type: :
|
154
|
+
class_option :header, type: :boolean
|
144
155
|
|
145
|
-
class_option :
|
146
|
-
desc: "Specifies the
|
156
|
+
class_option :connection, aliases: "-c", type: :string,
|
157
|
+
desc: "Specifies the connection to use."
|
147
158
|
|
148
159
|
def perform
|
149
160
|
extract_environment_option_from_argument
|