railties 5.2.8.1 → 6.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of railties might be problematic. Click here for more details.

Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +182 -223
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +35 -28
  5. data/README.rdoc +1 -1
  6. data/lib/minitest/rails_plugin.rb +6 -10
  7. data/lib/rails/all.rb +4 -0
  8. data/lib/rails/api/generator.rb +2 -1
  9. data/lib/rails/api/task.rb +16 -0
  10. data/lib/rails/app_loader.rb +1 -1
  11. data/lib/rails/app_updater.rb +3 -1
  12. data/lib/rails/application/configuration.rb +54 -12
  13. data/lib/rails/application/default_middleware_stack.rb +2 -0
  14. data/lib/rails/application.rb +21 -45
  15. data/lib/rails/backtrace_cleaner.rb +5 -17
  16. data/lib/rails/code_statistics.rb +3 -3
  17. data/lib/rails/command/actions.rb +0 -10
  18. data/lib/rails/command/base.rb +1 -5
  19. data/lib/rails/command/behavior.rb +4 -46
  20. data/lib/rails/command/environment_argument.rb +1 -11
  21. data/lib/rails/command/spellchecker.rb +58 -0
  22. data/lib/rails/command.rb +11 -10
  23. data/lib/rails/commands/credentials/USAGE +19 -1
  24. data/lib/rails/commands/credentials/credentials_command.rb +42 -23
  25. data/lib/rails/commands/db/system/change/change_command.rb +20 -0
  26. data/lib/rails/commands/dbconsole/dbconsole_command.rb +2 -2
  27. data/lib/rails/commands/dev/dev_command.rb +17 -0
  28. data/lib/rails/commands/encrypted/encrypted_command.rb +2 -3
  29. data/lib/rails/commands/help/help_command.rb +1 -1
  30. data/lib/rails/commands/initializers/initializers_command.rb +16 -0
  31. data/lib/rails/commands/new/new_command.rb +2 -2
  32. data/lib/rails/commands/notes/notes_command.rb +39 -0
  33. data/lib/rails/commands/plugin/plugin_command.rb +1 -1
  34. data/lib/rails/commands/routes/routes_command.rb +37 -0
  35. data/lib/rails/commands/runner/runner_command.rb +6 -6
  36. data/lib/rails/commands/secrets/USAGE +3 -3
  37. data/lib/rails/commands/secrets/secrets_command.rb +3 -3
  38. data/lib/rails/commands/server/server_command.rb +109 -48
  39. data/lib/rails/configuration.rb +1 -7
  40. data/lib/rails/engine/configuration.rb +3 -1
  41. data/lib/rails/engine.rb +3 -9
  42. data/lib/rails/gem_version.rb +4 -4
  43. data/lib/rails/generators/actions.rb +48 -37
  44. data/lib/rails/generators/app_base.rb +49 -89
  45. data/lib/rails/generators/app_name.rb +50 -0
  46. data/lib/rails/generators/base.rb +0 -4
  47. data/lib/rails/generators/database.rb +57 -0
  48. data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -1
  49. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
  50. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +1 -1
  51. data/lib/rails/generators/generated_attribute.rb +17 -17
  52. data/lib/rails/generators/model_helpers.rb +8 -1
  53. data/lib/rails/generators/named_base.rb +1 -5
  54. data/lib/rails/generators/rails/app/app_generator.rb +37 -72
  55. data/lib/rails/generators/rails/app/templates/Gemfile.tt +3 -6
  56. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
  57. data/lib/rails/generators/rails/app/templates/app/{assets/javascripts/cable.js.tt → javascript/channels/consumer.js} +2 -9
  58. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
  59. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +15 -0
  60. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
  61. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
  62. data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -5
  63. data/lib/rails/generators/rails/app/templates/bin/update.tt +6 -7
  64. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +2 -0
  65. data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
  66. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +2 -2
  67. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +2 -2
  68. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
  69. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
  70. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
  71. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +4 -4
  72. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
  73. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +6 -6
  74. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -2
  76. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +5 -12
  77. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -2
  78. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
  79. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +4 -0
  80. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +33 -0
  81. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  82. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +3 -5
  83. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
  84. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
  85. data/lib/rails/generators/rails/app/templates/gitignore.tt +2 -7
  86. data/lib/rails/generators/rails/app/templates/package.json.tt +7 -1
  87. data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
  88. data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
  89. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +7 -0
  90. data/lib/rails/generators/rails/assets/USAGE +1 -4
  91. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -8
  92. data/lib/rails/generators/rails/controller/controller_generator.rb +11 -1
  93. data/lib/rails/generators/rails/credentials/credentials_generator.rb +7 -8
  94. data/lib/rails/generators/rails/db/system/change/change_generator.rb +55 -0
  95. data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +4 -5
  96. data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
  97. data/lib/rails/generators/rails/plugin/plugin_generator.rb +9 -18
  98. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -1
  99. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
  100. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
  101. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
  102. data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
  103. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +1 -1
  104. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
  105. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +1 -2
  107. data/lib/rails/generators/resource_helpers.rb +1 -6
  108. data/lib/rails/generators/test_unit/integration/integration_generator.rb +6 -0
  109. data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
  110. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
  111. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +1 -1
  112. data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
  113. data/lib/rails/generators/testing/behaviour.rb +3 -0
  114. data/lib/rails/generators.rb +11 -12
  115. data/lib/rails/info.rb +2 -2
  116. data/lib/rails/info_controller.rb +1 -1
  117. data/lib/rails/mailers_controller.rb +1 -1
  118. data/lib/rails/paths.rb +19 -9
  119. data/lib/rails/railtie.rb +1 -1
  120. data/lib/rails/ruby_version_check.rb +3 -3
  121. data/lib/rails/secrets.rb +0 -1
  122. data/lib/rails/source_annotation_extractor.rb +125 -117
  123. data/lib/rails/tasks/annotations.rake +9 -9
  124. data/lib/rails/tasks/dev.rake +5 -4
  125. data/lib/rails/tasks/framework.rake +5 -1
  126. data/lib/rails/tasks/initializers.rake +5 -4
  127. data/lib/rails/tasks/log.rake +0 -1
  128. data/lib/rails/tasks/routes.rake +4 -26
  129. data/lib/rails/tasks/statistics.rake +1 -0
  130. data/lib/rails/tasks/yarn.rake +1 -1
  131. data/lib/rails/templates/rails/welcome/index.html.erb +2 -2
  132. data/lib/rails/test_help.rb +11 -9
  133. data/lib/rails/test_unit/reporter.rb +1 -1
  134. data/lib/rails/test_unit/runner.rb +5 -5
  135. data/lib/rails/test_unit/testing.rake +1 -1
  136. metadata +33 -27
  137. data/lib/rails/commands/encrypted/USAGE +0 -28
  138. data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
  139. data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
  140. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
  141. data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
  142. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -38
  143. data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
data/lib/rails/command.rb CHANGED
@@ -4,7 +4,6 @@ require "active_support"
4
4
  require "active_support/dependencies/autoload"
5
5
  require "active_support/core_ext/enumerable"
6
6
  require "active_support/core_ext/object/blank"
7
- require "active_support/core_ext/hash/transform_values"
8
7
 
9
8
  require "thor"
10
9
 
@@ -12,6 +11,7 @@ module Rails
12
11
  module Command
13
12
  extend ActiveSupport::Autoload
14
13
 
14
+ autoload :Spellchecker
15
15
  autoload :Behavior
16
16
  autoload :Base
17
17
 
@@ -83,20 +83,21 @@ module Rails
83
83
  end
84
84
 
85
85
  def print_commands # :nodoc:
86
- sorted_groups.each { |b, n| print_list(b, n) }
86
+ commands.each { |command| puts(" #{command}") }
87
87
  end
88
88
 
89
- def sorted_groups # :nodoc:
90
- lookup!
89
+ private
90
+ COMMANDS_IN_USAGE = %w(generate console server test test:system dbconsole new)
91
+ private_constant :COMMANDS_IN_USAGE
91
92
 
92
- groups = (subclasses - hidden_commands).group_by { |c| c.namespace.split(":").first }
93
- groups.transform_values! { |commands| commands.flat_map(&:printing_commands).sort }
93
+ def commands
94
+ lookup!
94
95
 
95
- rails = groups.delete("rails")
96
- [[ "rails", rails ]] + groups.sort.to_a
97
- end
96
+ visible_commands = (subclasses - hidden_commands).flat_map(&:printing_commands)
97
+
98
+ (visible_commands - COMMANDS_IN_USAGE).sort
99
+ end
98
100
 
99
- private
100
101
  def command_type # :doc:
101
102
  @command_type ||= "command"
102
103
  end
@@ -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 `bin/rails credentials:edit`.
17
+ credentials file in `config/credentials.yml.enc` the first time you run `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.
@@ -38,3 +38,21 @@ the encrypted credentials.
38
38
  When the temporary file is next saved the contents are encrypted and written to
39
39
  `config/credentials.yml.enc` while the file itself is destroyed to prevent credentials
40
40
  from leaking.
41
+
42
+ === Environment Specific Credentials
43
+
44
+ The `credentials` command supports passing an `--environment` option to create an
45
+ environment specific override. That override will takes precedence over the
46
+ global `config/credentials.yml.enc` file when running in that environment. So:
47
+
48
+ rails credentials:edit --environment development
49
+
50
+ will create `config/credentials/development.yml.enc` with the corresponding
51
+ encryption key in `config/credentials/development.key` if the credentials file
52
+ doesn't exist.
53
+
54
+ The encryption key can also be put in `ENV["RAILS_MASTER_KEY"]`, which takes
55
+ precedence over the file encryption key.
56
+
57
+ In addition to that, the default credentials lookup paths can be overriden through
58
+ `config.credentials.content_path` and `config.credentials.key_path`.
@@ -8,6 +8,9 @@ module Rails
8
8
  class CredentialsCommand < Rails::Command::Base # :nodoc:
9
9
  include Helpers::Editor
10
10
 
11
+ class_option :environment, aliases: "-e", type: :string,
12
+ desc: "Uses credentials from config/credentials/:environment.yml.enc encrypted by config/credentials/:environment.key key"
13
+
11
14
  no_commands do
12
15
  def help
13
16
  say "Usage:\n #{self.class.banner}"
@@ -17,62 +20,78 @@ module Rails
17
20
  end
18
21
 
19
22
  def edit
20
- require_application!
23
+ require_application_and_environment!
21
24
 
22
25
  ensure_editor_available(command: "bin/rails credentials:edit") || (return)
23
- ensure_master_key_has_been_added if Rails.application.credentials.key.nil?
26
+
27
+ ensure_encryption_key_has_been_added if credentials.key.nil?
24
28
  ensure_credentials_have_been_added
25
29
 
26
30
  catch_editing_exceptions do
27
31
  change_credentials_in_system_editor
28
32
  end
29
33
 
30
- say "New credentials encrypted and saved."
34
+ say "File encrypted and saved."
35
+ rescue ActiveSupport::MessageEncryptor::InvalidMessage
36
+ say "Couldn't decrypt #{content_path}. Perhaps you passed the wrong key?"
31
37
  end
32
38
 
33
39
  def show
34
- require_application!
40
+ require_application_and_environment!
35
41
 
36
- say Rails.application.credentials.read.presence || missing_credentials_message
42
+ say credentials.read.presence || missing_credentials_message
37
43
  end
38
44
 
39
45
  private
40
- def ensure_master_key_has_been_added
41
- master_key_generator.add_master_key_file
42
- master_key_generator.ignore_master_key_file
46
+ def credentials
47
+ Rails.application.encrypted(content_path, key_path: key_path)
48
+ end
49
+
50
+ def ensure_encryption_key_has_been_added
51
+ encryption_key_file_generator.add_key_file(key_path)
52
+ encryption_key_file_generator.ignore_key_file(key_path)
43
53
  end
44
54
 
45
55
  def ensure_credentials_have_been_added
46
- credentials_generator.add_credentials_file_silently
56
+ encrypted_file_generator.add_encrypted_file_silently(content_path, key_path)
47
57
  end
48
58
 
49
59
  def change_credentials_in_system_editor
50
- Rails.application.credentials.change do |tmp_path|
60
+ credentials.change do |tmp_path|
51
61
  system("#{ENV["EDITOR"]} #{tmp_path}")
52
62
  end
53
63
  end
54
64
 
65
+ def missing_credentials_message
66
+ if credentials.key.nil?
67
+ "Missing '#{key_path}' to decrypt credentials. See `rails credentials:help`"
68
+ else
69
+ "File '#{content_path}' does not exist. Use `rails credentials:edit` to change that."
70
+ end
71
+ end
55
72
 
56
- def master_key_generator
57
- require "rails/generators"
58
- require "rails/generators/rails/master_key/master_key_generator"
59
73
 
60
- Rails::Generators::MasterKeyGenerator.new
74
+ def content_path
75
+ options[:environment] ? "config/credentials/#{options[:environment]}.yml.enc" : "config/credentials.yml.enc"
61
76
  end
62
77
 
63
- def credentials_generator
78
+ def key_path
79
+ options[:environment] ? "config/credentials/#{options[:environment]}.key" : "config/master.key"
80
+ end
81
+
82
+
83
+ def encryption_key_file_generator
64
84
  require "rails/generators"
65
- require "rails/generators/rails/credentials/credentials_generator"
85
+ require "rails/generators/rails/encryption_key_file/encryption_key_file_generator"
66
86
 
67
- Rails::Generators::CredentialsGenerator.new
87
+ Rails::Generators::EncryptionKeyFileGenerator.new
68
88
  end
69
89
 
70
- def missing_credentials_message
71
- if Rails.application.credentials.key.nil?
72
- "Missing master key to decrypt credentials. See bin/rails credentials:help"
73
- else
74
- "No credentials have been added yet. Use bin/rails credentials:edit to change that."
75
- end
90
+ def encrypted_file_generator
91
+ require "rails/generators"
92
+ require "rails/generators/rails/encrypted_file/encrypted_file_generator"
93
+
94
+ Rails::Generators::EncryptedFileGenerator.new
76
95
  end
77
96
  end
78
97
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require "rails/generators/rails/db/system/change/change_generator"
5
+
6
+ module Rails
7
+ module Command
8
+ module Db
9
+ module System
10
+ class ChangeCommand < Base # :nodoc:
11
+ class_option :to, desc: "The database system to switch to."
12
+
13
+ def perform
14
+ Rails::Generators::Db::System::ChangeGenerator.start
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -75,7 +75,7 @@ module Rails
75
75
  args += ["-P", "#{config['password']}"] if config["password"]
76
76
 
77
77
  if config["host"]
78
- host_arg = "#{config['host']}".dup
78
+ host_arg = +"#{config['host']}"
79
79
  host_arg << ":#{config['port']}" if config["port"]
80
80
  args += ["-S", host_arg]
81
81
  end
@@ -97,7 +97,7 @@ module Rails
97
97
  elsif configurations[environment].blank? && configurations[connection].blank?
98
98
  raise ActiveRecord::AdapterNotSpecified, "'#{environment}' database is not configured. Available configuration: #{configurations.inspect}"
99
99
  else
100
- configurations[environment].presence || configurations[connection]
100
+ configurations[connection] || configurations[environment].presence
101
101
  end
102
102
  end
103
103
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/dev_caching"
4
+
5
+ module Rails
6
+ module Command
7
+ class DevCommand < Base # :nodoc:
8
+ def help
9
+ say "rails dev:cache # Toggle development mode caching on/off."
10
+ end
11
+
12
+ def cache
13
+ Rails::DevCaching.enable_by_file
14
+ end
15
+ end
16
+ end
17
+ end
@@ -16,7 +16,6 @@ module Rails
16
16
  def help
17
17
  say "Usage:\n #{self.class.banner}"
18
18
  say ""
19
- say self.class.desc
20
19
  end
21
20
  end
22
21
 
@@ -77,9 +76,9 @@ module Rails
77
76
 
78
77
  def missing_encrypted_message(key:, key_path:, file_path:)
79
78
  if key.nil?
80
- "Missing '#{key_path}' to decrypt data. See bin/rails encrypted:help"
79
+ "Missing '#{key_path}' to decrypt data. See `rails encrypted:help`"
81
80
  else
82
- "File '#{file_path}' does not exist. Use bin/rails encrypted:edit #{file_path} to change that."
81
+ "File '#{file_path}' does not exist. Use `rails encrypted:edit #{file_path}` to change that."
83
82
  end
84
83
  end
85
84
  end
@@ -6,7 +6,7 @@ module Rails
6
6
  hide_command!
7
7
 
8
8
  def help(*)
9
- puts self.class.desc
9
+ say self.class.desc
10
10
 
11
11
  Rails::Command.print_commands
12
12
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Command
5
+ class InitializersCommand < Base # :nodoc:
6
+ desc "initializers", "Print out all defined initializers in the order they are invoked by Rails."
7
+ def perform
8
+ require_application_and_environment!
9
+
10
+ Rails.application.initializers.tsort_each do |initializer|
11
+ say "#{initializer.context_class}.#{initializer.name}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -10,8 +10,8 @@ module Rails
10
10
  end
11
11
 
12
12
  def perform(*)
13
- puts "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n"
14
- puts "Type 'rails' for help."
13
+ say "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n"
14
+ say "Type 'rails' for help."
15
15
  exit 1
16
16
  end
17
17
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/source_annotation_extractor"
4
+
5
+ module Rails
6
+ module Command
7
+ class NotesCommand < Base # :nodoc:
8
+ class_option :annotations, aliases: "-a", desc: "Filter by specific annotations, e.g. Foobar TODO", type: :array, default: %w(OPTIMIZE FIXME TODO)
9
+
10
+ def perform(*)
11
+ require_application_and_environment!
12
+
13
+ deprecation_warning
14
+ display_annotations
15
+ end
16
+
17
+ private
18
+ def display_annotations
19
+ annotations = options[:annotations]
20
+ tag = (annotations.length > 1)
21
+
22
+ Rails::SourceAnnotationExtractor.enumerate annotations.join("|"), tag: tag, dirs: directories
23
+ end
24
+
25
+ def directories
26
+ Rails::SourceAnnotationExtractor::Annotation.directories + source_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(",")
36
+ end
37
+ end
38
+ end
39
+ end
@@ -26,7 +26,7 @@ module Rails
26
26
 
27
27
  if File.exist?(railsrc)
28
28
  extra_args = File.read(railsrc).split(/\n+/).flat_map(&:split)
29
- puts "Using #{extra_args.join(" ")} from #{railsrc}"
29
+ say "Using #{extra_args.join(" ")} from #{railsrc}"
30
30
  plugin_args.insert(1, *extra_args)
31
31
  end
32
32
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/command"
4
+
5
+ module Rails
6
+ module Command
7
+ class RoutesCommand < Base # :nodoc:
8
+ class_option :controller, aliases: "-c", desc: "Filter by a specific controller, e.g. PostsController or Admin::PostsController."
9
+ class_option :grep, aliases: "-g", desc: "Grep routes by a specific pattern."
10
+ class_option :expanded, type: :boolean, aliases: "-E", desc: "Print routes expanded vertically with parts explained."
11
+
12
+ def perform(*)
13
+ require_application_and_environment!
14
+ require "action_dispatch/routing/inspector"
15
+
16
+ say inspector.format(formatter, routes_filter)
17
+ end
18
+
19
+ private
20
+ def inspector
21
+ ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
22
+ end
23
+
24
+ def formatter
25
+ if options.key?("expanded")
26
+ ActionDispatch::Routing::ConsoleFormatter::Expanded.new
27
+ else
28
+ ActionDispatch::Routing::ConsoleFormatter::Sheet.new
29
+ end
30
+ end
31
+
32
+ def routes_filter
33
+ options.symbolize_keys.slice(:controller, :grep)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -10,7 +10,7 @@ module Rails
10
10
  no_commands do
11
11
  def help
12
12
  super
13
- puts self.class.desc
13
+ say self.class.desc
14
14
  end
15
15
  end
16
16
 
@@ -39,11 +39,11 @@ module Rails
39
39
  else
40
40
  begin
41
41
  eval(code_or_file, TOPLEVEL_BINDING, __FILE__, __LINE__)
42
- rescue SyntaxError, NameError => error
43
- $stderr.puts "Please specify a valid ruby command or the path of a script to run."
44
- $stderr.puts "Run '#{self.class.executable} -h' for help."
45
- $stderr.puts
46
- $stderr.puts error
42
+ rescue SyntaxError, NameError => e
43
+ error "Please specify a valid ruby command or the path of a script to run."
44
+ error "Run '#{self.class.executable} -h' for help."
45
+ error ""
46
+ error e
47
47
  exit 1
48
48
  end
49
49
  end
@@ -7,7 +7,7 @@ with the code.
7
7
 
8
8
  === Setup
9
9
 
10
- Run `bin/rails secrets:setup` to opt in and generate the `config/secrets.yml.key`
10
+ Run `rails secrets:setup` to opt in and generate the `config/secrets.yml.key`
11
11
  and `config/secrets.yml.enc` files.
12
12
 
13
13
  The latter contains all the keys to be encrypted while the former holds the
@@ -45,12 +45,12 @@ the key. Add this:
45
45
 
46
46
  config.read_encrypted_secrets = true
47
47
 
48
- to the environment you'd like to read encrypted secrets. `bin/rails secrets:setup`
48
+ to the environment you'd like to read encrypted secrets. `rails secrets:setup`
49
49
  inserts this into the production environment by default.
50
50
 
51
51
  === Editing Secrets
52
52
 
53
- After `bin/rails secrets:setup`, run `bin/rails secrets:edit`.
53
+ After `rails secrets:setup`, run `rails secrets:edit`.
54
54
 
55
55
  That command opens a temporary file in `$EDITOR` with the decrypted contents of
56
56
  `config/secrets.yml.enc` to edit the encrypted secrets.
@@ -22,7 +22,7 @@ module Rails
22
22
  if ENV["EDITOR"].to_s.empty?
23
23
  say "No $EDITOR to open decrypted secrets in. Assign one like this:"
24
24
  say ""
25
- say %(EDITOR="mate --wait" bin/rails secrets:edit)
25
+ say %(EDITOR="mate --wait" rails secrets:edit)
26
26
  say ""
27
27
  say "For editors that fork and exit immediately, it's important to pass a wait flag,"
28
28
  say "otherwise the secrets will be saved immediately with no chance to edit."
@@ -42,7 +42,7 @@ module Rails
42
42
  rescue Rails::Secrets::MissingKeyError => error
43
43
  say error.message
44
44
  rescue Errno::ENOENT => error
45
- if error.message =~ /secrets\.yml\.enc/
45
+ if /secrets\.yml\.enc/.match?(error.message)
46
46
  deprecate_in_favor_of_credentials_and_exit
47
47
  else
48
48
  raise
@@ -56,7 +56,7 @@ module Rails
56
56
  private
57
57
  def deprecate_in_favor_of_credentials_and_exit
58
58
  say "Encrypted secrets is deprecated in favor of credentials. Run:"
59
- say "bin/rails credentials:help"
59
+ say "rails credentials:help"
60
60
 
61
61
  exit 1
62
62
  end