railties 6.0.4.3 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +234 -420
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +1 -1
- data/README.rdoc +1 -1
- data/lib/minitest/rails_plugin.rb +16 -1
- data/lib/rails/api/task.rb +1 -1
- data/lib/rails/application/bootstrap.rb +5 -5
- data/lib/rails/application/configuration.rb +72 -22
- data/lib/rails/application/default_middleware_stack.rb +5 -3
- data/lib/rails/application/finisher.rb +15 -2
- data/lib/rails/application/routes_reloader.rb +9 -2
- data/lib/rails/application.rb +45 -79
- data/lib/rails/backtrace_cleaner.rb +12 -7
- data/lib/rails/code_statistics.rb +3 -3
- data/lib/rails/code_statistics_calculator.rb +6 -6
- data/lib/rails/command/base.rb +1 -1
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +1 -1
- data/lib/rails/command.rb +7 -1
- data/lib/rails/commands/credentials/USAGE +17 -2
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/credentials/credentials_command.rb +28 -4
- data/lib/rails/commands/db/system/change/change_command.rb +6 -1
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +61 -58
- data/lib/rails/commands/encrypted/encrypted_command.rb +4 -4
- data/lib/rails/commands/generate/generate_command.rb +1 -1
- data/lib/rails/commands/notes/notes_command.rb +3 -13
- data/lib/rails/commands/rake/rake_command.rb +9 -8
- data/lib/rails/commands/secrets/USAGE +9 -3
- data/lib/rails/commands/server/server_command.rb +14 -41
- data/lib/rails/commands/test/test_command.rb +2 -2
- data/lib/rails/configuration.rb +40 -10
- data/lib/rails/engine/configuration.rb +1 -0
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +35 -32
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators/actions/create_migration.rb +5 -0
- data/lib/rails/generators/actions.rb +50 -29
- data/lib/rails/generators/app_base.rb +39 -22
- data/lib/rails/generators/base.rb +14 -11
- data/lib/rails/generators/database.rb +3 -4
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +3 -3
- data/lib/rails/generators/generated_attribute.rb +3 -9
- data/lib/rails/generators/migration.rb +2 -1
- data/lib/rails/generators/model_helpers.rb +26 -2
- data/lib/rails/generators/named_base.rb +1 -1
- data/lib/rails/generators/rails/app/USAGE +2 -1
- data/lib/rails/generators/rails/app/app_generator.rb +89 -15
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +11 -11
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +1 -1
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +11 -11
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +2 -1
- 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 +4 -4
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +13 -0
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +9 -3
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +14 -7
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +3 -4
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +10 -9
- 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 +17 -3
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +15 -5
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -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/filter_parameter_logging.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +67 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +6 -1
- 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 +0 -1
- data/lib/rails/generators/rails/app/templates/package.json.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +5 -5
- data/lib/rails/generators/rails/assets/USAGE +2 -3
- 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 +2 -40
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +1 -1
- data/lib/rails/generators/rails/generator/USAGE +2 -2
- data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
- data/lib/rails/generators/rails/helper/USAGE +2 -3
- data/lib/rails/generators/rails/integration_test/USAGE +2 -2
- data/lib/rails/generators/rails/migration/USAGE +4 -4
- data/lib/rails/generators/rails/model/USAGE +15 -16
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +25 -23
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +10 -19
- 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 +0 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +13 -11
- 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 -3
- 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 +6 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
- data/lib/rails/generators/rails/system_test/USAGE +2 -2
- data/lib/rails/generators/rails/task/USAGE +3 -3
- 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/templates/generator_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +1 -1
- 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/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/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/behaviour.rb +1 -1
- data/lib/rails/generators.rb +29 -15
- data/lib/rails/info.rb +1 -1
- data/lib/rails/info_controller.rb +1 -1
- data/lib/rails/mailers_controller.rb +1 -0
- data/lib/rails/paths.rb +14 -6
- data/lib/rails/railtie/configuration.rb +3 -2
- data/lib/rails/railtie.rb +31 -10
- data/lib/rails/source_annotation_extractor.rb +1 -15
- data/lib/rails/tasks/engine.rake +1 -4
- data/lib/rails/tasks/framework.rake +7 -1
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/statistics.rake +1 -1
- data/lib/rails/tasks/yarn.rake +14 -2
- data/lib/rails/tasks.rb +0 -4
- data/lib/rails/templates/rails/mailers/email.html.erb +1 -0
- data/lib/rails/templates/rails/welcome/index.html.erb +1 -1
- data/lib/rails/test_unit/reporter.rb +2 -1
- data/lib/rails/test_unit/runner.rb +12 -3
- data/lib/rails/test_unit/testing.rake +6 -0
- data/lib/rails.rb +5 -8
- metadata +24 -30
- 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_6_0.rb.tt +0 -45
- 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 -11
- data/lib/rails/tasks/initializers.rake +0 -9
- data/lib/rails/tasks/routes.rake +0 -9
@@ -58,20 +58,20 @@ class CodeStatisticsCalculator #:nodoc:
|
|
58
58
|
@lines += 1
|
59
59
|
|
60
60
|
if comment_started
|
61
|
-
if patterns[:end_block_comment] &&
|
61
|
+
if patterns[:end_block_comment] && patterns[:end_block_comment].match?(line)
|
62
62
|
comment_started = false
|
63
63
|
end
|
64
64
|
next
|
65
65
|
else
|
66
|
-
if patterns[:begin_block_comment] &&
|
66
|
+
if patterns[:begin_block_comment] && patterns[:begin_block_comment].match?(line)
|
67
67
|
comment_started = true
|
68
68
|
next
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
@classes += 1 if patterns[:class] &&
|
73
|
-
@methods += 1 if patterns[:method] &&
|
74
|
-
if line
|
72
|
+
@classes += 1 if patterns[:class] && patterns[:class].match?(line)
|
73
|
+
@methods += 1 if patterns[:method] && patterns[:method].match?(line)
|
74
|
+
if !line.match?(/^\s*$/) && (patterns[:line_comment].nil? || !line.match?(patterns[:line_comment]))
|
75
75
|
@code_lines += 1
|
76
76
|
end
|
77
77
|
end
|
@@ -82,7 +82,7 @@ class CodeStatisticsCalculator #:nodoc:
|
|
82
82
|
if file_path.end_with? "_test.rb"
|
83
83
|
:minitest
|
84
84
|
else
|
85
|
-
File.extname(file_path).
|
85
|
+
File.extname(file_path).delete_prefix(".").downcase.to_sym
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
data/lib/rails/command/base.rb
CHANGED
data/lib/rails/command.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support"
|
4
|
-
require "active_support/dependencies/autoload"
|
5
4
|
require "active_support/core_ext/enumerable"
|
6
5
|
require "active_support/core_ext/object/blank"
|
7
6
|
|
@@ -41,12 +40,19 @@ module Rails
|
|
41
40
|
command_name, namespace = "help", "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name)
|
42
41
|
command_name, namespace = "version", "version" if %w( -v --version ).include?(command_name)
|
43
42
|
|
43
|
+
# isolate ARGV to ensure that commands depend only on the args they are given
|
44
|
+
args = args.dup # args might *be* ARGV so dup before clearing
|
45
|
+
old_argv = ARGV.dup
|
46
|
+
ARGV.clear
|
47
|
+
|
44
48
|
command = find_by_namespace(namespace, command_name)
|
45
49
|
if command && command.all_commands[command_name]
|
46
50
|
command.perform(command_name, args, config)
|
47
51
|
else
|
48
52
|
find_by_namespace("rake").perform(full_namespace, args, config)
|
49
53
|
end
|
54
|
+
ensure
|
55
|
+
ARGV.replace(old_argv)
|
50
56
|
end
|
51
57
|
|
52
58
|
# Rails finds namespaces similar to Thor, it only adds one rule:
|
@@ -14,7 +14,7 @@ that just contains the secret_key_base used by MessageVerifiers/MessageEncryptor
|
|
14
14
|
signing and encrypting cookies.
|
15
15
|
|
16
16
|
For applications created prior to Rails 5.2, we'll automatically generate a new
|
17
|
-
credentials file in `config/credentials.yml.enc` the first time you run `rails credentials:edit`.
|
17
|
+
credentials file in `config/credentials.yml.enc` the first time you run `bin/rails credentials:edit`.
|
18
18
|
If you didn't have a master key saved in `config/master.key`, that'll be created too.
|
19
19
|
|
20
20
|
Don't lose this master key! Put it in a password manager your team can access.
|
@@ -30,6 +30,21 @@ You could prepend that to your server's start command like this:
|
|
30
30
|
|
31
31
|
RAILS_MASTER_KEY="very-secret-and-secure" server.start
|
32
32
|
|
33
|
+
=== Set up Git to Diff Credentials
|
34
|
+
|
35
|
+
Rails provides `rails credentials:diff --enroll` to instruct Git to call `rails credentials:diff`
|
36
|
+
when `git diff` is run on a credentials file.
|
37
|
+
|
38
|
+
Running the command enrolls the project such that all credentials files use the
|
39
|
+
"rails_credentials" diff driver in .gitattributes.
|
40
|
+
|
41
|
+
Additionally since Git requires the driver itself to be set up in a config file
|
42
|
+
that isn't tracked Rails automatically ensures it's configured when running
|
43
|
+
`credentials:edit`.
|
44
|
+
|
45
|
+
Otherwise each co-worker would have to run enable manually, including on each new
|
46
|
+
repo clone.
|
47
|
+
|
33
48
|
=== Editing Credentials
|
34
49
|
|
35
50
|
This will open a temporary file in `$EDITOR` with the decrypted contents to edit
|
@@ -45,7 +60,7 @@ The `credentials` command supports passing an `--environment` option to create a
|
|
45
60
|
environment specific override. That override will take precedence over the
|
46
61
|
global `config/credentials.yml.enc` file when running in that environment. So:
|
47
62
|
|
48
|
-
rails credentials:edit --environment development
|
63
|
+
bin/rails credentials:edit --environment development
|
49
64
|
|
50
65
|
will create `config/credentials/development.yml.enc` with the corresponding
|
51
66
|
encryption key in `config/credentials/development.key` if the credentials file
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails::Command::CredentialsCommand::Diffing # :nodoc:
|
4
|
+
def enroll_project_in_credentials_diffing
|
5
|
+
if enrolled?
|
6
|
+
true
|
7
|
+
else
|
8
|
+
gitattributes.write(<<~end_of_template, mode: "a")
|
9
|
+
config/credentials/*.yml.enc diff=rails_credentials
|
10
|
+
config/credentials.yml.enc diff=rails_credentials
|
11
|
+
end_of_template
|
12
|
+
|
13
|
+
say "Project successfully enrolled!"
|
14
|
+
say "Rails ensures the rails_credentials diff driver is set when running `credentials:edit`. See `credentials:help` for more."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def ensure_rails_credentials_driver_is_set
|
19
|
+
set_driver if enrolled? && !driver_configured?
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def enrolled?
|
24
|
+
gitattributes.read.match?(/config\/credentials(\/\*)?\.yml\.enc diff=rails_credentials/)
|
25
|
+
rescue Errno::ENOENT
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
def driver_configured?
|
30
|
+
system "git config --get diff.rails_credentials.textconv", out: File::NULL
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_driver
|
34
|
+
puts "running"
|
35
|
+
system "git config diff.rails_credentials.textconv 'bin/rails credentials:diff'"
|
36
|
+
end
|
37
|
+
|
38
|
+
def gitattributes
|
39
|
+
Rails.root.join(".gitattributes")
|
40
|
+
end
|
41
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "pathname"
|
3
4
|
require "active_support"
|
4
5
|
require "rails/command/helpers/editor"
|
5
6
|
require "rails/command/environment_argument"
|
@@ -10,6 +11,9 @@ module Rails
|
|
10
11
|
include Helpers::Editor
|
11
12
|
include EnvironmentArgument
|
12
13
|
|
14
|
+
require_relative "credentials_command/diffing"
|
15
|
+
include Diffing
|
16
|
+
|
13
17
|
self.environment_desc = "Uses credentials from config/credentials/:environment.yml.enc encrypted by config/credentials/:environment.key key"
|
14
18
|
|
15
19
|
no_commands do
|
@@ -28,6 +32,7 @@ module Rails
|
|
28
32
|
|
29
33
|
ensure_encryption_key_has_been_added if credentials.key.nil?
|
30
34
|
ensure_credentials_have_been_added
|
35
|
+
ensure_rails_credentials_driver_is_set
|
31
36
|
|
32
37
|
catch_editing_exceptions do
|
33
38
|
change_credentials_in_system_editor
|
@@ -45,6 +50,23 @@ module Rails
|
|
45
50
|
say credentials.read.presence || missing_credentials_message
|
46
51
|
end
|
47
52
|
|
53
|
+
option :enroll, type: :boolean, default: false,
|
54
|
+
desc: "Enrolls project in credential file diffing with `git diff`"
|
55
|
+
|
56
|
+
def diff(content_path = nil)
|
57
|
+
if @content_path = content_path
|
58
|
+
extract_environment_option_from_argument(default_environment: extract_environment_from_path(content_path))
|
59
|
+
require_application!
|
60
|
+
|
61
|
+
say credentials.read.presence || credentials.content_path.read
|
62
|
+
else
|
63
|
+
require_application!
|
64
|
+
enroll_project_in_credentials_diffing if options[:enroll]
|
65
|
+
end
|
66
|
+
rescue ActiveSupport::MessageEncryptor::InvalidMessage
|
67
|
+
say credentials.content_path.read
|
68
|
+
end
|
69
|
+
|
48
70
|
private
|
49
71
|
def credentials
|
50
72
|
Rails.application.encrypted(content_path, key_path: key_path)
|
@@ -71,21 +93,23 @@ module Rails
|
|
71
93
|
|
72
94
|
def missing_credentials_message
|
73
95
|
if credentials.key.nil?
|
74
|
-
"Missing '#{key_path}' to decrypt credentials. See `rails credentials:help`"
|
96
|
+
"Missing '#{key_path}' to decrypt credentials. See `bin/rails credentials:help`"
|
75
97
|
else
|
76
|
-
"File '#{content_path}' does not exist. Use `rails credentials:edit` to change that."
|
98
|
+
"File '#{content_path}' does not exist. Use `bin/rails credentials:edit` to change that."
|
77
99
|
end
|
78
100
|
end
|
79
101
|
|
80
|
-
|
81
102
|
def content_path
|
82
|
-
options[:environment] ? "config/credentials/#{options[:environment]}.yml.enc" : "config/credentials.yml.enc"
|
103
|
+
@content_path ||= options[:environment] ? "config/credentials/#{options[:environment]}.yml.enc" : "config/credentials.yml.enc"
|
83
104
|
end
|
84
105
|
|
85
106
|
def key_path
|
86
107
|
options[:environment] ? "config/credentials/#{options[:environment]}.key" : "config/master.key"
|
87
108
|
end
|
88
109
|
|
110
|
+
def extract_environment_from_path(path)
|
111
|
+
available_environments.find { |env| path.include? env } if path.end_with?(".yml.enc")
|
112
|
+
end
|
89
113
|
|
90
114
|
def encryption_key_file_generator
|
91
115
|
require "rails/generators"
|
@@ -10,8 +10,13 @@ module Rails
|
|
10
10
|
class ChangeCommand < Base # :nodoc:
|
11
11
|
class_option :to, desc: "The database system to switch to."
|
12
12
|
|
13
|
+
def initialize(positional_args, option_args, *)
|
14
|
+
@argv = positional_args + option_args
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
13
18
|
def perform
|
14
|
-
Rails::Generators::Db::System::ChangeGenerator.start
|
19
|
+
Rails::Generators::Db::System::ChangeGenerator.start(@argv)
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_support/deprecation"
|
4
3
|
require "active_support/core_ext/string/filters"
|
4
|
+
require "active_support/deprecation"
|
5
5
|
require "rails/command/environment_argument"
|
6
6
|
|
7
7
|
module Rails
|
@@ -16,55 +16,56 @@ module Rails
|
|
16
16
|
|
17
17
|
def start
|
18
18
|
ENV["RAILS_ENV"] ||= @options[:environment] || environment
|
19
|
+
config = db_config.configuration_hash
|
19
20
|
|
20
|
-
case
|
21
|
+
case db_config.adapter
|
21
22
|
when /^(jdbc)?mysql/
|
22
23
|
args = {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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"
|
33
34
|
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
|
34
35
|
|
35
|
-
if config[
|
36
|
-
args << "--password=#{config[
|
37
|
-
elsif config[
|
36
|
+
if config[:password] && @options[:include_password]
|
37
|
+
args << "--password=#{config[:password]}"
|
38
|
+
elsif config[:password] && !config[:password].to_s.empty?
|
38
39
|
args << "-p"
|
39
40
|
end
|
40
41
|
|
41
|
-
args <<
|
42
|
+
args << db_config.database
|
42
43
|
|
43
44
|
find_cmd_and_exec(["mysql", "mysql5"], *args)
|
44
45
|
|
45
46
|
when /^postgres|^postgis/
|
46
|
-
ENV["PGUSER"] = config[
|
47
|
-
ENV["PGHOST"] = config[
|
48
|
-
ENV["PGPORT"] = config[
|
49
|
-
ENV["PGPASSWORD"] = config[
|
50
|
-
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)
|
51
52
|
|
52
53
|
when "sqlite3"
|
53
54
|
args = []
|
54
55
|
|
55
|
-
args << "-#{@options[
|
56
|
-
args << "-header" if @options[
|
57
|
-
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)
|
58
59
|
|
59
60
|
find_cmd_and_exec("sqlite3", *args)
|
60
61
|
|
61
62
|
when "oracle", "oracle_enhanced"
|
62
63
|
logon = ""
|
63
64
|
|
64
|
-
if config[
|
65
|
-
logon = config[
|
66
|
-
logon << "/#{config[
|
67
|
-
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
|
68
69
|
end
|
69
70
|
|
70
71
|
find_cmd_and_exec("sqlplus", logon)
|
@@ -72,36 +73,43 @@ module Rails
|
|
72
73
|
when "sqlserver"
|
73
74
|
args = []
|
74
75
|
|
75
|
-
args += ["-
|
76
|
-
args += ["-U", "#{config[
|
77
|
-
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]
|
78
79
|
|
79
|
-
if config[
|
80
|
-
host_arg = +"
|
81
|
-
host_arg << "
|
80
|
+
if config[:host]
|
81
|
+
host_arg = +"tcp:#{config[:host]}"
|
82
|
+
host_arg << ",#{config[:port]}" if config[:port]
|
82
83
|
args += ["-S", host_arg]
|
83
84
|
end
|
84
85
|
|
85
|
-
find_cmd_and_exec("
|
86
|
+
find_cmd_and_exec("sqlcmd", *args)
|
86
87
|
|
87
88
|
else
|
88
|
-
abort "Unknown command-line client for #{
|
89
|
+
abort "Unknown command-line client for #{db_config.database}."
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
92
93
|
def config
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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}"
|
104
110
|
end
|
111
|
+
|
112
|
+
@db_config
|
105
113
|
end
|
106
114
|
|
107
115
|
def environment
|
@@ -131,7 +139,12 @@ module Rails
|
|
131
139
|
found = commands.detect do |cmd|
|
132
140
|
dirs_on_path.detect do |path|
|
133
141
|
full_path_command = File.join(path, cmd)
|
134
|
-
|
142
|
+
begin
|
143
|
+
stat = File.stat(full_path_command)
|
144
|
+
rescue SystemCallError
|
145
|
+
else
|
146
|
+
stat.file? && stat.executable?
|
147
|
+
end
|
135
148
|
end
|
136
149
|
end
|
137
150
|
|
@@ -155,9 +168,6 @@ module Rails
|
|
155
168
|
|
156
169
|
class_option :header, type: :boolean
|
157
170
|
|
158
|
-
class_option :connection, aliases: "-c", type: :string,
|
159
|
-
desc: "Specifies the connection to use."
|
160
|
-
|
161
171
|
class_option :database, aliases: "--db", type: :string,
|
162
172
|
desc: "Specifies the database to use."
|
163
173
|
|
@@ -167,13 +177,6 @@ module Rails
|
|
167
177
|
# RAILS_ENV needs to be set before config/application is required.
|
168
178
|
ENV["RAILS_ENV"] = options[:environment]
|
169
179
|
|
170
|
-
if options["connection"]
|
171
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
172
|
-
`connection` option is deprecated and will be removed in Rails 6.1. Please use `database` option instead.
|
173
|
-
MSG
|
174
|
-
options["database"] = options["connection"]
|
175
|
-
end
|
176
|
-
|
177
180
|
require_application_and_environment!
|
178
181
|
Rails::DBConsole.start(options)
|
179
182
|
end
|
@@ -21,7 +21,7 @@ module Rails
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def edit(file_path)
|
24
|
-
|
24
|
+
require_application!
|
25
25
|
encrypted = Rails.application.encrypted(file_path, key_path: options[:key])
|
26
26
|
|
27
27
|
ensure_editor_available(command: "bin/rails encrypted:edit") || (return)
|
@@ -38,7 +38,7 @@ module Rails
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def show(file_path)
|
41
|
-
|
41
|
+
require_application!
|
42
42
|
encrypted = Rails.application.encrypted(file_path, key_path: options[:key])
|
43
43
|
|
44
44
|
say encrypted.read.presence || missing_encrypted_message(key: encrypted.key, key_path: options[:key], file_path: file_path)
|
@@ -77,9 +77,9 @@ module Rails
|
|
77
77
|
|
78
78
|
def missing_encrypted_message(key:, key_path:, file_path:)
|
79
79
|
if key.nil?
|
80
|
-
"Missing '#{key_path}' to decrypt data. See `rails encrypted:help`"
|
80
|
+
"Missing '#{key_path}' to decrypt data. See `bin/rails encrypted:help`"
|
81
81
|
else
|
82
|
-
"File '#{file_path}' does not exist. Use `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."
|
83
83
|
end
|
84
84
|
end
|
85
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
|
@@ -5,34 +5,24 @@ require "rails/source_annotation_extractor"
|
|
5
5
|
module Rails
|
6
6
|
module Command
|
7
7
|
class NotesCommand < Base # :nodoc:
|
8
|
-
class_option :annotations, aliases: "-a", desc: "Filter by specific annotations, e.g. Foobar TODO", type: :array
|
8
|
+
class_option :annotations, aliases: "-a", desc: "Filter by specific annotations, e.g. Foobar TODO", type: :array, default: Rails::SourceAnnotationExtractor::Annotation.tags
|
9
9
|
|
10
10
|
def perform(*)
|
11
11
|
require_application_and_environment!
|
12
12
|
|
13
|
-
deprecation_warning
|
14
13
|
display_annotations
|
15
14
|
end
|
16
15
|
|
17
16
|
private
|
18
17
|
def display_annotations
|
19
|
-
annotations = options[:annotations]
|
18
|
+
annotations = options[:annotations]
|
20
19
|
tag = (annotations.length > 1)
|
21
20
|
|
22
21
|
Rails::SourceAnnotationExtractor.enumerate annotations.join("|"), tag: tag, dirs: directories
|
23
22
|
end
|
24
23
|
|
25
24
|
def directories
|
26
|
-
Rails::SourceAnnotationExtractor::Annotation.directories
|
27
|
-
end
|
28
|
-
|
29
|
-
def deprecation_warning
|
30
|
-
return if source_annotation_directories.empty?
|
31
|
-
ActiveSupport::Deprecation.warn("`SOURCE_ANNOTATION_DIRECTORIES` is deprecated and will be removed in Rails 6.1. You can add default directories by using config.annotations.register_directories instead.")
|
32
|
-
end
|
33
|
-
|
34
|
-
def source_annotation_directories
|
35
|
-
ENV["SOURCE_ANNOTATION_DIRECTORIES"].to_s.split(",")
|
25
|
+
Rails::SourceAnnotationExtractor::Annotation.directories
|
36
26
|
end
|
37
27
|
end
|
38
28
|
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")
|
@@ -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
|
@@ -7,7 +13,7 @@ with the code.
|
|
7
13
|
|
8
14
|
=== Setup
|
9
15
|
|
10
|
-
Run `rails secrets:setup` to opt in and generate the `config/secrets.yml.key`
|
16
|
+
Run `bin/rails secrets:setup` to opt in and generate the `config/secrets.yml.key`
|
11
17
|
and `config/secrets.yml.enc` files.
|
12
18
|
|
13
19
|
The latter contains all the keys to be encrypted while the former holds the
|
@@ -45,12 +51,12 @@ the key. Add this:
|
|
45
51
|
|
46
52
|
config.read_encrypted_secrets = true
|
47
53
|
|
48
|
-
to the environment you'd like to read encrypted secrets. `rails secrets:setup`
|
54
|
+
to the environment you'd like to read encrypted secrets. `bin/rails secrets:setup`
|
49
55
|
inserts this into the production environment by default.
|
50
56
|
|
51
57
|
=== Editing Secrets
|
52
58
|
|
53
|
-
After `rails secrets:setup`, run `rails secrets:edit`.
|
59
|
+
After `bin/rails secrets:setup`, run `bin/rails secrets:edit`.
|
54
60
|
|
55
61
|
That command opens a temporary file in `$EDITOR` with the decrypted contents of
|
56
62
|
`config/secrets.yml.enc` to edit the encrypted secrets.
|