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
@@ -14,6 +14,11 @@ module TestUnit # :nodoc:
14
14
 
15
15
  template "system_test.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb")
16
16
  end
17
+
18
+ private
19
+ def file_name
20
+ @_file_name ||= super.sub(/_test\z/i, "")
21
+ end
17
22
  end
18
23
  end
19
24
  end
@@ -67,6 +67,9 @@ module Rails
67
67
  def run_generator(args = default_arguments, config = {})
68
68
  capture(:stdout) do
69
69
  args += ["--skip-bundle"] unless args.include? "--dev"
70
+ args |= ["--skip-bootsnap"] unless args.include? "--no-skip-bootsnap"
71
+ args |= ["--skip-webpack-install"] unless args.include? "--no-skip-webpack-install"
72
+
70
73
  generator_class.start(args, config.reverse_merge(destination_root: destination_root))
71
74
  end
72
75
  end
@@ -23,6 +23,8 @@ module Rails
23
23
  autoload :ActiveModel, "rails/generators/active_model"
24
24
  autoload :Base, "rails/generators/base"
25
25
  autoload :Migration, "rails/generators/migration"
26
+ autoload :Database, "rails/generators/database"
27
+ autoload :AppName, "rails/generators/app_name"
26
28
  autoload :NamedBase, "rails/generators/named_base"
27
29
  autoload :ResourceHelpers, "rails/generators/resource_helpers"
28
30
  autoload :TestCase, "rails/generators/test_case"
@@ -33,8 +35,6 @@ module Rails
33
35
  rails: {
34
36
  actions: "-a",
35
37
  orm: "-o",
36
- javascripts: "-j",
37
- javascript_engine: "-je",
38
38
  resource_controller: "-c",
39
39
  scaffold_controller: "-c",
40
40
  stylesheets: "-y",
@@ -56,8 +56,6 @@ module Rails
56
56
  force_plural: false,
57
57
  helper: true,
58
58
  integration_tool: nil,
59
- javascripts: true,
60
- javascript_engine: :js,
61
59
  orm: false,
62
60
  resource_controller: :controller,
63
61
  resource_route: true,
@@ -126,7 +124,7 @@ module Rails
126
124
  )
127
125
 
128
126
  if ARGV.first == "mailer"
129
- options[:rails].merge!(template_engine: :erb)
127
+ options[:rails][:template_engine] = :erb
130
128
  end
131
129
  end
132
130
 
@@ -222,6 +220,7 @@ module Rails
222
220
  rails.delete("encryption_key_file")
223
221
  rails.delete("master_key")
224
222
  rails.delete("credentials")
223
+ rails.delete("db:system:change")
225
224
 
226
225
  hidden_namespaces.each { |n| groups.delete(n.to_s) }
227
226
 
@@ -258,7 +257,6 @@ module Rails
258
257
 
259
258
  namespaces = Hash[subclasses.map { |klass| [klass.namespace, klass] }]
260
259
  lookups.each do |namespace|
261
-
262
260
  klass = namespaces[namespace]
263
261
  return klass if klass
264
262
  end
@@ -276,12 +274,13 @@ module Rails
276
274
  klass.start(args, config)
277
275
  else
278
276
  options = sorted_groups.flat_map(&:last)
279
- suggestions = options.sort_by { |suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3)
280
- suggestions.map! { |s| "'#{s}'" }
281
- msg = "Could not find generator '#{namespace}'. ".dup
282
- msg << "Maybe you meant #{ suggestions[0...-1].join(', ')} or #{suggestions[-1]}\n"
283
- msg << "Run `rails generate --help` for more options."
284
- puts msg
277
+ suggestion = Rails::Command::Spellchecker.suggest(namespace.to_s, from: options)
278
+ suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
279
+
280
+ puts <<~MSG
281
+ Could not find generator '#{namespace}'. #{suggestion_msg}
282
+ Run `rails generate --help` for more options.
283
+ MSG
285
284
  end
286
285
  end
287
286
 
data/lib/rails/info.rb CHANGED
@@ -41,7 +41,7 @@ module Rails
41
41
  alias inspect to_s
42
42
 
43
43
  def to_html
44
- "<table>".dup.tap do |table|
44
+ (+"<table>").tap do |table|
45
45
  properties.each do |(name, value)|
46
46
  table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
47
47
  formatted_value = if value.kind_of?(Array)
@@ -63,7 +63,7 @@ module Rails
63
63
 
64
64
  # The Ruby version and platform, e.g. "2.0.0-p247 (x86_64-darwin12.4.0)".
65
65
  property "Ruby version" do
66
- "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})"
66
+ RUBY_DESCRIPTION
67
67
  end
68
68
 
69
69
  # The RubyGems version, if it's installed.
@@ -4,7 +4,7 @@ require "rails/application_controller"
4
4
  require "action_dispatch/routing/inspector"
5
5
 
6
6
  class Rails::InfoController < Rails::ApplicationController # :nodoc:
7
- prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
7
+ prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATH
8
8
  layout -> { request.xhr? ? false : "application" }
9
9
 
10
10
  before_action :require_local!
@@ -3,7 +3,7 @@
3
3
  require "rails/application_controller"
4
4
 
5
5
  class Rails::MailersController < Rails::ApplicationController # :nodoc:
6
- prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
6
+ prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATH
7
7
 
8
8
  before_action :require_local!, unless: :show_previews?
9
9
  before_action :find_preview, :set_locale, only: :preview
data/lib/rails/paths.rb CHANGED
@@ -113,10 +113,11 @@ module Rails
113
113
  attr_accessor :glob
114
114
 
115
115
  def initialize(root, current, paths, options = {})
116
- @paths = paths
117
- @current = current
118
- @root = root
119
- @glob = options[:glob]
116
+ @paths = paths
117
+ @current = current
118
+ @root = root
119
+ @glob = options[:glob]
120
+ @exclude = options[:exclude]
120
121
 
121
122
  options[:autoload_once] ? autoload_once! : skip_autoload_once!
122
123
  options[:eager_load] ? eager_load! : skip_eager_load!
@@ -189,13 +190,11 @@ module Rails
189
190
  raise "You need to set a path root" unless @root.path
190
191
  result = []
191
192
 
192
- each do |p|
193
- path = File.expand_path(p, @root.path)
193
+ each do |path|
194
+ path = File.expand_path(path, @root.path)
194
195
 
195
196
  if @glob && File.directory?(path)
196
- Dir.chdir(path) do
197
- result.concat(Dir.glob(@glob).map { |file| File.join path, file }.sort)
198
- end
197
+ result.concat files_in(path)
199
198
  else
200
199
  result << path
201
200
  end
@@ -222,6 +221,17 @@ module Rails
222
221
  end
223
222
 
224
223
  alias to_a expanded
224
+
225
+ private
226
+
227
+ def files_in(path)
228
+ Dir.chdir(path) do
229
+ files = Dir.glob(@glob)
230
+ files -= @exclude if @exclude
231
+ files.map! { |file| File.join(path, file) }
232
+ files.sort
233
+ end
234
+ end
225
235
  end
226
236
  end
227
237
  end
data/lib/rails/railtie.rb CHANGED
@@ -224,7 +224,7 @@ module Rails
224
224
  end
225
225
 
226
226
  def railtie_namespace #:nodoc:
227
- @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:railtie_namespace) }
227
+ @railtie_namespace ||= self.class.module_parents.detect { |n| n.respond_to?(:railtie_namespace) }
228
228
  end
229
229
 
230
230
  protected
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2") && RUBY_ENGINE == "ruby"
3
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5.0") && RUBY_ENGINE == "ruby"
4
4
  desc = defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
5
5
  abort <<-end_message
6
6
 
7
- Rails 5 requires Ruby 2.2.2 or newer.
7
+ Rails 6 requires Ruby 2.5.0 or newer.
8
8
 
9
9
  You're running
10
10
  #{desc}
11
11
 
12
- Please upgrade to Ruby 2.2.2 or newer to continue.
12
+ Please upgrade to Ruby 2.5.0 or newer to continue.
13
13
 
14
14
  end_message
15
15
  end
data/lib/rails/secrets.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "yaml"
4
4
  require "active_support/message_encryptor"
5
- require "active_support/core_ext/string/strip"
6
5
 
7
6
  module Rails
8
7
  # Greatly inspired by Ara T. Howard's magnificent sekrets gem. 😘
@@ -1,141 +1,149 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Implements the logic behind the rake tasks for annotations like
4
- #
5
- # rails notes
6
- # rails notes:optimize
7
- #
8
- # and friends. See <tt>rails -T notes</tt> and <tt>railties/lib/rails/tasks/annotations.rake</tt>.
9
- #
10
- # Annotation objects are triplets <tt>:line</tt>, <tt>:tag</tt>, <tt>:text</tt> that
11
- # represent the line where the annotation lives, its tag, and its text. Note
12
- # the filename is not stored.
13
- #
14
- # Annotations are looked for in comments and modulus whitespace they have to
15
- # start with the tag optionally followed by a colon. Everything up to the end
16
- # of the line (or closing ERB comment tag) is considered to be their text.
17
- class SourceAnnotationExtractor
18
- Annotation = Struct.new(:line, :tag, :text) do
19
- def self.directories
20
- @@directories ||= %w(app config db lib test) + (ENV["SOURCE_ANNOTATION_DIRECTORIES"] || "").split(",")
21
- end
3
+ require "active_support/deprecation"
22
4
 
23
- # Registers additional directories to be included
24
- # SourceAnnotationExtractor::Annotation.register_directories("spec", "another")
25
- def self.register_directories(*dirs)
26
- directories.push(*dirs)
27
- end
5
+ # Remove this deprecated class in the next minor version
6
+ #:nodoc:
7
+ SourceAnnotationExtractor = ActiveSupport::Deprecation::DeprecatedConstantProxy.
8
+ new("SourceAnnotationExtractor", "Rails::SourceAnnotationExtractor")
28
9
 
29
- def self.extensions
30
- @@extensions ||= {}
31
- end
10
+ module Rails
11
+ # Implements the logic behind <tt>Rails::Command::NotesCommand</tt>. See <tt>rails notes --help</tt> for usage information.
12
+ #
13
+ # Annotation objects are triplets <tt>:line</tt>, <tt>:tag</tt>, <tt>:text</tt> that
14
+ # represent the line where the annotation lives, its tag, and its text. Note
15
+ # the filename is not stored.
16
+ #
17
+ # Annotations are looked for in comments and modulus whitespace they have to
18
+ # start with the tag optionally followed by a colon. Everything up to the end
19
+ # of the line (or closing ERB comment tag) is considered to be their text.
20
+ class SourceAnnotationExtractor
21
+ class Annotation < Struct.new(:line, :tag, :text)
22
+ def self.directories
23
+ @@directories ||= %w(app config db lib test)
24
+ end
32
25
 
33
- # Registers new Annotations File Extensions
34
- # SourceAnnotationExtractor::Annotation.register_extensions("css", "scss", "sass", "less", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
35
- def self.register_extensions(*exts, &block)
36
- extensions[/\.(#{exts.join("|")})$/] = block
37
- end
26
+ # Registers additional directories to be included
27
+ # Rails::SourceAnnotationExtractor::Annotation.register_directories("spec", "another")
28
+ def self.register_directories(*dirs)
29
+ directories.push(*dirs)
30
+ end
31
+
32
+ def self.extensions
33
+ @@extensions ||= {}
34
+ end
38
35
 
39
- register_extensions("builder", "rb", "rake", "yml", "yaml", "ruby") { |tag| /#\s*(#{tag}):?\s*(.*)$/ }
40
- register_extensions("css", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
41
- register_extensions("erb") { |tag| /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/ }
36
+ # Registers new Annotations File Extensions
37
+ # Rails::SourceAnnotationExtractor::Annotation.register_extensions("css", "scss", "sass", "less", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
38
+ def self.register_extensions(*exts, &block)
39
+ extensions[/\.(#{exts.join("|")})$/] = block
40
+ end
41
+
42
+ register_extensions("builder", "rb", "rake", "yml", "yaml", "ruby") { |tag| /#\s*(#{tag}):?\s*(.*)$/ }
43
+ register_extensions("css", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
44
+ register_extensions("erb") { |tag| /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/ }
45
+
46
+ # Returns a representation of the annotation that looks like this:
47
+ #
48
+ # [126] [TODO] This algorithm is simple and clearly correct, make it faster.
49
+ #
50
+ # If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
51
+ # Otherwise the string contains just line and text.
52
+ def to_s(options = {})
53
+ s = +"[#{line.to_s.rjust(options[:indent])}] "
54
+ s << "[#{tag}] " if options[:tag]
55
+ s << text
56
+ end
57
+
58
+ # Used in annotations.rake
59
+ #:nodoc:
60
+ def self.notes_task_deprecation_warning
61
+ ActiveSupport::Deprecation.warn("This rake task is deprecated and will be removed in Rails 6.1. \nRefer to `rails notes --help` for more information.\n")
62
+ puts "\n"
63
+ end
64
+ end
42
65
 
43
- # Returns a representation of the annotation that looks like this:
66
+ # Prints all annotations with tag +tag+ under the root directories +app+,
67
+ # +config+, +db+, +lib+, and +test+ (recursively).
68
+ #
69
+ # Specific directories can be explicitly set using the <tt>:dirs</tt> key in +options+.
70
+ #
71
+ # Rails::SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true
44
72
  #
45
- # [126] [TODO] This algorithm is simple and clearly correct, make it faster.
73
+ # If +options+ has a <tt>:tag</tt> flag, it will be passed to each annotation's +to_s+.
46
74
  #
47
- # If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
48
- # Otherwise the string contains just line and text.
49
- def to_s(options = {})
50
- s = "[#{line.to_s.rjust(options[:indent])}] ".dup
51
- s << "[#{tag}] " if options[:tag]
52
- s << text
75
+ # See <tt>#find_in</tt> for a list of file extensions that will be taken into account.
76
+ #
77
+ # This class method is the single entry point for the `rails notes` command.
78
+ def self.enumerate(tag, options = {})
79
+ extractor = new(tag)
80
+ dirs = options.delete(:dirs) || Annotation.directories
81
+ extractor.display(extractor.find(dirs), options)
53
82
  end
54
- end
55
83
 
56
- # Prints all annotations with tag +tag+ under the root directories +app+,
57
- # +config+, +db+, +lib+, and +test+ (recursively).
58
- #
59
- # Additional directories may be added using a comma-delimited list set using
60
- # <tt>ENV['SOURCE_ANNOTATION_DIRECTORIES']</tt>.
61
- #
62
- # Directories may also be explicitly set using the <tt>:dirs</tt> key in +options+.
63
- #
64
- # SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true
65
- #
66
- # If +options+ has a <tt>:tag</tt> flag, it will be passed to each annotation's +to_s+.
67
- #
68
- # See <tt>#find_in</tt> for a list of file extensions that will be taken into account.
69
- #
70
- # This class method is the single entry point for the rake tasks.
71
- def self.enumerate(tag, options = {})
72
- extractor = new(tag)
73
- dirs = options.delete(:dirs) || Annotation.directories
74
- extractor.display(extractor.find(dirs), options)
75
- end
76
-
77
- attr_reader :tag
78
-
79
- def initialize(tag)
80
- @tag = tag
81
- end
84
+ attr_reader :tag
82
85
 
83
- # Returns a hash that maps filenames under +dirs+ (recursively) to arrays
84
- # with their annotations.
85
- def find(dirs)
86
- dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
87
- end
86
+ def initialize(tag)
87
+ @tag = tag
88
+ end
88
89
 
89
- # Returns a hash that maps filenames under +dir+ (recursively) to arrays
90
- # with their annotations. Only files with annotations are included. Files
91
- # with extension +.builder+, +.rb+, +.rake+, +.yml+, +.yaml+, +.ruby+,
92
- # +.css+, +.js+ and +.erb+ are taken into account.
93
- def find_in(dir)
94
- results = {}
95
-
96
- Dir.glob("#{dir}/*") do |item|
97
- next if File.basename(item)[0] == ?.
98
-
99
- if File.directory?(item)
100
- results.update(find_in(item))
101
- else
102
- extension = Annotation.extensions.detect do |regexp, _block|
103
- regexp.match(item)
104
- end
90
+ # Returns a hash that maps filenames under +dirs+ (recursively) to arrays
91
+ # with their annotations.
92
+ def find(dirs)
93
+ dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
94
+ end
105
95
 
106
- if extension
107
- pattern = extension.last.call(tag)
108
- results.update(extract_annotations_from(item, pattern)) if pattern
96
+ # Returns a hash that maps filenames under +dir+ (recursively) to arrays
97
+ # with their annotations. Files with extensions registered in
98
+ # <tt>Rails::SourceAnnotationExtractor::Annotation.extensions</tt> are
99
+ # taken into account. Only files with annotations are included.
100
+ def find_in(dir)
101
+ results = {}
102
+
103
+ Dir.glob("#{dir}/*") do |item|
104
+ next if File.basename(item)[0] == ?.
105
+
106
+ if File.directory?(item)
107
+ results.update(find_in(item))
108
+ else
109
+ extension = Annotation.extensions.detect do |regexp, _block|
110
+ regexp.match(item)
111
+ end
112
+
113
+ if extension
114
+ pattern = extension.last.call(tag)
115
+ results.update(extract_annotations_from(item, pattern)) if pattern
116
+ end
109
117
  end
110
118
  end
111
- end
112
119
 
113
- results
114
- end
120
+ results
121
+ end
115
122
 
116
- # If +file+ is the filename of a file that contains annotations this method returns
117
- # a hash with a single entry that maps +file+ to an array of its annotations.
118
- # Otherwise it returns an empty hash.
119
- def extract_annotations_from(file, pattern)
120
- lineno = 0
121
- result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
122
- lineno += 1
123
- next list unless line =~ pattern
124
- list << Annotation.new(lineno, $1, $2)
123
+ # If +file+ is the filename of a file that contains annotations this method returns
124
+ # a hash with a single entry that maps +file+ to an array of its annotations.
125
+ # Otherwise it returns an empty hash.
126
+ def extract_annotations_from(file, pattern)
127
+ lineno = 0
128
+ result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
129
+ lineno += 1
130
+ next list unless line =~ pattern
131
+ list << Annotation.new(lineno, $1, $2)
132
+ end
133
+ result.empty? ? {} : { file => result }
125
134
  end
126
- result.empty? ? {} : { file => result }
127
- end
128
135
 
129
- # Prints the mapping from filenames to annotations in +results+ ordered by filename.
130
- # The +options+ hash is passed to each annotation's +to_s+.
131
- def display(results, options = {})
132
- options[:indent] = results.flat_map { |f, a| a.map(&:line) }.max.to_s.size
133
- results.keys.sort.each do |file|
134
- puts "#{file}:"
135
- results[file].each do |note|
136
- puts " * #{note.to_s(options)}"
136
+ # Prints the mapping from filenames to annotations in +results+ ordered by filename.
137
+ # The +options+ hash is passed to each annotation's +to_s+.
138
+ def display(results, options = {})
139
+ options[:indent] = results.flat_map { |f, a| a.map(&:line) }.max.to_s.size
140
+ results.keys.sort.each do |file|
141
+ puts "#{file}:"
142
+ results[file].each do |note|
143
+ puts " * #{note.to_s(options)}"
144
+ end
145
+ puts
137
146
  end
138
- puts
139
147
  end
140
148
  end
141
149
  end
@@ -2,21 +2,21 @@
2
2
 
3
3
  require "rails/source_annotation_extractor"
4
4
 
5
- desc "Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)"
6
- task :notes do
7
- SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", tag: true
5
+ task notes: :environment do
6
+ Rails::SourceAnnotationExtractor::Annotation.notes_task_deprecation_warning
7
+ Rails::Command.invoke :notes
8
8
  end
9
9
 
10
10
  namespace :notes do
11
11
  ["OPTIMIZE", "FIXME", "TODO"].each do |annotation|
12
- # desc "Enumerate all #{annotation} annotations"
13
- task annotation.downcase.intern do
14
- SourceAnnotationExtractor.enumerate annotation
12
+ task annotation.downcase.intern => :environment do
13
+ Rails::SourceAnnotationExtractor::Annotation.notes_task_deprecation_warning
14
+ Rails::Command.invoke :notes, ["--annotations", annotation]
15
15
  end
16
16
  end
17
17
 
18
- desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM"
19
- task :custom do
20
- SourceAnnotationExtractor.enumerate ENV["ANNOTATION"]
18
+ task custom: :environment do
19
+ Rails::SourceAnnotationExtractor::Annotation.notes_task_deprecation_warning
20
+ Rails::Command.invoke :notes, ["--annotations", ENV["ANNOTATION"]]
21
21
  end
22
22
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rails/dev_caching"
3
+ require "rails/command"
4
+ require "active_support/deprecation"
4
5
 
5
6
  namespace :dev do
6
- desc "Toggle development mode caching on/off"
7
- task :cache do
8
- Rails::DevCaching.enable_by_file
7
+ task cache: :environment do
8
+ ActiveSupport::Deprecation.warn("Using `bin/rake dev:cache` is deprecated and will be removed in Rails 6.1. Use `bin/rails dev:cache` instead.\n")
9
+ Rails::Command.invoke "dev:cache"
9
10
  end
10
11
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  namespace :app do
4
4
  desc "Update configs and some other initially generated files (or use just update:configs or update:bin)"
5
- task update: [ "update:configs", "update:bin", "update:upgrade_guide_info" ]
5
+ task update: [ "update:configs", "update:bin", "update:active_storage", "update:upgrade_guide_info" ]
6
6
 
7
7
  desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
8
8
  task template: :environment do
@@ -51,6 +51,10 @@ namespace :app do
51
51
  Rails::AppUpdater.invoke_from_app_generator :update_bin_files
52
52
  end
53
53
 
54
+ task :active_storage do
55
+ Rails::AppUpdater.invoke_from_app_generator :update_active_storage
56
+ end
57
+
54
58
  task :upgrade_guide_info do
55
59
  Rails::AppUpdater.invoke_from_app_generator :display_upgrade_guide_info
56
60
  end
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- desc "Print out all defined initializers in the order they are invoked by Rails."
3
+ require "rails/command"
4
+ require "active_support/deprecation"
5
+
4
6
  task initializers: :environment do
5
- Rails.application.initializers.tsort_each do |initializer|
6
- puts "#{initializer.context_class}.#{initializer.name}"
7
- end
7
+ ActiveSupport::Deprecation.warn("Using `bin/rake initializers` is deprecated and will be removed in Rails 6.1. Use `bin/rails initializers` instead.\n")
8
+ Rails::Command.invoke "initializers"
8
9
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :log do
4
-
5
4
  ##
6
5
  # Truncates all/specified log files
7
6
  # ENV['LOGS']
@@ -1,31 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "optparse"
3
+ require "rails/command"
4
+ require "active_support/deprecation"
4
5
 
5
- desc "Print out all defined routes in match order, with names. Target specific controller with -c option, or grep routes using -g option"
6
6
  task routes: :environment do
7
- all_routes = Rails.application.routes.routes
8
- require "action_dispatch/routing/inspector"
9
- inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
10
-
11
- routes_filter = nil
12
-
13
- OptionParser.new do |opts|
14
- opts.banner = "Usage: rails routes [options]"
15
-
16
- Rake.application.standard_rake_options.each { |args| opts.on(*args) }
17
-
18
- opts.on("-c CONTROLLER") do |controller|
19
- routes_filter = { controller: controller }
20
- end
21
-
22
- opts.on("-g PATTERN") do |pattern|
23
- routes_filter = pattern
24
- end
25
-
26
- end.parse!(ARGV.reject { |x| x == "routes" })
27
-
28
- puts inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, routes_filter)
29
-
30
- exit 0 # ensure extra arguments aren't interpreted as Rake tasks
7
+ ActiveSupport::Deprecation.warn("Using `bin/rake routes` is deprecated and will be removed in Rails 6.1. Use `bin/rails routes` instead.\n")
8
+ Rails::Command.invoke "routes"
31
9
  end
@@ -11,6 +11,7 @@ STATS_DIRECTORIES = [
11
11
  %w(Mailers app/mailers),
12
12
  %w(Channels app/channels),
13
13
  %w(JavaScripts app/assets/javascripts),
14
+ %w(JavaScript app/javascript),
14
15
  %w(Libraries lib/),
15
16
  %w(APIs app/apis),
16
17
  %w(Controller\ tests test/controllers),
@@ -8,7 +8,7 @@ namespace :yarn do
8
8
  node_env = ENV.fetch("NODE_ENV") do
9
9
  valid_node_envs.include?(Rails.env) ? Rails.env : "production"
10
10
  end
11
- system({ "NODE_ENV" => node_env }, "./bin/yarn install --no-progress")
11
+ system({ "NODE_ENV" => node_env }, "#{Rails.root}/bin/yarn install --no-progress --frozen-lockfile")
12
12
  end
13
13
  end
14
14