railties 6.1.6 → 7.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +93 -412
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +16 -16
  5. data/README.rdoc +0 -1
  6. data/lib/rails/app_updater.rb +2 -4
  7. data/lib/rails/application/bootstrap.rb +17 -5
  8. data/lib/rails/application/configuration.rb +52 -31
  9. data/lib/rails/application/default_middleware_stack.rb +6 -3
  10. data/lib/rails/application/finisher.rb +43 -85
  11. data/lib/rails/application/routes_reloader.rb +8 -0
  12. data/lib/rails/application.rb +24 -50
  13. data/lib/rails/application_controller.rb +2 -2
  14. data/lib/rails/autoloaders/inflector.rb +21 -0
  15. data/lib/rails/autoloaders.rb +12 -16
  16. data/lib/rails/code_statistics.rb +2 -2
  17. data/lib/rails/code_statistics_calculator.rb +10 -1
  18. data/lib/rails/command/base.rb +26 -12
  19. data/lib/rails/command/behavior.rb +1 -1
  20. data/lib/rails/command/environment_argument.rb +1 -1
  21. data/lib/rails/command.rb +8 -5
  22. data/lib/rails/commands/credentials/USAGE +4 -2
  23. data/lib/rails/commands/credentials/credentials_command/diffing.rb +26 -16
  24. data/lib/rails/commands/credentials/credentials_command.rb +6 -2
  25. data/lib/rails/commands/dbconsole/dbconsole_command.rb +16 -15
  26. data/lib/rails/commands/help/USAGE +3 -2
  27. data/lib/rails/commands/runner/runner_command.rb +3 -2
  28. data/lib/rails/commands/server/server_command.rb +2 -5
  29. data/lib/rails/configuration.rb +18 -23
  30. data/lib/rails/engine/configuration.rb +2 -2
  31. data/lib/rails/engine.rb +23 -27
  32. data/lib/rails/gem_version.rb +4 -4
  33. data/lib/rails/generators/actions/create_migration.rb +2 -4
  34. data/lib/rails/generators/actions.rb +35 -13
  35. data/lib/rails/generators/app_base.rb +66 -102
  36. data/lib/rails/generators/app_name.rb +1 -1
  37. data/lib/rails/generators/base.rb +9 -13
  38. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
  39. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
  40. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +5 -27
  41. data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
  42. data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +20 -0
  43. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +7 -16
  44. data/lib/rails/generators/erb.rb +1 -1
  45. data/lib/rails/generators/generated_attribute.rb +40 -4
  46. data/lib/rails/generators/migration.rb +2 -6
  47. data/lib/rails/generators/model_helpers.rb +1 -1
  48. data/lib/rails/generators/named_base.rb +1 -1
  49. data/lib/rails/generators/rails/app/app_generator.rb +44 -88
  50. data/lib/rails/generators/rails/app/templates/Gemfile.tt +41 -52
  51. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +2 -2
  52. data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +2 -2
  53. data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +1 -1
  54. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +3 -10
  55. data/lib/rails/generators/rails/app/templates/bin/rails.tt +1 -4
  56. data/lib/rails/generators/rails/app/templates/bin/rake.tt +0 -3
  57. data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -14
  58. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +1 -1
  59. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
  60. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
  61. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
  62. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +2 -2
  63. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
  64. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
  65. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +3 -3
  66. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
  67. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +5 -5
  68. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -11
  69. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +9 -15
  70. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +2 -7
  71. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -5
  72. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +0 -5
  73. data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +2 -2
  74. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +4 -4
  75. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +85 -0
  76. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +3 -3
  77. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +1 -1
  78. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +3 -0
  79. data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
  80. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +2 -2
  81. data/lib/rails/generators/rails/app/templates/gitattributes.tt +0 -5
  82. data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
  83. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
  84. data/lib/rails/generators/rails/controller/controller_generator.rb +1 -2
  85. data/lib/rails/generators/rails/controller/templates/controller.rb.tt +0 -4
  86. data/lib/rails/generators/rails/db/system/change/change_generator.rb +1 -1
  87. data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
  88. data/lib/rails/generators/rails/plugin/plugin_generator.rb +40 -15
  89. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +4 -2
  90. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +9 -9
  91. data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
  92. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +2 -2
  93. data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
  94. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
  95. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +4 -4
  96. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -5
  97. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +2 -2
  98. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -1
  99. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +2 -2
  100. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +3 -3
  101. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +0 -19
  102. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -5
  103. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +6 -10
  104. data/lib/rails/generators/resource_helpers.rb +2 -2
  105. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +1 -1
  106. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
  107. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
  108. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +5 -5
  109. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +2 -2
  110. data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +3 -3
  111. data/lib/rails/generators/testing/behaviour.rb +1 -2
  112. data/lib/rails/generators.rb +9 -22
  113. data/lib/rails/info.rb +1 -1
  114. data/lib/rails/info_controller.rb +1 -3
  115. data/lib/rails/initializable.rb +1 -1
  116. data/lib/rails/mailers_controller.rb +2 -4
  117. data/lib/rails/rack/logger.rb +0 -1
  118. data/lib/rails/railtie/configuration.rb +1 -2
  119. data/lib/rails/railtie.rb +9 -9
  120. data/lib/rails/ruby_version_check.rb +3 -3
  121. data/lib/rails/tasks/framework.rake +2 -8
  122. data/lib/rails/tasks/statistics.rake +3 -1
  123. data/lib/rails/tasks/tmp.rake +8 -1
  124. data/lib/rails/tasks/yarn.rake +5 -1
  125. data/lib/rails/tasks/zeitwerk.rake +2 -10
  126. data/lib/rails/templates/layouts/application.html.erb +15 -0
  127. data/lib/rails/templates/rails/mailers/email.html.erb +12 -10
  128. data/lib/rails/templates/rails/welcome/index.html.erb +3 -0
  129. data/lib/rails/test_unit/railtie.rb +0 -4
  130. data/lib/rails/test_unit/runner.rb +7 -5
  131. data/lib/rails/test_unit/testing.rake +4 -9
  132. data/lib/rails.rb +1 -0
  133. metadata +37 -40
  134. data/lib/rails/.DS_Store +0 -0
  135. data/lib/rails/command/spellchecker.rb +0 -57
  136. data/lib/rails/generators/css/assets/assets_generator.rb +0 -15
  137. data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
  138. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -18
  139. data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +0 -6
  140. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +0 -5
  141. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +0 -23
  142. data/lib/rails/generators/rails/app/templates/bin/spring.tt +0 -13
  143. data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -16
  144. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb.tt +0 -8
  145. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb.tt +0 -5
  146. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -67
  147. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +0 -6
  148. data/lib/rails/generators/rails/app/templates/package.json.tt +0 -11
  149. data/lib/rails/generators/rails/assets/USAGE +0 -16
  150. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -26
  151. data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
  152. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
@@ -7,8 +7,8 @@ class Rails::ApplicationController < ActionController::Base # :nodoc:
7
7
  before_action :disable_content_security_policy_nonce!
8
8
 
9
9
  content_security_policy do |policy|
10
- policy.script_src :unsafe_inline
11
- policy.style_src :unsafe_inline
10
+ policy.script_src :self, :unsafe_inline
11
+ policy.style_src :self, :unsafe_inline
12
12
  end
13
13
 
14
14
  private
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/inflector"
4
+
5
+ module Rails
6
+ module Autoloaders
7
+ module Inflector # :nodoc:
8
+ # Concurrent::Map is not needed. This is a private class, and overrides
9
+ # must be defined while the application boots.
10
+ @overrides = {}
11
+
12
+ def self.camelize(basename, _abspath)
13
+ @overrides[basename] || basename.camelize
14
+ end
15
+
16
+ def self.inflect(overrides)
17
+ @overrides.merge!(overrides)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,35 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/dependencies/zeitwerk_integration"
3
+ require "zeitwerk"
4
4
 
5
5
  module Rails
6
6
  module Autoloaders # :nodoc:
7
+ require_relative "autoloaders/inflector"
8
+
7
9
  class << self
8
10
  include Enumerable
9
11
 
10
12
  def main
11
- if zeitwerk_enabled?
12
- @main ||= Zeitwerk::Loader.new.tap do |loader|
13
- loader.tag = "rails.main"
14
- loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
15
- end
13
+ @main ||= Zeitwerk::Loader.new.tap do |loader|
14
+ loader.tag = "rails.main"
15
+ loader.inflector = Inflector
16
16
  end
17
17
  end
18
18
 
19
19
  def once
20
- if zeitwerk_enabled?
21
- @once ||= Zeitwerk::Loader.new.tap do |loader|
22
- loader.tag = "rails.once"
23
- loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
24
- end
20
+ @once ||= Zeitwerk::Loader.new.tap do |loader|
21
+ loader.tag = "rails.once"
22
+ loader.inflector = Inflector
25
23
  end
26
24
  end
27
25
 
28
26
  def each
29
- if zeitwerk_enabled?
30
- yield main
31
- yield once
32
- end
27
+ yield main
28
+ yield once
33
29
  end
34
30
 
35
31
  def logger=(logger)
@@ -41,7 +37,7 @@ module Rails
41
37
  end
42
38
 
43
39
  def zeitwerk_enabled?
44
- Rails.configuration.autoloader == :zeitwerk
40
+ true
45
41
  end
46
42
  end
47
43
  end
@@ -3,7 +3,7 @@
3
3
  require "rails/code_statistics_calculator"
4
4
  require "active_support/core_ext/enumerable"
5
5
 
6
- class CodeStatistics #:nodoc:
6
+ class CodeStatistics # :nodoc:
7
7
  TEST_TYPES = ["Controller tests",
8
8
  "Helper tests",
9
9
  "Model tests",
@@ -40,7 +40,7 @@ class CodeStatistics #:nodoc:
40
40
  Hash[@pairs.map { |pair| [pair.first, calculate_directory_statistics(pair.last)] }]
41
41
  end
42
42
 
43
- def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|ts|coffee|rake)$/)
43
+ def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|ts|css|scss|coffee|rake|erb)$/)
44
44
  stats = CodeStatisticsCalculator.new
45
45
 
46
46
  Dir.foreach(directory) do |file_name|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class CodeStatisticsCalculator #:nodoc:
3
+ class CodeStatisticsCalculator # :nodoc:
4
4
  attr_reader :lines, :code_lines, :classes, :methods
5
5
 
6
6
  PATTERNS = {
@@ -11,6 +11,15 @@ class CodeStatisticsCalculator #:nodoc:
11
11
  class: /^\s*class\s+[_A-Z]/,
12
12
  method: /^\s*def\s+[_a-z]/,
13
13
  },
14
+ erb: {
15
+ line_comment: %r{((^\s*<%#.*%>)|(<!--.*-->))},
16
+ },
17
+ css: {
18
+ line_comment: %r{^\s*/\*.*\*/},
19
+ },
20
+ scss: {
21
+ line_comment: %r{((^\s*/\*.*\*/)|(^\s*//))},
22
+ },
14
23
  js: {
15
24
  line_comment: %r{^\s*//},
16
25
  begin_block_comment: %r{^\s*/\*},
@@ -14,6 +14,24 @@ module Rails
14
14
  class Error < Thor::Error # :nodoc:
15
15
  end
16
16
 
17
+ class CorrectableError < Error # :nodoc:
18
+ attr_reader :key, :options
19
+
20
+ def initialize(message, key, options)
21
+ @key = key
22
+ @options = options
23
+ super(message)
24
+ end
25
+
26
+ if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable)
27
+ include DidYouMean::Correctable
28
+
29
+ def corrections
30
+ @corrections ||= DidYouMean::SpellChecker.new(dictionary: options).correct(key)
31
+ end
32
+ end
33
+ end
34
+
17
35
  include Actions
18
36
 
19
37
  class << self
@@ -32,7 +50,7 @@ module Rails
32
50
  if usage
33
51
  super
34
52
  else
35
- @desc ||= ERB.new(File.read(usage_path)).result(binding) if usage_path
53
+ @desc ||= ERB.new(File.read(usage_path), trim_mode: "-").result(binding) if usage_path
36
54
  end
37
55
  end
38
56
 
@@ -53,7 +71,7 @@ module Rails
53
71
  Rails::Command.hidden_commands << self
54
72
  end
55
73
 
56
- def inherited(base) #:nodoc:
74
+ def inherited(base) # :nodoc:
57
75
  super
58
76
 
59
77
  if base.name && !base.name.end_with?("Base")
@@ -86,10 +104,8 @@ module Rails
86
104
  #
87
105
  # Rails::Command::TestCommand.base_name # => 'rails'
88
106
  def base_name
89
- @base_name ||= begin
90
- if base = name.to_s.split("::").first
91
- base.underscore
92
- end
107
+ @base_name ||= if base = name.to_s.split("::").first
108
+ base.underscore
93
109
  end
94
110
  end
95
111
 
@@ -97,11 +113,9 @@ module Rails
97
113
  #
98
114
  # Rails::Command::TestCommand.command_name # => 'test'
99
115
  def command_name
100
- @command_name ||= begin
101
- if command = name.to_s.split("::").last
102
- command.chomp!("Command")
103
- command.underscore
104
- end
116
+ @command_name ||= if command = name.to_s.split("::").last
117
+ command.chomp!("Command")
118
+ command.underscore
105
119
  end
106
120
  end
107
121
 
@@ -148,7 +162,7 @@ module Rails
148
162
 
149
163
  def namespaced_commands
150
164
  commands.keys.map do |key|
151
- if command_root_namespace.match?(/(\A|\:)#{key}\z/)
165
+ if command_root_namespace.match?(/(\A|:)#{key}\z/)
152
166
  command_root_namespace
153
167
  else
154
168
  "#{command_root_namespace}:#{key}"
@@ -4,7 +4,7 @@ require "active_support"
4
4
 
5
5
  module Rails
6
6
  module Command
7
- module Behavior #:nodoc:
7
+ module Behavior # :nodoc:
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  class_methods do
@@ -5,7 +5,7 @@ require "active_support/core_ext/class/attribute"
5
5
 
6
6
  module Rails
7
7
  module Command
8
- module EnvironmentArgument #:nodoc:
8
+ module EnvironmentArgument # :nodoc:
9
9
  extend ActiveSupport::Concern
10
10
 
11
11
  included do
data/lib/rails/command.rb CHANGED
@@ -10,7 +10,6 @@ module Rails
10
10
  module Command
11
11
  extend ActiveSupport::Autoload
12
12
 
13
- autoload :Spellchecker
14
13
  autoload :Behavior
15
14
  autoload :Base
16
15
 
@@ -38,6 +37,7 @@ module Rails
38
37
  end
39
38
 
40
39
  command_name, namespace = "help", "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name)
40
+ command_name, namespace, args = "application", "application", ["--help"] if rails_new_with_no_path?(args)
41
41
  command_name, namespace = "version", "version" if %w( -v --version ).include?(command_name)
42
42
 
43
43
  original_argv = ARGV.dup
@@ -47,6 +47,7 @@ module Rails
47
47
  if command && command.all_commands[command_name]
48
48
  command.perform(command_name, args, config)
49
49
  else
50
+ args = ["--describe", full_namespace] if HELP_MAPPINGS.include?(args[0])
50
51
  find_by_namespace("rake").perform(full_namespace, args, config)
51
52
  end
52
53
  ensure
@@ -58,14 +59,12 @@ module Rails
58
59
  # Command names must end with "_command.rb". This is required because Rails
59
60
  # looks in load paths and loads the command just before it's going to be used.
60
61
  #
61
- # find_by_namespace :webrat, :rails, :integration
62
+ # find_by_namespace :webrat, :integration
62
63
  #
63
64
  # Will search for the following commands:
64
65
  #
65
- # "rails:webrat", "webrat:integration", "webrat"
66
+ # "webrat", "webrat:integration", "rails:webrat", "rails:webrat:integration"
66
67
  #
67
- # Notice that "rails:commands:webrat" could be loaded as well, what
68
- # Rails looks for is the first and last parts of the namespace.
69
68
  def find_by_namespace(namespace, command_name = nil) # :nodoc:
70
69
  lookups = [ namespace ]
71
70
  lookups << "#{namespace}:#{command_name}" if command_name
@@ -94,6 +93,10 @@ module Rails
94
93
  COMMANDS_IN_USAGE = %w(generate console server test test:system dbconsole new)
95
94
  private_constant :COMMANDS_IN_USAGE
96
95
 
96
+ def rails_new_with_no_path?(args)
97
+ args == ["new"]
98
+ end
99
+
97
100
  def commands
98
101
  lookup!
99
102
 
@@ -32,8 +32,8 @@ You could prepend that to your server's start command like this:
32
32
 
33
33
  === Set up Git to Diff Credentials
34
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.
35
+ Rails provides `bin/rails credentials:diff --enroll` to instruct Git to call
36
+ `bin/rails credentials:diff` when `git diff` is run on a credentials file.
37
37
 
38
38
  Running the command enrolls the project such that all credentials files use the
39
39
  "rails_credentials" diff driver in .gitattributes.
@@ -45,6 +45,8 @@ that isn't tracked Rails automatically ensures it's configured when running
45
45
  Otherwise each co-worker would have to run enable manually, including on each new
46
46
  repo clone.
47
47
 
48
+ To disenroll from this feature, run `bin/rails credentials:diff --disenroll`.
49
+
48
50
  === Editing Credentials
49
51
 
50
52
  This will open a temporary file in `$EDITOR` with the decrypted contents to edit
@@ -1,37 +1,47 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rails::Command::CredentialsCommand::Diffing # :nodoc:
4
+ GITATTRIBUTES_ENTRY = <<~END
5
+ config/credentials/*.yml.enc diff=rails_credentials
6
+ config/credentials.yml.enc diff=rails_credentials
7
+ END
8
+
4
9
  def enroll_project_in_credentials_diffing
5
- if enrolled?
6
- true
10
+ if enrolled_in_credentials_diffing?
11
+ say "Project is already enrolled in credentials file diffing."
7
12
  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
13
+ gitattributes.write(GITATTRIBUTES_ENTRY, mode: "a")
12
14
 
13
- say "Project successfully enrolled!"
15
+ say "Enrolled project in credentials file diffing!"
14
16
  say "Rails ensures the rails_credentials diff driver is set when running `credentials:edit`. See `credentials:help` for more."
15
17
  end
16
18
  end
17
19
 
18
- def ensure_rails_credentials_driver_is_set
19
- set_driver if enrolled? && !driver_configured?
20
+ def disenroll_project_from_credentials_diffing
21
+ if enrolled_in_credentials_diffing?
22
+ gitattributes.write(gitattributes.read.gsub(GITATTRIBUTES_ENTRY, ""))
23
+ gitattributes.delete if gitattributes.empty?
24
+
25
+ say "Disenrolled project from credentials file diffing!"
26
+ else
27
+ say "Project is not enrolled in credentials file diffing."
28
+ end
29
+ end
30
+
31
+ def ensure_diffing_driver_is_configured
32
+ configure_diffing_driver if enrolled_in_credentials_diffing? && !diffing_driver_configured?
20
33
  end
21
34
 
22
35
  private
23
- def enrolled?
24
- gitattributes.read.match?(/config\/credentials(\/\*)?\.yml\.enc diff=rails_credentials/)
25
- rescue Errno::ENOENT
26
- false
36
+ def enrolled_in_credentials_diffing?
37
+ gitattributes.file? && gitattributes.read.include?(GITATTRIBUTES_ENTRY)
27
38
  end
28
39
 
29
- def driver_configured?
40
+ def diffing_driver_configured?
30
41
  system "git config --get diff.rails_credentials.textconv", out: File::NULL
31
42
  end
32
43
 
33
- def set_driver
34
- puts "running"
44
+ def configure_diffing_driver
35
45
  system "git config diff.rails_credentials.textconv 'bin/rails credentials:diff'"
36
46
  end
37
47
 
@@ -33,7 +33,7 @@ module Rails
33
33
 
34
34
  ensure_encryption_key_has_been_added if credentials.key.nil?
35
35
  ensure_credentials_have_been_added
36
- ensure_rails_credentials_driver_is_set
36
+ ensure_diffing_driver_is_configured
37
37
 
38
38
  catch_editing_exceptions do
39
39
  change_credentials_in_system_editor
@@ -52,7 +52,10 @@ module Rails
52
52
  end
53
53
 
54
54
  option :enroll, type: :boolean, default: false,
55
- desc: "Enrolls project in credential file diffing with `git diff`"
55
+ desc: "Enrolls project in credentials file diffing with `git diff`"
56
+
57
+ option :disenroll, type: :boolean, default: false,
58
+ desc: "Disenrolls project from credentials file diffing"
56
59
 
57
60
  def diff(content_path = nil)
58
61
  if @content_path = content_path
@@ -62,6 +65,7 @@ module Rails
62
65
  say credentials.read.presence || credentials.content_path.read
63
66
  else
64
67
  require_application!
68
+ disenroll_project_from_credentials_diffing if options[:disenroll]
65
69
  enroll_project_in_credentials_diffing if options[:enroll]
66
70
  end
67
71
  rescue ActiveSupport::MessageEncryptor::InvalidMessage
@@ -31,7 +31,7 @@ module Rails
31
31
  sslcapath: "--ssl-capath",
32
32
  sslcipher: "--ssl-cipher",
33
33
  sslkey: "--ssl-key"
34
- }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
34
+ }.filter_map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }
35
35
 
36
36
  if config[:password] && @options[:include_password]
37
37
  args << "--password=#{config[:password]}"
@@ -44,10 +44,14 @@ module Rails
44
44
  find_cmd_and_exec(["mysql", "mysql5"], *args)
45
45
 
46
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]
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]
51
55
  find_cmd_and_exec("psql", db_config.database)
52
56
 
53
57
  when "sqlite3"
@@ -98,18 +102,15 @@ module Rails
98
102
  def db_config
99
103
  return @db_config if defined?(@db_config)
100
104
 
101
- # If the user provided a database, use that. Otherwise find
102
- # the first config in the database.yml
103
- if database
104
- @db_config = configurations.configs_for(env_name: environment, name: database, include_replicas: true)
105
- else
106
- @db_config = configurations.find_db_config(environment)
107
- end
105
+ # We need to check whether the user passed the database the
106
+ # first time around to show a consistent error message to people
107
+ # relying on 2-level database configuration.
108
+
109
+ @db_config = configurations.configs_for(env_name: environment, name: database, include_hidden: true)
108
110
 
109
111
  unless @db_config
110
- missing_db = database ? "'#{database}' database is not" : "No databases are"
111
112
  raise ActiveRecord::AdapterNotSpecified,
112
- "#{missing_db} configured for '#{environment}'. Available configuration: #{configurations.inspect}"
113
+ "'#{database}' database is not configured for '#{environment}'. Available configuration: #{configurations.inspect}"
113
114
  end
114
115
 
115
116
  @db_config
@@ -120,7 +121,7 @@ module Rails
120
121
  end
121
122
 
122
123
  def database
123
- @options[:database]
124
+ @options.fetch(:database, "primary")
124
125
  end
125
126
 
126
127
  private
@@ -6,10 +6,11 @@ The most common rails commands are:
6
6
  test:system Run system tests
7
7
  dbconsole Start a console for the database specified in config/database.yml
8
8
  (short-cut alias: "db")
9
- <% unless engine? %>
9
+ <% unless engine? -%>
10
10
  new Create a new Rails application. "rails new my_app" creates a
11
11
  new application called MyApp in "./my_app"
12
- <% end %>
12
+ plugin new Create a new Rails railtie or engine
13
+ <% end -%>
13
14
 
14
15
  All commands can be run with -h (or --help) for more information.
15
16
  In addition to those commands, there are:
@@ -38,8 +38,9 @@ module Rails
38
38
  if code_or_file == "-"
39
39
  eval($stdin.read, TOPLEVEL_BINDING, "stdin")
40
40
  elsif File.exist?(code_or_file)
41
- $0 = code_or_file
42
- Kernel.load code_or_file
41
+ expanded_file_path = File.expand_path code_or_file
42
+ $0 = expanded_file_path
43
+ Kernel.load expanded_file_path
43
44
  else
44
45
  begin
45
46
  eval(code_or_file, TOPLEVEL_BINDING, __FILE__, __LINE__)
@@ -4,7 +4,6 @@ require "fileutils"
4
4
  require "action_dispatch"
5
5
  require "rails"
6
6
  require "active_support/core_ext/string/filters"
7
- require "active_support/core_ext/symbol/starts_ends_with"
8
7
  require "rails/dev_caching"
9
8
  require "rails/command/environment_argument"
10
9
 
@@ -263,11 +262,9 @@ module Rails
263
262
  Run `bin/rails server --help` for more options.
264
263
  MSG
265
264
  else
266
- suggestion = Rails::Command::Spellchecker.suggest(server, from: RACK_SERVERS)
267
- suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
268
-
265
+ error = CorrectableError.new("Could not find server '#{server}'.", server, RACK_SERVERS)
269
266
  <<~MSG
270
- Could not find server "#{server}". #{suggestion_msg}
267
+ #{error.message}
271
268
  Run `bin/rails server --help` for more options.
272
269
  MSG
273
270
  end
@@ -49,48 +49,43 @@ module Rails
49
49
  @delete_operations = delete_operations
50
50
  end
51
51
 
52
- def insert_before(*args, &block)
53
- @operations << -> middleware { middleware.insert_before(*args, &block) }
52
+ def insert_before(...)
53
+ @operations << -> middleware { middleware.insert_before(...) }
54
54
  end
55
- ruby2_keywords(:insert_before) if respond_to?(:ruby2_keywords, true)
56
55
 
57
56
  alias :insert :insert_before
58
57
 
59
- def insert_after(*args, &block)
60
- @operations << -> middleware { middleware.insert_after(*args, &block) }
58
+ def insert_after(...)
59
+ @operations << -> middleware { middleware.insert_after(...) }
61
60
  end
62
- ruby2_keywords(:insert_after) if respond_to?(:ruby2_keywords, true)
63
61
 
64
- def swap(*args, &block)
65
- @operations << -> middleware { middleware.swap(*args, &block) }
62
+ def swap(...)
63
+ @operations << -> middleware { middleware.swap(...) }
66
64
  end
67
- ruby2_keywords(:swap) if respond_to?(:ruby2_keywords, true)
68
65
 
69
- def use(*args, &block)
70
- @operations << -> middleware { middleware.use(*args, &block) }
66
+ def use(...)
67
+ @operations << -> middleware { middleware.use(...) }
71
68
  end
72
- ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
73
69
 
74
- def delete(*args, &block)
75
- @delete_operations << -> middleware { middleware.delete(*args, &block) }
70
+ def delete(...)
71
+ @delete_operations << -> middleware { middleware.delete(...) }
76
72
  end
77
73
 
78
- def move_before(*args, &block)
79
- @delete_operations << -> middleware { middleware.move_before(*args, &block) }
74
+ def move_before(...)
75
+ @delete_operations << -> middleware { middleware.move_before(...) }
80
76
  end
81
77
 
82
78
  alias :move :move_before
83
79
 
84
- def move_after(*args, &block)
85
- @delete_operations << -> middleware { middleware.move_after(*args, &block) }
80
+ def move_after(...)
81
+ @delete_operations << -> middleware { middleware.move_after(...) }
86
82
  end
87
83
 
88
- def unshift(*args, &block)
89
- @operations << -> middleware { middleware.unshift(*args, &block) }
84
+ def unshift(...)
85
+ @operations << -> middleware { middleware.unshift(...) }
90
86
  end
91
- ruby2_keywords(:unshift) if respond_to?(:ruby2_keywords, true)
92
87
 
93
- def merge_into(other) #:nodoc:
88
+ def merge_into(other) # :nodoc:
94
89
  (@operations + @delete_operations).each do |operation|
95
90
  operation.call(other)
96
91
  end
@@ -106,7 +101,7 @@ module Rails
106
101
  attr_reader :operations, :delete_operations
107
102
  end
108
103
 
109
- class Generators #:nodoc:
104
+ class Generators # :nodoc:
110
105
  attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging, :api_only
111
106
  attr_reader :hidden_namespaces, :after_generate_callbacks
112
107
 
@@ -55,9 +55,9 @@ module Rails
55
55
  paths.add "lib/tasks", glob: "**/*.rake"
56
56
 
57
57
  paths.add "config"
58
- paths.add "config/environments", glob: "#{Rails.env}.rb"
58
+ paths.add "config/environments", glob: -"#{Rails.env}.rb"
59
59
  paths.add "config/initializers", glob: "**/*.rb"
60
- paths.add "config/locales", glob: "*.{rb,yml}"
60
+ paths.add "config/locales", glob: "**/*.{rb,yml}"
61
61
  paths.add "config/routes.rb"
62
62
  paths.add "config/routes", glob: "**/*.rb"
63
63