railties 7.0.8.7 → 7.2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +210 -272
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.md +99 -0
- data/README.rdoc +4 -4
- data/lib/minitest/rails_plugin.rb +67 -1
- data/lib/rails/all.rb +1 -3
- data/lib/rails/api/task.rb +39 -6
- data/lib/rails/application/bootstrap.rb +28 -10
- data/lib/rails/application/configuration.rb +228 -72
- data/lib/rails/application/default_middleware_stack.rb +8 -2
- data/lib/rails/application/dummy_config.rb +19 -0
- data/lib/rails/application/finisher.rb +50 -33
- data/lib/rails/application.rb +117 -76
- data/lib/rails/backtrace_cleaner.rb +19 -4
- data/lib/rails/cli.rb +5 -3
- data/lib/rails/command/actions.rb +10 -12
- data/lib/rails/command/base.rb +55 -53
- data/lib/rails/command/environment_argument.rb +32 -16
- data/lib/rails/command/helpers/editor.rb +17 -12
- data/lib/rails/command.rb +84 -33
- data/lib/rails/commands/about/about_command.rb +14 -0
- data/lib/rails/commands/app/update_command.rb +102 -0
- data/lib/rails/commands/application/application_command.rb +2 -0
- data/lib/rails/commands/boot/boot_command.rb +14 -0
- data/lib/rails/commands/console/console_command.rb +11 -30
- data/lib/rails/commands/console/irb_console.rb +146 -0
- data/lib/rails/commands/credentials/USAGE +53 -55
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +5 -3
- data/lib/rails/commands/credentials/credentials_command.rb +64 -70
- data/lib/rails/commands/db/system/change/change_command.rb +2 -1
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +32 -131
- data/lib/rails/commands/destroy/destroy_command.rb +3 -2
- data/lib/rails/commands/dev/dev_command.rb +1 -6
- data/lib/rails/commands/devcontainer/devcontainer_command.rb +39 -0
- data/lib/rails/commands/encrypted/USAGE +15 -20
- data/lib/rails/commands/encrypted/encrypted_command.rb +46 -35
- data/lib/rails/commands/gem_help/USAGE +16 -0
- data/lib/rails/commands/gem_help/gem_help_command.rb +13 -0
- data/lib/rails/commands/generate/generate_command.rb +2 -2
- data/lib/rails/commands/help/USAGE +13 -13
- data/lib/rails/commands/help/help_command.rb +21 -2
- data/lib/rails/commands/initializers/initializers_command.rb +1 -4
- data/lib/rails/commands/middleware/middleware_command.rb +17 -0
- data/lib/rails/commands/new/new_command.rb +2 -0
- data/lib/rails/commands/notes/notes_command.rb +2 -1
- data/lib/rails/commands/plugin/plugin_command.rb +2 -0
- data/lib/rails/commands/rake/rake_command.rb +25 -22
- data/lib/rails/commands/restart/restart_command.rb +14 -0
- data/lib/rails/commands/routes/routes_command.rb +13 -1
- data/lib/rails/commands/runner/USAGE +14 -12
- data/lib/rails/commands/runner/runner_command.rb +42 -19
- data/lib/rails/commands/secret/secret_command.rb +13 -0
- data/lib/rails/commands/server/server_command.rb +37 -34
- data/lib/rails/commands/test/USAGE +14 -0
- data/lib/rails/commands/test/test_command.rb +58 -14
- data/lib/rails/commands/unused_routes/unused_routes_command.rb +75 -0
- data/lib/rails/commands/version/version_command.rb +1 -0
- data/lib/rails/configuration.rb +15 -6
- data/lib/rails/console/app.rb +5 -35
- data/lib/rails/console/helpers.rb +5 -16
- data/lib/rails/console/methods.rb +23 -0
- data/lib/rails/deprecator.rb +7 -0
- data/lib/rails/engine/configuration.rb +50 -6
- data/lib/rails/engine.rb +53 -25
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions.rb +6 -15
- data/lib/rails/generators/active_model.rb +28 -14
- data/lib/rails/generators/app_base.rb +382 -88
- data/lib/rails/generators/app_name.rb +3 -14
- data/lib/rails/generators/base.rb +21 -9
- data/lib/rails/generators/database.rb +231 -35
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +2 -0
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +2 -0
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +2 -0
- data/lib/rails/generators/generated_attribute.rb +38 -1
- data/lib/rails/generators/migration.rb +4 -5
- data/lib/rails/generators/model_helpers.rb +2 -1
- data/lib/rails/generators/rails/app/USAGE +22 -6
- data/lib/rails/generators/rails/app/app_generator.rb +135 -86
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +110 -0
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +19 -21
- data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +4 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +8 -1
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/views/pwa/manifest.json.erb.tt +22 -0
- data/lib/rails/generators/rails/app/templates/app/views/pwa/service-worker.js +26 -0
- data/lib/rails/generators/rails/app/templates/bin/brakeman.tt +6 -0
- data/lib/rails/generators/rails/app/templates/bin/rubocop.tt +7 -0
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +15 -2
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +6 -17
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -6
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +10 -3
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbcmysql.yml.tt → trilogy.yml.tt} +12 -7
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +25 -8
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +40 -28
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +20 -13
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.tt +70 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -9
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +11 -13
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +25 -34
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +11 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +6 -4
- data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +15 -0
- data/lib/rails/generators/rails/app/templates/dockerignore.tt +56 -0
- data/lib/rails/generators/rails/app/templates/github/ci.yml.tt +138 -0
- data/lib/rails/generators/rails/app/templates/github/dependabot.yml +12 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +7 -11
- data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
- data/lib/rails/generators/rails/app/templates/public/406-unsupported-browser.html +66 -0
- data/lib/rails/generators/rails/app/templates/public/icon.png +0 -0
- data/lib/rails/generators/rails/app/templates/public/icon.svg +3 -0
- data/lib/rails/generators/rails/app/templates/rubocop.yml.tt +8 -0
- data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +10 -8
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +9 -7
- data/lib/rails/generators/rails/application_record/application_record_generator.rb +4 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +2 -1
- data/lib/rails/generators/rails/controller/USAGE +12 -4
- data/lib/rails/generators/rails/controller/controller_generator.rb +6 -1
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +1 -1
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +29 -24
- data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +8 -0
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +146 -5
- data/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb +166 -0
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/Dockerfile.tt +3 -0
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/compose.yaml.tt +47 -0
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/devcontainer.json.tt +37 -0
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -2
- data/lib/rails/generators/rails/migration/USAGE +21 -11
- data/lib/rails/generators/rails/migration/migration_generator.rb +4 -0
- data/lib/rails/generators/rails/model/model_generator.rb +4 -0
- data/lib/rails/generators/rails/plugin/USAGE +17 -6
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +45 -22
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +7 -3
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +2 -0
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -17
- data/lib/rails/generators/rails/plugin/templates/bin/rubocop.tt +7 -0
- data/lib/rails/generators/rails/plugin/templates/github/ci.yml.tt +103 -0
- data/lib/rails/generators/rails/plugin/templates/github/dependabot.yml +12 -0
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -2
- data/lib/rails/generators/rails/plugin/templates/rubocop.yml.tt +8 -0
- data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +5 -5
- data/lib/rails/generators/rails/resource/resource_generator.rb +6 -0
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -1
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
- data/lib/rails/generators/test_case.rb +2 -2
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +6 -4
- data/lib/rails/generators/test_unit/mailer/templates/preview.rb.tt +3 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +16 -2
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +2 -0
- data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb.tt +1 -1
- data/lib/rails/generators/testing/assertions.rb +20 -0
- data/lib/rails/generators/testing/{behaviour.rb → behavior.rb} +8 -4
- data/lib/rails/generators.rb +12 -16
- data/lib/rails/health_controller.rb +55 -0
- data/lib/rails/info.rb +3 -3
- data/lib/rails/info_controller.rb +33 -11
- data/lib/rails/mailers_controller.rb +29 -6
- data/lib/rails/paths.rb +15 -12
- data/lib/rails/pwa_controller.rb +15 -0
- data/lib/rails/rack/logger.rb +27 -16
- data/lib/rails/rackup/server.rb +15 -0
- data/lib/rails/railtie/configurable.rb +2 -2
- data/lib/rails/railtie/configuration.rb +14 -1
- data/lib/rails/railtie.rb +33 -34
- data/lib/rails/source_annotation_extractor.rb +67 -18
- data/lib/rails/tasks/engine.rake +8 -8
- data/lib/rails/tasks/framework.rake +2 -34
- data/lib/rails/tasks/log.rake +1 -1
- data/lib/rails/tasks/misc.rake +3 -14
- data/lib/rails/tasks/statistics.rake +5 -4
- data/lib/rails/tasks/tmp.rake +6 -6
- data/lib/rails/tasks/zeitwerk.rake +15 -35
- data/lib/rails/tasks.rb +0 -2
- data/lib/rails/templates/layouts/application.html.erb +1 -1
- data/lib/rails/templates/rails/mailers/email.html.erb +44 -8
- data/lib/rails/templates/rails/mailers/index.html.erb +14 -7
- data/lib/rails/templates/rails/mailers/mailer.html.erb +11 -5
- data/lib/rails/templates/rails/welcome/index.html.erb +5 -2
- data/lib/rails/test_help.rb +11 -18
- data/lib/rails/test_unit/line_filtering.rb +1 -1
- data/lib/rails/test_unit/reporter.rb +14 -4
- data/lib/rails/test_unit/runner.rb +62 -20
- data/lib/rails/test_unit/test_parser.rb +133 -0
- data/lib/rails/test_unit/testing.rake +13 -33
- data/lib/rails/testing/maintain_test_schema.rb +16 -0
- data/lib/rails/version.rb +1 -1
- data/lib/rails/zeitwerk_checker.rb +15 -0
- data/lib/rails.rb +20 -17
- metadata +87 -40
- data/RDOC_MAIN.rdoc +0 -97
- data/lib/rails/app_updater.rb +0 -40
- data/lib/rails/application/dummy_erb_compiler.rb +0 -18
- data/lib/rails/commands/secrets/USAGE +0 -66
- data/lib/rails/commands/secrets/secrets_command.rb +0 -65
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +0 -68
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +0 -70
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +0 -24
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +0 -62
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +0 -53
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +0 -143
- data/lib/rails/generators/rails/app/templates/public/apple-touch-icon-precomposed.png +0 -0
- data/lib/rails/generators/rails/app/templates/public/apple-touch-icon.png +0 -0
- data/lib/rails/generators/rails/app/templates/public/favicon.ico +0 -0
- data/lib/rails/generators/rails/model/USAGE +0 -113
- data/lib/rails/ruby_version_check.rb +0 -15
- data/lib/rails/secrets.rb +0 -110
- data/lib/rails/tasks/middleware.rake +0 -9
- data/lib/rails/tasks/restart.rake +0 -9
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/core_ext/string/filters"
|
4
|
-
require "active_support/deprecation"
|
5
4
|
require "rails/command/environment_argument"
|
6
5
|
|
7
6
|
module Rails
|
@@ -12,150 +11,56 @@ module Rails
|
|
12
11
|
|
13
12
|
def initialize(options = {})
|
14
13
|
@options = options
|
14
|
+
@options[:environment] ||= Rails::Command.environment
|
15
15
|
end
|
16
16
|
|
17
17
|
def start
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
when /^(jdbc)?mysql/
|
23
|
-
args = {
|
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"
|
34
|
-
}.filter_map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }
|
35
|
-
|
36
|
-
if config[:password] && @options[:include_password]
|
37
|
-
args << "--password=#{config[:password]}"
|
38
|
-
elsif config[:password] && !config[:password].to_s.empty?
|
39
|
-
args << "-p"
|
40
|
-
end
|
41
|
-
|
42
|
-
args << db_config.database
|
43
|
-
|
44
|
-
find_cmd_and_exec(["mysql", "mysql5"], *args)
|
45
|
-
|
46
|
-
when /^postgres|^postgis/
|
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
|
-
ENV["PGSSLMODE"] = config[:sslmode].to_s if config[:sslmode]
|
52
|
-
ENV["PGSSLCERT"] = config[:sslcert].to_s if config[:sslcert]
|
53
|
-
ENV["PGSSLKEY"] = config[:sslkey].to_s if config[:sslkey]
|
54
|
-
ENV["PGSSLROOTCERT"] = config[:sslrootcert].to_s if config[:sslrootcert]
|
55
|
-
find_cmd_and_exec("psql", db_config.database)
|
56
|
-
|
57
|
-
when "sqlite3"
|
58
|
-
args = []
|
59
|
-
|
60
|
-
args << "-#{@options[:mode]}" if @options[:mode]
|
61
|
-
args << "-header" if @options[:header]
|
62
|
-
args << File.expand_path(db_config.database, Rails.respond_to?(:root) ? Rails.root : nil)
|
63
|
-
|
64
|
-
find_cmd_and_exec("sqlite3", *args)
|
65
|
-
|
66
|
-
when "oracle", "oracle_enhanced"
|
67
|
-
logon = ""
|
18
|
+
adapter_class.dbconsole(db_config, @options)
|
19
|
+
rescue NotImplementedError, ActiveRecord::AdapterNotFound, LoadError => error
|
20
|
+
abort error.message
|
21
|
+
end
|
68
22
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
23
|
+
def db_config
|
24
|
+
@db_config ||= begin
|
25
|
+
# If the user provided a database, use that. Otherwise find
|
26
|
+
# the first config in the database.yml
|
27
|
+
config = if database
|
28
|
+
@db_config = configurations.configs_for(env_name: environment, name: database, include_hidden: true)
|
29
|
+
else
|
30
|
+
@db_config = configurations.find_db_config(environment)
|
73
31
|
end
|
74
32
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
args += ["-d", "#{db_config.database}"] if db_config.database
|
81
|
-
args += ["-U", "#{config[:username]}"] if config[:username]
|
82
|
-
args += ["-P", "#{config[:password]}"] if config[:password]
|
83
|
-
|
84
|
-
if config[:host]
|
85
|
-
host_arg = +"tcp:#{config[:host]}"
|
86
|
-
host_arg << ",#{config[:port]}" if config[:port]
|
87
|
-
args += ["-S", host_arg]
|
33
|
+
unless config
|
34
|
+
missing_db = database ? "'#{database}' database is not" : "No databases are"
|
35
|
+
raise ActiveRecord::AdapterNotSpecified,
|
36
|
+
"#{missing_db} configured for '#{environment}'. Available configuration: #{configurations.inspect}"
|
88
37
|
end
|
89
38
|
|
90
|
-
|
91
|
-
|
92
|
-
else
|
93
|
-
abort "Unknown command-line client for #{db_config.database}."
|
39
|
+
config.validate!
|
40
|
+
config
|
94
41
|
end
|
95
42
|
end
|
96
43
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
# If the user provided a database, use that. Otherwise find
|
101
|
-
# the first config in the database.yml
|
102
|
-
if database
|
103
|
-
@db_config = configurations.configs_for(env_name: environment, name: database, include_hidden: true)
|
104
|
-
else
|
105
|
-
@db_config = configurations.find_db_config(environment)
|
106
|
-
end
|
107
|
-
|
108
|
-
unless @db_config
|
109
|
-
missing_db = database ? "'#{database}' database is not" : "No databases are"
|
110
|
-
raise ActiveRecord::AdapterNotSpecified,
|
111
|
-
"#{missing_db} configured for '#{environment}'. Available configuration: #{configurations.inspect}"
|
112
|
-
end
|
113
|
-
|
114
|
-
@db_config
|
44
|
+
def database
|
45
|
+
@options[:database]
|
115
46
|
end
|
116
47
|
|
117
48
|
def environment
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
def database
|
122
|
-
@options[:database]
|
49
|
+
@options[:environment]
|
123
50
|
end
|
124
51
|
|
125
52
|
private
|
53
|
+
def adapter_class
|
54
|
+
ActiveRecord::ConnectionAdapters.resolve(db_config.adapter)
|
55
|
+
rescue LoadError
|
56
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter
|
57
|
+
end
|
58
|
+
|
126
59
|
def configurations # :doc:
|
127
60
|
require APP_PATH
|
128
61
|
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
129
62
|
ActiveRecord::Base.configurations
|
130
63
|
end
|
131
|
-
|
132
|
-
def find_cmd_and_exec(commands, *args) # :doc:
|
133
|
-
commands = Array(commands)
|
134
|
-
|
135
|
-
dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR)
|
136
|
-
unless (ext = RbConfig::CONFIG["EXEEXT"]).empty?
|
137
|
-
commands = commands.map { |cmd| "#{cmd}#{ext}" }
|
138
|
-
end
|
139
|
-
|
140
|
-
full_path_command = nil
|
141
|
-
found = commands.detect do |cmd|
|
142
|
-
dirs_on_path.detect do |path|
|
143
|
-
full_path_command = File.join(path, cmd)
|
144
|
-
begin
|
145
|
-
stat = File.stat(full_path_command)
|
146
|
-
rescue SystemCallError
|
147
|
-
else
|
148
|
-
stat.file? && stat.executable?
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
if found
|
154
|
-
exec full_path_command, *args
|
155
|
-
else
|
156
|
-
abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
|
157
|
-
end
|
158
|
-
end
|
159
64
|
end
|
160
65
|
|
161
66
|
module Command
|
@@ -166,20 +71,16 @@ module Rails
|
|
166
71
|
desc: "Automatically provide the password from database.yml"
|
167
72
|
|
168
73
|
class_option :mode, enum: %w( html list line column ), type: :string,
|
169
|
-
desc: "Automatically put the sqlite3 database in the specified mode
|
74
|
+
desc: "Automatically put the sqlite3 database in the specified mode"
|
170
75
|
|
171
76
|
class_option :header, type: :boolean
|
172
77
|
|
173
78
|
class_option :database, aliases: "--db", type: :string,
|
174
|
-
desc: "
|
79
|
+
desc: "Specify the database to use."
|
175
80
|
|
81
|
+
desc "dbconsole", "Start a console for the database specified in config/database.yml"
|
176
82
|
def perform
|
177
|
-
|
178
|
-
|
179
|
-
# RAILS_ENV needs to be set before config/application is required.
|
180
|
-
ENV["RAILS_ENV"] = options[:environment]
|
181
|
-
|
182
|
-
require_application_and_environment!
|
83
|
+
boot_application!
|
183
84
|
Rails::DBConsole.start(options)
|
184
85
|
end
|
185
86
|
end
|
@@ -7,18 +7,19 @@ module Rails
|
|
7
7
|
class DestroyCommand < Base # :nodoc:
|
8
8
|
no_commands do
|
9
9
|
def help
|
10
|
-
|
10
|
+
boot_application!
|
11
11
|
load_generators
|
12
12
|
|
13
13
|
Rails::Generators.help self.class.command_name
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
desc "destroy GENERATOR", "Remove code generated by `bin/rails generate`"
|
17
18
|
def perform(*)
|
18
19
|
generator = args.shift
|
19
20
|
return help unless generator
|
20
21
|
|
21
|
-
|
22
|
+
boot_application!
|
22
23
|
load_generators
|
23
24
|
|
24
25
|
Rails::Generators.invoke generator, args, behavior: :revoke, destination_root: Rails::Command.root
|
@@ -5,12 +5,7 @@ require "rails/dev_caching"
|
|
5
5
|
module Rails
|
6
6
|
module Command
|
7
7
|
class DevCommand < Base # :nodoc:
|
8
|
-
|
9
|
-
def help
|
10
|
-
say "rails dev:cache # Toggle development mode caching on/off."
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
8
|
+
desc "cache", "Toggle development mode caching on/off"
|
14
9
|
def cache
|
15
10
|
Rails::DevCaching.enable_by_file
|
16
11
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
require "rails/generators/rails/devcontainer/devcontainer_generator"
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
module Command
|
8
|
+
class DevcontainerCommand < Base # :nodoc:
|
9
|
+
desc "devcontainer", "Generate a Dev Container setup based on current application configuration"
|
10
|
+
def perform(*)
|
11
|
+
boot_application!
|
12
|
+
|
13
|
+
say "Generating Dev Container with the following options:"
|
14
|
+
devcontainer_options.each do |option, value|
|
15
|
+
say "#{option}: #{value}"
|
16
|
+
end
|
17
|
+
|
18
|
+
Rails::Generators::DevcontainerGenerator.new([], devcontainer_options).invoke_all
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def devcontainer_options
|
23
|
+
@devcontainer_options ||= {
|
24
|
+
app_name: Rails.application.railtie_name.chomp("_application"),
|
25
|
+
database: !!defined?(ActiveRecord) && database,
|
26
|
+
active_storage: !!defined?(ActiveStorage),
|
27
|
+
redis: !!(defined?(ActionCable) || defined?(ActiveJob)),
|
28
|
+
system_test: File.exist?("test/application_system_test_case.rb"),
|
29
|
+
node: File.exist?(".node-version"),
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def database
|
34
|
+
adapter = ActiveRecord::Base.connection_db_config.adapter
|
35
|
+
adapter == "mysql2" ? "mysql" : adapter
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,28 +1,23 @@
|
|
1
|
-
|
1
|
+
Description:
|
2
|
+
The Rails `encrypted` commands provide access to encrypted files or configurations.
|
3
|
+
See the `Rails.application.encrypted` documentation for using them in your app.
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
+
Encryption Keys:
|
6
|
+
By default, Rails looks for the encryption key in `ENV["RAILS_MASTER_KEY"]` or
|
7
|
+
`config/master.key`, but that lookup can be overridden with `--key`:
|
5
8
|
|
6
|
-
|
9
|
+
<%= executable(:edit) %> config/encrypted_file.yml.enc --key config/encrypted_file.key
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
Don't commit the key! Add it to your source control's ignore file. If you use
|
12
|
+
Git, Rails handles this for you.
|
10
13
|
|
11
|
-
|
14
|
+
Examples:
|
15
|
+
To edit or create an encrypted file use:
|
12
16
|
|
13
|
-
|
14
|
-
Git, Rails handles this for you.
|
17
|
+
<%= executable(:edit) %> config/encrypted_file.yml.enc
|
15
18
|
|
16
|
-
|
19
|
+
This opens a temporary file in `$VISUAL` or `$EDITOR` with the decrypted contents for editing.
|
17
20
|
|
18
|
-
To
|
21
|
+
To print the decrypted contents of an encrypted file use:
|
19
22
|
|
20
|
-
|
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
|
23
|
+
<%= executable(:show) %> config/encrypted_file.yml.enc
|
@@ -12,54 +12,65 @@ module Rails
|
|
12
12
|
class_option :key, aliases: "-k", type: :string,
|
13
13
|
default: "config/master.key", desc: "The Rails.root relative path to the encryption key"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
say ""
|
19
|
-
say self.class.desc
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def edit(file_path)
|
24
|
-
require_application!
|
25
|
-
encrypted = Rails.application.encrypted(file_path, key_path: options[:key])
|
15
|
+
desc "edit", "Open the decrypted file in `$VISUAL` or `$EDITOR` for editing"
|
16
|
+
def edit(*)
|
17
|
+
load_environment_config!
|
26
18
|
|
27
|
-
|
28
|
-
|
29
|
-
ensure_encrypted_file_has_been_added(file_path, options[:key])
|
19
|
+
ensure_encryption_key_has_been_added
|
20
|
+
ensure_encrypted_configuration_has_been_added
|
30
21
|
|
31
|
-
|
32
|
-
change_encrypted_file_in_system_editor(file_path, options[:key])
|
33
|
-
end
|
34
|
-
|
35
|
-
say "File encrypted and saved."
|
36
|
-
rescue ActiveSupport::MessageEncryptor::InvalidMessage
|
37
|
-
say "Couldn't decrypt #{file_path}. Perhaps you passed the wrong key?"
|
22
|
+
change_encrypted_configuration_in_system_editor
|
38
23
|
end
|
39
24
|
|
40
|
-
|
41
|
-
|
42
|
-
|
25
|
+
desc "show", "Show the decrypted contents of the file"
|
26
|
+
def show(*)
|
27
|
+
load_environment_config!
|
43
28
|
|
44
|
-
say
|
29
|
+
say encrypted_configuration.read.presence || missing_encrypted_configuration_message
|
45
30
|
end
|
46
31
|
|
47
32
|
private
|
48
|
-
def
|
33
|
+
def content_path
|
34
|
+
@content_path ||= args[0]
|
35
|
+
end
|
36
|
+
|
37
|
+
def key_path
|
38
|
+
options[:key]
|
39
|
+
end
|
40
|
+
|
41
|
+
def encrypted_configuration
|
42
|
+
@encrypted_configuration ||= Rails.application.encrypted(content_path, key_path: key_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def ensure_encryption_key_has_been_added
|
46
|
+
return if encrypted_configuration.key?
|
49
47
|
encryption_key_file_generator.add_key_file(key_path)
|
50
48
|
encryption_key_file_generator.ignore_key_file(key_path)
|
51
49
|
end
|
52
50
|
|
53
|
-
def
|
54
|
-
encrypted_file_generator.add_encrypted_file_silently(
|
51
|
+
def ensure_encrypted_configuration_has_been_added
|
52
|
+
encrypted_file_generator.add_encrypted_file_silently(content_path, key_path)
|
55
53
|
end
|
56
54
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
55
|
+
def change_encrypted_configuration_in_system_editor
|
56
|
+
using_system_editor do
|
57
|
+
encrypted_configuration.change { |tmp_path| system_editor(tmp_path) }
|
58
|
+
say "File encrypted and saved."
|
59
|
+
warn_if_encrypted_configuration_is_invalid
|
60
60
|
end
|
61
|
+
rescue ActiveSupport::EncryptedFile::MissingKeyError => error
|
62
|
+
say error.message
|
63
|
+
rescue ActiveSupport::MessageEncryptor::InvalidMessage
|
64
|
+
say "Couldn't decrypt #{content_path}. Perhaps you passed the wrong key?"
|
61
65
|
end
|
62
66
|
|
67
|
+
def warn_if_encrypted_configuration_is_invalid
|
68
|
+
encrypted_configuration.validate!
|
69
|
+
rescue ActiveSupport::EncryptedConfiguration::InvalidContentError => error
|
70
|
+
say "WARNING: #{error.message}", :red
|
71
|
+
say ""
|
72
|
+
say "Your application will not be able to load '#{content_path}' until the error has been fixed.", :red
|
73
|
+
end
|
63
74
|
|
64
75
|
def encryption_key_file_generator
|
65
76
|
require "rails/generators"
|
@@ -75,11 +86,11 @@ module Rails
|
|
75
86
|
Rails::Generators::EncryptedFileGenerator.new
|
76
87
|
end
|
77
88
|
|
78
|
-
def
|
79
|
-
if key
|
80
|
-
"Missing '#{key_path}' to decrypt data. See
|
89
|
+
def missing_encrypted_configuration_message
|
90
|
+
if !encrypted_configuration.key?
|
91
|
+
"Missing '#{key_path}' to decrypt data. See `#{executable(:help)}`"
|
81
92
|
else
|
82
|
-
"File '#{
|
93
|
+
"File '#{content_path}' does not exist. Use `#{executable(:edit)} #{content_path}` to change that."
|
83
94
|
end
|
84
95
|
end
|
85
96
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Usage:
|
2
|
+
rails COMMAND [options]
|
3
|
+
|
4
|
+
You must specify a command:
|
5
|
+
|
6
|
+
new Create a new Rails application. "rails new my_app" creates a
|
7
|
+
new application called MyApp in "./my_app"
|
8
|
+
plugin new Create a new Rails railtie or engine
|
9
|
+
|
10
|
+
All commands can be run with -h (or --help) for more information.
|
11
|
+
|
12
|
+
Inside a Rails application directory, some common commands are:
|
13
|
+
|
14
|
+
console Start the Rails console
|
15
|
+
server Start the Rails server
|
16
|
+
test Run tests except system tests
|
@@ -7,7 +7,7 @@ module Rails
|
|
7
7
|
class GenerateCommand < Base # :nodoc:
|
8
8
|
no_commands do
|
9
9
|
def help
|
10
|
-
|
10
|
+
boot_application!
|
11
11
|
load_generators
|
12
12
|
|
13
13
|
Rails::Generators.help self.class.command_name
|
@@ -18,7 +18,7 @@ module Rails
|
|
18
18
|
generator = args.shift
|
19
19
|
return help unless generator
|
20
20
|
|
21
|
-
|
21
|
+
boot_application!
|
22
22
|
load_generators
|
23
23
|
|
24
24
|
ARGV.replace(args) # set up ARGV for third-party libraries
|
@@ -1,17 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
Usage:
|
2
|
+
bin/rails COMMAND [options]
|
3
|
+
|
4
|
+
You must specify a command. The most common commands are:
|
5
|
+
|
6
|
+
generate Generate new code (short-cut alias: "g")
|
7
|
+
console Start the Rails console (short-cut alias: "c")
|
8
|
+
server Start the Rails server (short-cut alias: "s")
|
9
|
+
test Run tests except system tests (short-cut alias: "t")
|
10
|
+
test:system Run system tests
|
11
|
+
dbconsole Start a console for the database specified in config/database.yml
|
12
|
+
(short-cut alias: "db")
|
9
13
|
<% unless engine? -%>
|
10
|
-
new
|
11
|
-
new application called MyApp in "./my_app"
|
12
|
-
plugin new Create a new Rails railtie or engine
|
14
|
+
plugin new Create a new Rails railtie or engine
|
13
15
|
<% end -%>
|
14
16
|
|
15
17
|
All commands can be run with -h (or --help) for more information.
|
16
|
-
In addition to those commands, there are:
|
17
|
-
|
@@ -6,10 +6,29 @@ module Rails
|
|
6
6
|
hide_command!
|
7
7
|
|
8
8
|
def help(*)
|
9
|
-
say self.class.
|
9
|
+
say self.class.class_usage
|
10
|
+
end
|
11
|
+
|
12
|
+
def help_extended(*)
|
13
|
+
help
|
14
|
+
|
15
|
+
say ""
|
16
|
+
say "In addition to those commands, there are:"
|
17
|
+
say ""
|
10
18
|
|
11
|
-
|
19
|
+
extended_commands = printing_commands_not_in_usage.sort_by(&:first)
|
20
|
+
print_table(extended_commands, truncate: true)
|
12
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
COMMANDS_IN_USAGE = %w(generate console server test test:system dbconsole new)
|
25
|
+
private_constant :COMMANDS_IN_USAGE
|
26
|
+
|
27
|
+
def printing_commands_not_in_usage # :nodoc:
|
28
|
+
Rails::Command.printing_commands.reject do |command, _|
|
29
|
+
command.in?(COMMANDS_IN_USAGE)
|
30
|
+
end
|
31
|
+
end
|
13
32
|
end
|
14
33
|
end
|
15
34
|
end
|
@@ -9,10 +9,7 @@ module Rails
|
|
9
9
|
|
10
10
|
desc "initializers", "Print out all defined initializers in the order they are invoked by Rails."
|
11
11
|
def perform
|
12
|
-
|
13
|
-
ENV["RAILS_ENV"] = options[:environment]
|
14
|
-
|
15
|
-
require_application_and_environment!
|
12
|
+
boot_application!
|
16
13
|
|
17
14
|
Rails.application.initializers.tsort_each do |initializer|
|
18
15
|
say "#{initializer.context_class}.#{initializer.name}"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Command
|
5
|
+
class MiddlewareCommand < Base # :nodoc:
|
6
|
+
desc "middleware", "Print out your Rack middleware stack"
|
7
|
+
def perform
|
8
|
+
boot_application!
|
9
|
+
|
10
|
+
Rails.configuration.middleware.each do |middleware|
|
11
|
+
say "use #{middleware.inspect}"
|
12
|
+
end
|
13
|
+
say "run #{Rails.application.class.name}.routes"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -7,8 +7,9 @@ module Rails
|
|
7
7
|
class NotesCommand < Base # :nodoc:
|
8
8
|
class_option :annotations, aliases: "-a", desc: "Filter by specific annotations, e.g. Foobar TODO", type: :array
|
9
9
|
|
10
|
+
desc "notes", "Show comments in your code annotated with FIXME, OPTIMIZE, and TODO"
|
10
11
|
def perform(*)
|
11
|
-
|
12
|
+
boot_application!
|
12
13
|
|
13
14
|
display_annotations
|
14
15
|
end
|