railties 7.0.4 → 7.1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +729 -174
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.md +99 -0
- data/README.rdoc +5 -5
- data/lib/minitest/rails_plugin.rb +63 -0
- data/lib/rails/api/task.rb +35 -4
- data/lib/rails/app_updater.rb +1 -1
- data/lib/rails/application/bootstrap.rb +23 -4
- data/lib/rails/application/configuration.rb +190 -70
- 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 +43 -33
- data/lib/rails/application.rb +159 -59
- data/lib/rails/application_controller.rb +1 -1
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/lib/rails/cli.rb +5 -2
- 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/application/application_command.rb +2 -0
- data/lib/rails/commands/console/console_command.rb +17 -13
- 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 +25 -115
- 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 +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 +32 -20
- data/lib/rails/commands/secret/secret_command.rb +13 -0
- data/lib/rails/commands/secrets/USAGE +44 -49
- data/lib/rails/commands/secrets/secrets_command.rb +20 -38
- data/lib/rails/commands/server/server_command.rb +33 -32
- data/lib/rails/commands/test/USAGE +14 -0
- data/lib/rails/commands/test/test_command.rb +56 -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 +5 -5
- data/lib/rails/console/app.rb +1 -4
- data/lib/rails/deprecator.rb +7 -0
- data/lib/rails/engine/configuration.rb +50 -6
- data/lib/rails/engine.rb +49 -21
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions.rb +178 -59
- data/lib/rails/generators/active_model.rb +28 -14
- data/lib/rails/generators/app_base.rb +355 -82
- data/lib/rails/generators/app_name.rb +3 -14
- data/lib/rails/generators/base.rb +17 -9
- data/lib/rails/generators/database.rb +39 -1
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +1 -1
- data/lib/rails/generators/generated_attribute.rb +12 -0
- data/lib/rails/generators/migration.rb +1 -2
- 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 +83 -62
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +103 -0
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +10 -10
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +6 -17
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +4 -6
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +59 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +11 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +31 -27
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +2 -0
- 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 +3 -3
- 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 +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 +11 -19
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +5 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +6 -4
- 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/gitignore.tt +4 -8
- 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 +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 +5 -0
- 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 +30 -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/model/model_generator.rb +4 -0
- data/lib/rails/generators/rails/plugin/USAGE +17 -6
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +4 -13
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -15
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -2
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +4 -4
- 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/rails/scaffold_controller/templates/controller.rb.tt +2 -2
- data/lib/rails/generators/test_case.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +1 -1
- data/lib/rails/generators/testing/{behaviour.rb → behavior.rb} +5 -2
- data/lib/rails/generators.rb +6 -14
- data/lib/rails/health_controller.rb +55 -0
- data/lib/rails/info.rb +1 -1
- data/lib/rails/info_controller.rb +31 -11
- data/lib/rails/mailers_controller.rb +15 -5
- data/lib/rails/paths.rb +13 -10
- data/lib/rails/rack/logger.rb +15 -12
- data/lib/rails/rackup/server.rb +15 -0
- data/lib/rails/railtie/configuration.rb +14 -1
- data/lib/rails/railtie.rb +18 -18
- data/lib/rails/ruby_version_check.rb +2 -0
- data/lib/rails/secrets.rb +10 -8
- data/lib/rails/source_annotation_extractor.rb +67 -18
- data/lib/rails/tasks/engine.rake +8 -8
- data/lib/rails/tasks/framework.rake +4 -10
- 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 +5 -5
- data/lib/rails/tasks/zeitwerk.rake +15 -35
- data/lib/rails/tasks.rb +0 -2
- data/lib/rails/templates/rails/mailers/email.html.erb +32 -0
- 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 +1 -0
- data/lib/rails/test_help.rb +13 -14
- data/lib/rails/test_unit/line_filtering.rb +1 -1
- data/lib/rails/test_unit/reporter.rb +6 -2
- data/lib/rails/test_unit/runner.rb +36 -18
- data/lib/rails/test_unit/test_parser.rb +88 -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 +15 -15
- metadata +66 -29
- data/RDOC_MAIN.rdoc +0 -97
- data/lib/rails/application/dummy_erb_compiler.rb +0 -18
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +0 -135
- data/lib/rails/generators/rails/model/USAGE +0 -113
- data/lib/rails/tasks/middleware.rake +0 -9
- data/lib/rails/tasks/restart.rake +0 -9
@@ -3,12 +3,12 @@
|
|
3
3
|
require "fileutils"
|
4
4
|
require "action_dispatch"
|
5
5
|
require "rails"
|
6
|
-
require "active_support/core_ext/string/filters"
|
7
6
|
require "rails/dev_caching"
|
8
7
|
require "rails/command/environment_argument"
|
8
|
+
require "rails/rackup/server"
|
9
9
|
|
10
10
|
module Rails
|
11
|
-
class Server < ::
|
11
|
+
class Server < Rackup::Server
|
12
12
|
class Options
|
13
13
|
def parse!(args)
|
14
14
|
Rails::Command::ServerCommand.new([], args).server_options
|
@@ -79,13 +79,13 @@ module Rails
|
|
79
79
|
console.formatter = Rails.logger.formatter
|
80
80
|
console.level = Rails.logger.level
|
81
81
|
|
82
|
-
unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDOUT)
|
83
|
-
Rails.logger.
|
82
|
+
unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDERR, STDOUT)
|
83
|
+
Rails.logger.broadcast_to(console)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
def use_puma?
|
88
|
-
server.to_s
|
88
|
+
server.to_s.end_with?("Handler::Puma")
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -93,30 +93,32 @@ module Rails
|
|
93
93
|
class ServerCommand < Base # :nodoc:
|
94
94
|
include EnvironmentArgument
|
95
95
|
|
96
|
+
RACK_HANDLER_GEMS = %w(cgi webrick scgi thin puma unicorn falcon)
|
96
97
|
# Hard-coding a bunch of handlers here as we don't have a public way of
|
97
|
-
# querying them from the
|
98
|
-
|
98
|
+
# querying them from the Rackup::Handler registry.
|
99
|
+
RACK_HANDLERS = RACK_HANDLER_GEMS + %w(fastcgi lsws)
|
100
|
+
RECOMMENDED_SERVER = "puma"
|
99
101
|
|
100
102
|
DEFAULT_PORT = 3000
|
101
103
|
DEFAULT_PIDFILE = "tmp/pids/server.pid"
|
102
104
|
|
103
105
|
class_option :port, aliases: "-p", type: :numeric,
|
104
|
-
desc: "
|
106
|
+
desc: "Run Rails on the specified port - defaults to 3000.", banner: :port
|
105
107
|
class_option :binding, aliases: "-b", type: :string,
|
106
|
-
desc: "
|
108
|
+
desc: "Bind Rails to the specified IP - defaults to 'localhost' in development and '0.0.0.0' in other environments'.",
|
107
109
|
banner: :IP
|
108
110
|
class_option :config, aliases: "-c", type: :string, default: "config.ru",
|
109
|
-
desc: "
|
111
|
+
desc: "Use a custom rackup configuration.", banner: :file
|
110
112
|
class_option :daemon, aliases: "-d", type: :boolean, default: false,
|
111
|
-
desc: "
|
113
|
+
desc: "Run server as a Daemon."
|
112
114
|
class_option :using, aliases: "-u", type: :string,
|
113
|
-
desc: "
|
115
|
+
desc: "Specify the Rack server used to run the application (thin/puma/webrick).", banner: :name
|
114
116
|
class_option :pid, aliases: "-P", type: :string,
|
115
|
-
desc: "
|
117
|
+
desc: "Specify the PID file - defaults to #{DEFAULT_PIDFILE}."
|
116
118
|
class_option :dev_caching, aliases: "-C", type: :boolean, default: nil,
|
117
|
-
desc: "
|
119
|
+
desc: "Specify whether to perform caching in development."
|
118
120
|
class_option :restart, type: :boolean, default: nil, hide: true
|
119
|
-
class_option :early_hints, type: :boolean, default: nil, desc: "
|
121
|
+
class_option :early_hints, type: :boolean, default: nil, desc: "Enable HTTP/2 early hints."
|
120
122
|
class_option :log_to_stdout, type: :boolean, default: nil, optional: true,
|
121
123
|
desc: "Whether to log to stdout. Enabled by default in development when not daemonized."
|
122
124
|
|
@@ -126,8 +128,8 @@ module Rails
|
|
126
128
|
@original_options = local_options - %w( --restart )
|
127
129
|
end
|
128
130
|
|
131
|
+
desc "server", "Start the Rails server"
|
129
132
|
def perform
|
130
|
-
extract_environment_option_from_argument
|
131
133
|
set_application_directory!
|
132
134
|
prepare_restart
|
133
135
|
|
@@ -227,7 +229,7 @@ module Rails
|
|
227
229
|
end
|
228
230
|
|
229
231
|
def restart_command
|
230
|
-
"
|
232
|
+
"#{executable} #{@original_options.join(" ")} --restart"
|
231
233
|
end
|
232
234
|
|
233
235
|
def early_hints
|
@@ -244,33 +246,32 @@ module Rails
|
|
244
246
|
File.expand_path(options[:pid] || ENV.fetch("PIDFILE", DEFAULT_PIDFILE))
|
245
247
|
end
|
246
248
|
|
247
|
-
def self.banner(*)
|
248
|
-
"rails server -u [thin/puma/webrick] [options]"
|
249
|
-
end
|
250
|
-
|
251
249
|
def prepare_restart
|
252
250
|
FileUtils.rm_f(pid) if options[:restart]
|
253
251
|
end
|
254
252
|
|
255
253
|
def rack_server_suggestion(server)
|
256
|
-
if server.
|
254
|
+
if server.nil?
|
255
|
+
<<~MSG
|
256
|
+
Could not find a server gem. Maybe you need to add one to the Gemfile?
|
257
|
+
|
258
|
+
gem "#{RECOMMENDED_SERVER}"
|
259
|
+
|
260
|
+
Run `#{executable} --help` for more options.
|
261
|
+
MSG
|
262
|
+
elsif server.in?(RACK_HANDLER_GEMS)
|
257
263
|
<<~MSG
|
258
264
|
Could not load server "#{server}". Maybe you need to the add it to the Gemfile?
|
259
265
|
|
260
266
|
gem "#{server}"
|
261
267
|
|
262
|
-
Run
|
268
|
+
Run `#{executable} --help` for more options.
|
263
269
|
MSG
|
264
270
|
else
|
265
|
-
error =
|
266
|
-
if error.respond_to?(:detailed_message)
|
267
|
-
formatted_message = error.detailed_message
|
268
|
-
else
|
269
|
-
formatted_message = error.message
|
270
|
-
end
|
271
|
+
error = CorrectableNameError.new("Could not find server '#{server}'.", server, RACK_HANDLERS)
|
271
272
|
<<~MSG
|
272
|
-
#{
|
273
|
-
Run
|
273
|
+
#{error.detailed_message}
|
274
|
+
Run `#{executable} --help` for more options.
|
274
275
|
MSG
|
275
276
|
end
|
276
277
|
end
|
@@ -279,7 +280,7 @@ module Rails
|
|
279
280
|
say <<~MSG
|
280
281
|
=> Booting #{ActiveSupport::Inflector.demodulize(server)}
|
281
282
|
=> Rails #{Rails.version} application starting in #{Rails.env} #{url}
|
282
|
-
=> Run
|
283
|
+
=> Run `#{executable} --help` for more startup options
|
283
284
|
MSG
|
284
285
|
end
|
285
286
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Examples:
|
2
|
+
You can run a single test by appending a line number to a filename:
|
3
|
+
|
4
|
+
<%= executable %> test/models/user_test.rb:27
|
5
|
+
|
6
|
+
You can run multiple tests with in a line range by appending the line range to a filename:
|
7
|
+
|
8
|
+
<%= executable %> test/models/user_test.rb:10-20
|
9
|
+
|
10
|
+
You can run multiple files and directories at the same time:
|
11
|
+
|
12
|
+
<%= executable %> test/controllers test/integration/login_test.rb
|
13
|
+
|
14
|
+
By default test failures and errors are reported inline during a run.
|
@@ -1,37 +1,79 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rails/command"
|
4
|
+
require "rails/commands/rake/rake_command"
|
4
5
|
require "rails/test_unit/runner"
|
5
6
|
require "rails/test_unit/reporter"
|
6
7
|
|
7
8
|
module Rails
|
8
9
|
module Command
|
9
10
|
class TestCommand < Base # :nodoc:
|
11
|
+
def self.executable(*args)
|
12
|
+
args.empty? ? Rails::TestUnitReporter.executable : super
|
13
|
+
end
|
14
|
+
|
10
15
|
no_commands do
|
11
|
-
def help
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
say ""
|
18
|
-
say "You can run multiple files and directories at the same time:"
|
19
|
-
say ""
|
20
|
-
say " #{Rails::TestUnitReporter.executable} test/controllers test/integration/login_test.rb"
|
16
|
+
def help(command_name = nil, *)
|
17
|
+
super
|
18
|
+
if command_name == "test"
|
19
|
+
say ""
|
20
|
+
say self.class.class_usage
|
21
|
+
end
|
21
22
|
say ""
|
22
|
-
say "By default test failures and errors are reported inline during a run."
|
23
|
-
say ""
|
24
|
-
|
25
23
|
Minitest.run(%w(--help))
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
|
27
|
+
desc "test [PATHS...]", "Run tests except system tests"
|
28
|
+
def perform(*args)
|
30
29
|
$LOAD_PATH << Rails::Command.root.join("test").to_s
|
31
30
|
|
32
31
|
Rails::TestUnit::Runner.parse_options(args)
|
32
|
+
run_prepare_task if self.args.none?(EXACT_TEST_ARGUMENT_PATTERN)
|
33
33
|
Rails::TestUnit::Runner.run(args)
|
34
34
|
end
|
35
|
+
|
36
|
+
# Define Thor tasks to avoid going through Rake and booting twice when using bin/rails test:*
|
37
|
+
Rails::TestUnit::Runner::TEST_FOLDERS.each do |name|
|
38
|
+
desc name, "Run tests in test/#{name}"
|
39
|
+
define_method(name) do |*args|
|
40
|
+
perform("test/#{name}", *args)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "all", "Run all tests, including system tests"
|
45
|
+
def all(*args)
|
46
|
+
perform("test/**/*_test.rb", *args)
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "functionals", "Run tests in test/controllers, test/mailers, and test/functional"
|
50
|
+
def functionals(*args)
|
51
|
+
perform("test/controllers", "test/mailers", "test/functional", *args)
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "units", "Run tests in test/models, test/helpers, and test/unit"
|
55
|
+
def units(*args)
|
56
|
+
perform("test/models", "test/helpers", "test/unit", *args)
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "system", "Run system tests only"
|
60
|
+
def system(*args)
|
61
|
+
perform("test/system", *args)
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "generators", "Run tests in test/lib/generators"
|
65
|
+
def generators(*args)
|
66
|
+
perform("test/lib/generators", *args)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
EXACT_TEST_ARGUMENT_PATTERN = /^-n|^--name\b|#{Rails::TestUnit::Runner::PATH_ARGUMENT_PATTERN}/
|
71
|
+
|
72
|
+
def run_prepare_task
|
73
|
+
Rails::Command::RakeCommand.perform("test:prepare", [], {})
|
74
|
+
rescue UnrecognizedCommandError => error
|
75
|
+
raise unless error.name == "test:prepare"
|
76
|
+
end
|
35
77
|
end
|
36
78
|
end
|
37
79
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/commands/routes/routes_command"
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
module Command
|
7
|
+
class UnusedRoutesCommand < Rails::Command::Base # :nodoc:
|
8
|
+
hide_command!
|
9
|
+
class_option :controller, aliases: "-c", desc: "Filter by a specific controller, e.g. PostsController or Admin::PostsController."
|
10
|
+
class_option :grep, aliases: "-g", desc: "Grep routes by a specific pattern."
|
11
|
+
|
12
|
+
class RouteInfo
|
13
|
+
def initialize(route)
|
14
|
+
requirements = route.requirements
|
15
|
+
@controller_name = requirements[:controller]
|
16
|
+
@action_name = requirements[:action]
|
17
|
+
@controller_class = (@controller_name.to_s.camelize + "Controller").safe_constantize
|
18
|
+
end
|
19
|
+
|
20
|
+
def unused?
|
21
|
+
controller_class_missing? || (action_missing? && template_missing?)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def view_path(root)
|
26
|
+
File.join(root.path, @controller_name, @action_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def controller_class_missing?
|
30
|
+
@controller_name && @controller_class.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
def template_missing?
|
34
|
+
@controller_class && @controller_class.try(:view_paths).to_a.flat_map { |path| Dir["#{view_path(path)}.*"] }.none?
|
35
|
+
end
|
36
|
+
|
37
|
+
def action_missing?
|
38
|
+
@controller_class && @controller_class.instance_methods.exclude?(@action_name.to_sym)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def perform(*)
|
43
|
+
boot_application!
|
44
|
+
require "action_dispatch/routing/inspector"
|
45
|
+
|
46
|
+
say(inspector.format(formatter, routes_filter))
|
47
|
+
|
48
|
+
exit(1) if routes.any?
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def inspector
|
53
|
+
ActionDispatch::Routing::RoutesInspector.new(routes)
|
54
|
+
end
|
55
|
+
|
56
|
+
def routes
|
57
|
+
@routes ||= begin
|
58
|
+
routes = Rails.application.routes.routes.select do |route|
|
59
|
+
RouteInfo.new(route).unused?
|
60
|
+
end
|
61
|
+
|
62
|
+
ActionDispatch::Journey::Routes.new(routes)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def formatter
|
67
|
+
ActionDispatch::Routing::ConsoleFormatter::Unused.new
|
68
|
+
end
|
69
|
+
|
70
|
+
def routes_filter
|
71
|
+
options.symbolize_keys.slice(:controller, :grep)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/rails/configuration.rb
CHANGED
@@ -7,17 +7,17 @@ require "rails/rack"
|
|
7
7
|
|
8
8
|
module Rails
|
9
9
|
module Configuration
|
10
|
-
# MiddlewareStackProxy is a proxy for the Rails middleware stack that allows
|
10
|
+
# MiddlewareStackProxy is a proxy for the \Rails middleware stack that allows
|
11
11
|
# you to configure middlewares in your application. It works basically as a
|
12
12
|
# command recorder, saving each command to be applied after initialization
|
13
13
|
# over the default middleware stack, so you can add, swap, or remove any
|
14
|
-
# middleware in Rails.
|
14
|
+
# middleware in \Rails.
|
15
15
|
#
|
16
16
|
# You can add your own middlewares by using the +config.middleware.use+ method:
|
17
17
|
#
|
18
18
|
# config.middleware.use Magical::Unicorns
|
19
19
|
#
|
20
|
-
# This will put the
|
20
|
+
# This will put the +Magical::Unicorns+ middleware on the end of the stack.
|
21
21
|
# You can use +insert_before+ if you wish to add a middleware before another:
|
22
22
|
#
|
23
23
|
# config.middleware.insert_before Rack::Head, Magical::Unicorns
|
@@ -34,8 +34,8 @@ module Rails
|
|
34
34
|
#
|
35
35
|
# config.middleware.move_before ActionDispatch::Flash, Magical::Unicorns
|
36
36
|
#
|
37
|
-
# This will move the
|
38
|
-
#
|
37
|
+
# This will move the +Magical::Unicorns+ middleware before the
|
38
|
+
# +ActionDispatch::Flash+. You can also move it after:
|
39
39
|
#
|
40
40
|
# config.middleware.move_after ActionDispatch::Flash, Magical::Unicorns
|
41
41
|
#
|
data/lib/rails/console/app.rb
CHANGED
@@ -9,9 +9,7 @@ module Rails
|
|
9
9
|
# instance, pass a non-false value as the parameter.
|
10
10
|
def app(create = false)
|
11
11
|
@app_integration_instance = nil if create
|
12
|
-
@app_integration_instance ||= new_session
|
13
|
-
sess.host! "www.example.com"
|
14
|
-
end
|
12
|
+
@app_integration_instance ||= new_session
|
15
13
|
end
|
16
14
|
|
17
15
|
# create a new session. If a block is given, the new session will be yielded
|
@@ -19,7 +17,6 @@ module Rails
|
|
19
17
|
def new_session
|
20
18
|
app = Rails.application
|
21
19
|
session = ActionDispatch::Integration::Session.new(app)
|
22
|
-
yield session if block_given?
|
23
20
|
|
24
21
|
# This makes app.url_for and app.foo_path available in the console
|
25
22
|
session.extend(app.routes.url_helpers)
|
@@ -9,12 +9,45 @@ module Rails
|
|
9
9
|
attr_accessor :middleware, :javascript_path
|
10
10
|
attr_writer :eager_load_paths, :autoload_once_paths, :autoload_paths
|
11
11
|
|
12
|
+
# An array of custom autoload paths to be added to the ones defined
|
13
|
+
# automatically by Rails. These won't be eager loaded, unless you push
|
14
|
+
# them to +eager_load_paths+ too, which is recommended.
|
15
|
+
#
|
16
|
+
# This collection is empty by default, it accepts strings and +Pathname+
|
17
|
+
# objects.
|
18
|
+
#
|
19
|
+
# If you'd like to add +lib+ to it, please see +autoload_lib+.
|
20
|
+
attr_reader :autoload_paths
|
21
|
+
|
22
|
+
# An array of custom autoload once paths. These won't be eager loaded
|
23
|
+
# unless you push them to +eager_load_paths+ too, which is recommended.
|
24
|
+
#
|
25
|
+
# This collection is empty by default, it accepts strings and +Pathname+
|
26
|
+
# objects.
|
27
|
+
#
|
28
|
+
# If you'd like to add +lib+ to it, please see +autoload_lib_once+.
|
29
|
+
attr_reader :autoload_once_paths
|
30
|
+
|
31
|
+
# An array of custom eager load paths to be added to the ones defined
|
32
|
+
# automatically by Rails. Anything in this collection is considered to be
|
33
|
+
# an autoload path regardless of whether it was added to +autoload_paths+.
|
34
|
+
#
|
35
|
+
# This collection is empty by default, it accepts strings and +Pathname+
|
36
|
+
# objects.
|
37
|
+
#
|
38
|
+
# If you'd like to add +lib+ to it, please see +autoload_lib+.
|
39
|
+
attr_reader :eager_load_paths
|
40
|
+
|
12
41
|
def initialize(root = nil)
|
13
42
|
super()
|
14
43
|
@root = root
|
15
44
|
@generators = app_generators.dup
|
16
45
|
@middleware = Rails::Configuration::MiddlewareStackProxy.new
|
17
46
|
@javascript_path = "javascript"
|
47
|
+
|
48
|
+
@autoload_paths = []
|
49
|
+
@autoload_once_paths = []
|
50
|
+
@eager_load_paths = []
|
18
51
|
end
|
19
52
|
|
20
53
|
# Holds generators configuration:
|
@@ -50,6 +83,9 @@ module Rails
|
|
50
83
|
paths.add "app/mailers", eager_load: true
|
51
84
|
paths.add "app/views"
|
52
85
|
|
86
|
+
# If you add more lib subdirectories here that should not be managed
|
87
|
+
# by the main autoloader, please update the config.autoload_lib call
|
88
|
+
# in the template that generates config/application.rb accordingly.
|
53
89
|
paths.add "lib", load_path: true
|
54
90
|
paths.add "lib/assets", glob: "*"
|
55
91
|
paths.add "lib/tasks", glob: "**/*.rake"
|
@@ -68,6 +104,8 @@ module Rails
|
|
68
104
|
paths.add "vendor", load_path: true
|
69
105
|
paths.add "vendor/assets", glob: "*"
|
70
106
|
|
107
|
+
paths.add "test/mailers/previews", autoload: true
|
108
|
+
|
71
109
|
paths
|
72
110
|
end
|
73
111
|
end
|
@@ -76,16 +114,22 @@ module Rails
|
|
76
114
|
@root = paths.path = Pathname.new(value).expand_path
|
77
115
|
end
|
78
116
|
|
79
|
-
|
80
|
-
|
117
|
+
# Private method that adds custom autoload paths to the ones defined by
|
118
|
+
# +paths+.
|
119
|
+
def all_autoload_paths # :nodoc:
|
120
|
+
autoload_paths + paths.autoload_paths
|
81
121
|
end
|
82
122
|
|
83
|
-
|
84
|
-
|
123
|
+
# Private method that adds custom autoload once paths to the ones defined
|
124
|
+
# by +paths+.
|
125
|
+
def all_autoload_once_paths # :nodoc:
|
126
|
+
autoload_once_paths + paths.autoload_once
|
85
127
|
end
|
86
128
|
|
87
|
-
|
88
|
-
|
129
|
+
# Private method that adds custom eager load paths to the ones defined by
|
130
|
+
# +paths+.
|
131
|
+
def all_eager_load_paths # :nodoc:
|
132
|
+
eager_load_paths + paths.eager_load
|
89
133
|
end
|
90
134
|
end
|
91
135
|
end
|