railties 5.2.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +293 -89
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +39 -33
- data/README.rdoc +3 -3
- data/lib/minitest/rails_plugin.rb +24 -13
- data/lib/rails/all.rb +4 -0
- data/lib/rails/api/generator.rb +2 -1
- data/lib/rails/api/task.rb +17 -0
- data/lib/rails/app_loader.rb +2 -2
- data/lib/rails/app_updater.rb +4 -1
- data/lib/rails/application/bootstrap.rb +9 -17
- data/lib/rails/application/configuration.rb +177 -27
- data/lib/rails/application/default_middleware_stack.rb +7 -3
- data/lib/rails/application/dummy_erb_compiler.rb +18 -0
- data/lib/rails/application/finisher.rb +69 -2
- data/lib/rails/application/routes_reloader.rb +9 -19
- data/lib/rails/application.rb +96 -66
- data/lib/rails/application_controller.rb +0 -1
- data/lib/rails/autoloaders.rb +48 -0
- data/lib/rails/backtrace_cleaner.rb +14 -21
- data/lib/rails/code_statistics.rb +8 -6
- data/lib/rails/code_statistics_calculator.rb +6 -6
- data/lib/rails/command/actions.rb +10 -0
- data/lib/rails/command/base.rb +17 -5
- data/lib/rails/command/behavior.rb +8 -49
- data/lib/rails/command/environment_argument.rb +9 -16
- data/lib/rails/command/spellchecker.rb +57 -0
- data/lib/rails/command.rb +18 -11
- data/lib/rails/commands/console/console_command.rb +6 -0
- data/lib/rails/commands/credentials/USAGE +33 -0
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/credentials/credentials_command.rb +78 -21
- data/lib/rails/commands/db/system/change/change_command.rb +25 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +66 -51
- data/lib/rails/commands/dev/dev_command.rb +19 -0
- data/lib/rails/commands/encrypted/USAGE +28 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +5 -4
- data/lib/rails/commands/generate/generate_command.rb +1 -1
- data/lib/rails/commands/help/help_command.rb +1 -1
- data/lib/rails/commands/initializers/initializers_command.rb +23 -0
- data/lib/rails/commands/new/new_command.rb +2 -2
- data/lib/rails/commands/notes/notes_command.rb +29 -0
- data/lib/rails/commands/plugin/plugin_command.rb +1 -1
- data/lib/rails/commands/rake/rake_command.rb +9 -8
- data/lib/rails/commands/routes/routes_command.rb +37 -0
- data/lib/rails/commands/runner/runner_command.rb +13 -9
- data/lib/rails/commands/secrets/USAGE +6 -0
- data/lib/rails/commands/secrets/secrets_command.rb +3 -3
- data/lib/rails/commands/server/server_command.rb +92 -56
- data/lib/rails/commands/test/test_command.rb +2 -2
- data/lib/rails/configuration.rb +48 -19
- data/lib/rails/engine/configuration.rb +6 -2
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +63 -35
- data/lib/rails/gem_version.rb +2 -2
- data/lib/rails/generators/actions/create_migration.rb +5 -1
- data/lib/rails/generators/actions.rb +89 -56
- data/lib/rails/generators/app_base.rb +80 -108
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/base.rb +19 -12
- data/lib/rails/generators/database.rb +57 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -2
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -1
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +7 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +9 -1
- data/lib/rails/generators/erb.rb +0 -1
- data/lib/rails/generators/generated_attribute.rb +50 -31
- data/lib/rails/generators/migration.rb +3 -3
- data/lib/rails/generators/model_helpers.rb +33 -2
- data/lib/rails/generators/named_base.rb +3 -7
- data/lib/rails/generators/rails/app/USAGE +2 -1
- data/lib/rails/generators/rails/app/app_generator.rb +127 -84
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +18 -21
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +6 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +23 -0
- data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +6 -5
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -9
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +9 -0
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +11 -3
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +16 -7
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +4 -5
- 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 +13 -12
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +13 -12
- 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 +16 -15
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +11 -10
- 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 +22 -5
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +43 -17
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +26 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +7 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +63 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +13 -4
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
- data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +10 -7
- data/lib/rails/generators/rails/app/templates/package.json.tt +8 -2
- data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -1
- data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +9 -2
- data/lib/rails/generators/rails/assets/USAGE +3 -7
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -1
- data/lib/rails/generators/rails/benchmark/USAGE +19 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
- data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
- data/lib/rails/generators/rails/controller/USAGE +2 -2
- data/lib/rails/generators/rails/controller/controller_generator.rb +10 -39
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +6 -7
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +65 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +10 -7
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -0
- 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/USAGE.tt +1 -1
- data/lib/rails/generators/rails/helper/USAGE +2 -3
- data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
- data/lib/rails/generators/rails/integration_test/USAGE +2 -2
- data/lib/rails/generators/rails/migration/USAGE +4 -4
- data/lib/rails/generators/rails/model/USAGE +15 -16
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +32 -56
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +18 -18
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -2
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +14 -11
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.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 +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
- data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -4
- data/lib/rails/generators/rails/resource/USAGE +4 -4
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
- data/lib/rails/generators/rails/scaffold/USAGE +5 -5
- data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +19 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +2 -2
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +2 -2
- 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 +1 -6
- data/lib/rails/generators/test_case.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +0 -1
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +5 -0
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +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 +12 -3
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +10 -2
- data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
- data/lib/rails/generators/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/behaviour.rb +4 -2
- data/lib/rails/generators.rb +38 -24
- data/lib/rails/info.rb +4 -4
- data/lib/rails/info_controller.rb +2 -3
- data/lib/rails/mailers_controller.rb +10 -4
- data/lib/rails/paths.rb +26 -10
- data/lib/rails/rack/logger.rb +5 -6
- data/lib/rails/railtie/configurable.rb +0 -1
- data/lib/rails/railtie/configuration.rb +3 -3
- data/lib/rails/railtie.rb +33 -13
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +0 -1
- data/lib/rails/source_annotation_extractor.rb +124 -117
- data/lib/rails/tasks/engine.rake +1 -4
- data/lib/rails/tasks/framework.rake +13 -3
- data/lib/rails/tasks/log.rake +0 -1
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/statistics.rake +5 -1
- data/lib/rails/tasks/yarn.rake +14 -1
- data/lib/rails/tasks/zeitwerk.rake +69 -0
- data/lib/rails/tasks.rb +1 -4
- data/lib/rails/templates/rails/mailers/email.html.erb +11 -7
- data/lib/rails/templates/rails/welcome/index.html.erb +3 -3
- data/lib/rails/test_help.rb +11 -9
- data/lib/rails/test_unit/reporter.rb +3 -2
- data/lib/rails/test_unit/runner.rb +25 -8
- data/lib/rails/test_unit/testing.rake +7 -1
- data/lib/rails.rb +10 -8
- metadata +45 -39
- data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js.tt +0 -13
- data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
- data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -34
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -35
- data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
- data/lib/rails/tasks/annotations.rake +0 -22
- data/lib/rails/tasks/dev.rake +0 -10
- data/lib/rails/tasks/initializers.rake +0 -8
- data/lib/rails/tasks/routes.rake +0 -31
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support/core_ext/string/filters"
|
4
|
+
require "active_support/deprecation"
|
3
5
|
require "rails/command/environment_argument"
|
4
6
|
|
5
7
|
module Rails
|
@@ -14,55 +16,56 @@ module Rails
|
|
14
16
|
|
15
17
|
def start
|
16
18
|
ENV["RAILS_ENV"] ||= @options[:environment] || environment
|
19
|
+
config = db_config.configuration_hash
|
17
20
|
|
18
|
-
case
|
21
|
+
case db_config.adapter
|
19
22
|
when /^(jdbc)?mysql/
|
20
23
|
args = {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
host: "--host",
|
25
|
+
port: "--port",
|
26
|
+
socket: "--socket",
|
27
|
+
username: "--user",
|
28
|
+
encoding: "--default-character-set",
|
29
|
+
sslca: "--ssl-ca",
|
30
|
+
sslcert: "--ssl-cert",
|
31
|
+
sslcapath: "--ssl-capath",
|
32
|
+
sslcipher: "--ssl-cipher",
|
33
|
+
sslkey: "--ssl-key"
|
31
34
|
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
|
32
35
|
|
33
|
-
if config[
|
34
|
-
args << "--password=#{config[
|
35
|
-
elsif config[
|
36
|
+
if config[:password] && @options[:include_password]
|
37
|
+
args << "--password=#{config[:password]}"
|
38
|
+
elsif config[:password] && !config[:password].to_s.empty?
|
36
39
|
args << "-p"
|
37
40
|
end
|
38
41
|
|
39
|
-
args <<
|
42
|
+
args << db_config.database
|
40
43
|
|
41
44
|
find_cmd_and_exec(["mysql", "mysql5"], *args)
|
42
45
|
|
43
46
|
when /^postgres|^postgis/
|
44
|
-
ENV["PGUSER"] = config[
|
45
|
-
ENV["PGHOST"] = config[
|
46
|
-
ENV["PGPORT"] = config[
|
47
|
-
ENV["PGPASSWORD"] = config[
|
48
|
-
find_cmd_and_exec("psql",
|
47
|
+
ENV["PGUSER"] = config[:username] if config[:username]
|
48
|
+
ENV["PGHOST"] = config[:host] if config[:host]
|
49
|
+
ENV["PGPORT"] = config[:port].to_s if config[:port]
|
50
|
+
ENV["PGPASSWORD"] = config[:password].to_s if config[:password] && @options[:include_password]
|
51
|
+
find_cmd_and_exec("psql", db_config.database)
|
49
52
|
|
50
53
|
when "sqlite3"
|
51
54
|
args = []
|
52
55
|
|
53
|
-
args << "-#{@options[
|
54
|
-
args << "-header" if @options[
|
55
|
-
args << File.expand_path(
|
56
|
+
args << "-#{@options[:mode]}" if @options[:mode]
|
57
|
+
args << "-header" if @options[:header]
|
58
|
+
args << File.expand_path(db_config.database, Rails.respond_to?(:root) ? Rails.root : nil)
|
56
59
|
|
57
60
|
find_cmd_and_exec("sqlite3", *args)
|
58
61
|
|
59
62
|
when "oracle", "oracle_enhanced"
|
60
63
|
logon = ""
|
61
64
|
|
62
|
-
if config[
|
63
|
-
logon = config[
|
64
|
-
logon << "/#{config[
|
65
|
-
logon << "@#{
|
65
|
+
if config[:username]
|
66
|
+
logon = config[:username].dup
|
67
|
+
logon << "/#{config[:password]}" if config[:password] && @options[:include_password]
|
68
|
+
logon << "@#{db_config.database}" if db_config.database
|
66
69
|
end
|
67
70
|
|
68
71
|
find_cmd_and_exec("sqlplus", logon)
|
@@ -70,44 +73,51 @@ module Rails
|
|
70
73
|
when "sqlserver"
|
71
74
|
args = []
|
72
75
|
|
73
|
-
args += ["-
|
74
|
-
args += ["-U", "#{config[
|
75
|
-
args += ["-P", "#{config[
|
76
|
+
args += ["-d", "#{db_config.database}"] if db_config.database
|
77
|
+
args += ["-U", "#{config[:username]}"] if config[:username]
|
78
|
+
args += ["-P", "#{config[:password]}"] if config[:password]
|
76
79
|
|
77
|
-
if config[
|
78
|
-
host_arg = "
|
79
|
-
host_arg << "
|
80
|
+
if config[:host]
|
81
|
+
host_arg = +"tcp:#{config[:host]}"
|
82
|
+
host_arg << ",#{config[:port]}" if config[:port]
|
80
83
|
args += ["-S", host_arg]
|
81
84
|
end
|
82
85
|
|
83
|
-
find_cmd_and_exec("
|
86
|
+
find_cmd_and_exec("sqlcmd", *args)
|
84
87
|
|
85
88
|
else
|
86
|
-
abort "Unknown command-line client for #{
|
89
|
+
abort "Unknown command-line client for #{db_config.database}."
|
87
90
|
end
|
88
91
|
end
|
89
92
|
|
90
93
|
def config
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
94
|
+
db_config.configuration_hash
|
95
|
+
end
|
96
|
+
deprecate config: "please use db_config.configuration_hash"
|
97
|
+
|
98
|
+
def db_config
|
99
|
+
return @db_config if defined?(@db_config)
|
100
|
+
|
101
|
+
# We need to check whether the user passed the database the
|
102
|
+
# first time around to show a consistent error message to people
|
103
|
+
# relying on 2-level database configuration.
|
104
|
+
|
105
|
+
@db_config = configurations.configs_for(env_name: environment, name: database)
|
106
|
+
|
107
|
+
unless @db_config
|
108
|
+
raise ActiveRecord::AdapterNotSpecified,
|
109
|
+
"'#{database}' database is not configured for '#{environment}'. Available configuration: #{configurations.inspect}"
|
102
110
|
end
|
111
|
+
|
112
|
+
@db_config
|
103
113
|
end
|
104
114
|
|
105
115
|
def environment
|
106
116
|
Rails.respond_to?(:env) ? Rails.env : Rails::Command.environment
|
107
117
|
end
|
108
118
|
|
109
|
-
def
|
110
|
-
@options.fetch(:
|
119
|
+
def database
|
120
|
+
@options.fetch(:database, "primary")
|
111
121
|
end
|
112
122
|
|
113
123
|
private
|
@@ -129,7 +139,12 @@ module Rails
|
|
129
139
|
found = commands.detect do |cmd|
|
130
140
|
dirs_on_path.detect do |path|
|
131
141
|
full_path_command = File.join(path, cmd)
|
132
|
-
|
142
|
+
begin
|
143
|
+
stat = File.stat(full_path_command)
|
144
|
+
rescue SystemCallError
|
145
|
+
else
|
146
|
+
stat.file? && stat.executable?
|
147
|
+
end
|
133
148
|
end
|
134
149
|
end
|
135
150
|
|
@@ -153,8 +168,8 @@ module Rails
|
|
153
168
|
|
154
169
|
class_option :header, type: :boolean
|
155
170
|
|
156
|
-
class_option :
|
157
|
-
desc: "Specifies the
|
171
|
+
class_option :database, aliases: "--db", type: :string,
|
172
|
+
desc: "Specifies the database to use."
|
158
173
|
|
159
174
|
def perform
|
160
175
|
extract_environment_option_from_argument
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/dev_caching"
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
module Command
|
7
|
+
class DevCommand < Base # :nodoc:
|
8
|
+
no_commands do
|
9
|
+
def help
|
10
|
+
say "rails dev:cache # Toggle development mode caching on/off."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def cache
|
15
|
+
Rails::DevCaching.enable_by_file
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
=== Storing Encrypted Files in Source Control
|
2
|
+
|
3
|
+
The Rails `encrypted` commands provide access to encrypted files or configurations.
|
4
|
+
See the `Rails.application.encrypted` documentation for using them in your app.
|
5
|
+
|
6
|
+
=== Encryption Keys
|
7
|
+
|
8
|
+
By default, Rails looks for the encryption key in `config/master.key` or
|
9
|
+
`ENV["RAILS_MASTER_KEY"]`, but that lookup can be overridden with `--key`:
|
10
|
+
|
11
|
+
rails encrypted:edit config/encrypted_file.yml.enc --key config/encrypted_file.key
|
12
|
+
|
13
|
+
Don't commit the key! Add it to your source control's ignore file. If you use
|
14
|
+
Git, Rails handles this for you.
|
15
|
+
|
16
|
+
=== Editing Files
|
17
|
+
|
18
|
+
To edit or create an encrypted file use:
|
19
|
+
|
20
|
+
rails encrypted:edit config/encrypted_file.yml.enc
|
21
|
+
|
22
|
+
This opens a temporary file in `$EDITOR` with the decrypted contents for editing.
|
23
|
+
|
24
|
+
=== Viewing Files
|
25
|
+
|
26
|
+
To print the decrypted contents of an encrypted file use:
|
27
|
+
|
28
|
+
rails encrypted:show config/encrypted_file.yml.enc
|
@@ -16,11 +16,12 @@ module Rails
|
|
16
16
|
def help
|
17
17
|
say "Usage:\n #{self.class.banner}"
|
18
18
|
say ""
|
19
|
+
say self.class.desc
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
23
|
def edit(file_path)
|
23
|
-
|
24
|
+
require_application!
|
24
25
|
encrypted = Rails.application.encrypted(file_path, key_path: options[:key])
|
25
26
|
|
26
27
|
ensure_editor_available(command: "bin/rails encrypted:edit") || (return)
|
@@ -37,7 +38,7 @@ module Rails
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def show(file_path)
|
40
|
-
|
41
|
+
require_application!
|
41
42
|
encrypted = Rails.application.encrypted(file_path, key_path: options[:key])
|
42
43
|
|
43
44
|
say encrypted.read.presence || missing_encrypted_message(key: encrypted.key, key_path: options[:key], file_path: file_path)
|
@@ -76,9 +77,9 @@ module Rails
|
|
76
77
|
|
77
78
|
def missing_encrypted_message(key:, key_path:, file_path:)
|
78
79
|
if key.nil?
|
79
|
-
"Missing '#{key_path}' to decrypt data. See bin/rails encrypted:help"
|
80
|
+
"Missing '#{key_path}' to decrypt data. See `bin/rails encrypted:help`"
|
80
81
|
else
|
81
|
-
"File '#{file_path}' does not exist. Use bin/rails encrypted:edit #{file_path} to change that."
|
82
|
+
"File '#{file_path}' does not exist. Use `bin/rails encrypted:edit #{file_path}` to change that."
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
@@ -21,7 +21,7 @@ module Rails
|
|
21
21
|
require_application_and_environment!
|
22
22
|
load_generators
|
23
23
|
|
24
|
-
ARGV.
|
24
|
+
ARGV.replace(args) # set up ARGV for third-party libraries
|
25
25
|
|
26
26
|
Rails::Generators.invoke generator, args, behavior: :invoke, destination_root: Rails::Command.root
|
27
27
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/command/environment_argument"
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
module Command
|
7
|
+
class InitializersCommand < Base # :nodoc:
|
8
|
+
include EnvironmentArgument
|
9
|
+
|
10
|
+
desc "initializers", "Print out all defined initializers in the order they are invoked by Rails."
|
11
|
+
def perform
|
12
|
+
extract_environment_option_from_argument
|
13
|
+
ENV["RAILS_ENV"] = options[:environment]
|
14
|
+
|
15
|
+
require_application_and_environment!
|
16
|
+
|
17
|
+
Rails.application.initializers.tsort_each do |initializer|
|
18
|
+
say "#{initializer.context_class}.#{initializer.name}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -10,8 +10,8 @@ module Rails
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def perform(*)
|
13
|
-
|
14
|
-
|
13
|
+
say "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n"
|
14
|
+
say "Type 'rails' for help."
|
15
15
|
exit 1
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/source_annotation_extractor"
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
module Command
|
7
|
+
class NotesCommand < Base # :nodoc:
|
8
|
+
class_option :annotations, aliases: "-a", desc: "Filter by specific annotations, e.g. Foobar TODO", type: :array, default: Rails::SourceAnnotationExtractor::Annotation.tags
|
9
|
+
|
10
|
+
def perform(*)
|
11
|
+
require_application_and_environment!
|
12
|
+
|
13
|
+
display_annotations
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def display_annotations
|
18
|
+
annotations = options[:annotations]
|
19
|
+
tag = (annotations.length > 1)
|
20
|
+
|
21
|
+
Rails::SourceAnnotationExtractor.enumerate annotations.join("|"), tag: tag, dirs: directories
|
22
|
+
end
|
23
|
+
|
24
|
+
def directories
|
25
|
+
Rails::SourceAnnotationExtractor::Annotation.directories
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -26,7 +26,7 @@ module Rails
|
|
26
26
|
|
27
27
|
if File.exist?(railsrc)
|
28
28
|
extra_args = File.read(railsrc).split(/\n+/).flat_map(&:split)
|
29
|
-
|
29
|
+
say "Using #{extra_args.join(" ")} from #{railsrc}"
|
30
30
|
plugin_args.insert(1, *extra_args)
|
31
31
|
end
|
32
32
|
end
|
@@ -12,15 +12,16 @@ module Rails
|
|
12
12
|
formatted_rake_tasks.map(&:first)
|
13
13
|
end
|
14
14
|
|
15
|
-
def perform(task,
|
15
|
+
def perform(task, args, config)
|
16
16
|
require_rake
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
Rake.with_application do |rake|
|
19
|
+
rake.init("rails", [task, *args])
|
20
|
+
rake.load_rakefile
|
21
|
+
if Rails.respond_to?(:root)
|
22
|
+
rake.options.suppress_backtrace_pattern = /\A(?!#{Regexp.quote(Rails.root.to_s)})/
|
23
|
+
end
|
24
|
+
rake.standard_exception_handling { rake.top_level }
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -30,7 +31,7 @@ module Rails
|
|
30
31
|
|
31
32
|
return @rake_tasks if defined?(@rake_tasks)
|
32
33
|
|
33
|
-
|
34
|
+
require_application!
|
34
35
|
|
35
36
|
Rake::TaskManager.record_task_metadata = true
|
36
37
|
Rake.application.instance_variable_set(:@name, "rails")
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/command"
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
module Command
|
7
|
+
class RoutesCommand < Base # :nodoc:
|
8
|
+
class_option :controller, aliases: "-c", desc: "Filter by a specific controller, e.g. PostsController or Admin::PostsController."
|
9
|
+
class_option :grep, aliases: "-g", desc: "Grep routes by a specific pattern."
|
10
|
+
class_option :expanded, type: :boolean, aliases: "-E", desc: "Print routes expanded vertically with parts explained."
|
11
|
+
|
12
|
+
def perform(*)
|
13
|
+
require_application_and_environment!
|
14
|
+
require "action_dispatch/routing/inspector"
|
15
|
+
|
16
|
+
say inspector.format(formatter, routes_filter)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def inspector
|
21
|
+
ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def formatter
|
25
|
+
if options.key?("expanded")
|
26
|
+
ActionDispatch::Routing::ConsoleFormatter::Expanded.new
|
27
|
+
else
|
28
|
+
ActionDispatch::Routing::ConsoleFormatter::Sheet.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def routes_filter
|
33
|
+
options.symbolize_keys.slice(:controller, :grep)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,16 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "rails/command/environment_argument"
|
4
|
+
|
3
5
|
module Rails
|
4
6
|
module Command
|
5
7
|
class RunnerCommand < Base # :nodoc:
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
include EnvironmentArgument
|
9
|
+
|
10
|
+
self.environment_desc = "The environment for the runner to operate under (test/development/production)"
|
9
11
|
|
10
12
|
no_commands do
|
11
13
|
def help
|
12
14
|
super
|
13
|
-
|
15
|
+
say self.class.desc
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -19,6 +21,8 @@ module Rails
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def perform(code_or_file = nil, *command_argv)
|
24
|
+
extract_environment_option_from_argument
|
25
|
+
|
22
26
|
unless code_or_file
|
23
27
|
help
|
24
28
|
exit 1
|
@@ -39,11 +43,11 @@ module Rails
|
|
39
43
|
else
|
40
44
|
begin
|
41
45
|
eval(code_or_file, TOPLEVEL_BINDING, __FILE__, __LINE__)
|
42
|
-
rescue SyntaxError, NameError =>
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
rescue SyntaxError, NameError => e
|
47
|
+
error "Please specify a valid ruby command or the path of a script to run."
|
48
|
+
error "Run '#{self.class.executable} -h' for help."
|
49
|
+
error ""
|
50
|
+
error e
|
47
51
|
exit 1
|
48
52
|
end
|
49
53
|
end
|
@@ -1,3 +1,9 @@
|
|
1
|
+
=== ** DEPRECATED **
|
2
|
+
|
3
|
+
Rails 5.2 has introduced a new `credentials` API that replaces Rails secrets.
|
4
|
+
Please use the Rails `credentials` commands instead.
|
5
|
+
Run `rails credentials:help` for more information.
|
6
|
+
|
1
7
|
=== Storing Encrypted Secrets in Source Control
|
2
8
|
|
3
9
|
The Rails `secrets` commands helps encrypting secrets to slim a production
|
@@ -22,7 +22,7 @@ module Rails
|
|
22
22
|
if ENV["EDITOR"].to_s.empty?
|
23
23
|
say "No $EDITOR to open decrypted secrets in. Assign one like this:"
|
24
24
|
say ""
|
25
|
-
say %(EDITOR="mate --wait"
|
25
|
+
say %(EDITOR="mate --wait" rails secrets:edit)
|
26
26
|
say ""
|
27
27
|
say "For editors that fork and exit immediately, it's important to pass a wait flag,"
|
28
28
|
say "otherwise the secrets will be saved immediately with no chance to edit."
|
@@ -42,7 +42,7 @@ module Rails
|
|
42
42
|
rescue Rails::Secrets::MissingKeyError => error
|
43
43
|
say error.message
|
44
44
|
rescue Errno::ENOENT => error
|
45
|
-
if
|
45
|
+
if /secrets\.yml\.enc/.match?(error.message)
|
46
46
|
deprecate_in_favor_of_credentials_and_exit
|
47
47
|
else
|
48
48
|
raise
|
@@ -56,7 +56,7 @@ module Rails
|
|
56
56
|
private
|
57
57
|
def deprecate_in_favor_of_credentials_and_exit
|
58
58
|
say "Encrypted secrets is deprecated in favor of credentials. Run:"
|
59
|
-
say "
|
59
|
+
say "rails credentials:help"
|
60
60
|
|
61
61
|
exit 1
|
62
62
|
end
|