railties 5.2.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +293 -89
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +39 -33
  5. data/README.rdoc +3 -3
  6. data/lib/minitest/rails_plugin.rb +24 -13
  7. data/lib/rails/all.rb +4 -0
  8. data/lib/rails/api/generator.rb +2 -1
  9. data/lib/rails/api/task.rb +17 -0
  10. data/lib/rails/app_loader.rb +2 -2
  11. data/lib/rails/app_updater.rb +4 -1
  12. data/lib/rails/application/bootstrap.rb +9 -17
  13. data/lib/rails/application/configuration.rb +177 -27
  14. data/lib/rails/application/default_middleware_stack.rb +7 -3
  15. data/lib/rails/application/dummy_erb_compiler.rb +18 -0
  16. data/lib/rails/application/finisher.rb +69 -2
  17. data/lib/rails/application/routes_reloader.rb +9 -19
  18. data/lib/rails/application.rb +96 -66
  19. data/lib/rails/application_controller.rb +0 -1
  20. data/lib/rails/autoloaders.rb +48 -0
  21. data/lib/rails/backtrace_cleaner.rb +14 -21
  22. data/lib/rails/code_statistics.rb +8 -6
  23. data/lib/rails/code_statistics_calculator.rb +6 -6
  24. data/lib/rails/command/actions.rb +10 -0
  25. data/lib/rails/command/base.rb +17 -5
  26. data/lib/rails/command/behavior.rb +8 -49
  27. data/lib/rails/command/environment_argument.rb +9 -16
  28. data/lib/rails/command/spellchecker.rb +57 -0
  29. data/lib/rails/command.rb +18 -11
  30. data/lib/rails/commands/console/console_command.rb +6 -0
  31. data/lib/rails/commands/credentials/USAGE +33 -0
  32. data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
  33. data/lib/rails/commands/credentials/credentials_command.rb +78 -21
  34. data/lib/rails/commands/db/system/change/change_command.rb +25 -0
  35. data/lib/rails/commands/dbconsole/dbconsole_command.rb +66 -51
  36. data/lib/rails/commands/dev/dev_command.rb +19 -0
  37. data/lib/rails/commands/encrypted/USAGE +28 -0
  38. data/lib/rails/commands/encrypted/encrypted_command.rb +5 -4
  39. data/lib/rails/commands/generate/generate_command.rb +1 -1
  40. data/lib/rails/commands/help/help_command.rb +1 -1
  41. data/lib/rails/commands/initializers/initializers_command.rb +23 -0
  42. data/lib/rails/commands/new/new_command.rb +2 -2
  43. data/lib/rails/commands/notes/notes_command.rb +29 -0
  44. data/lib/rails/commands/plugin/plugin_command.rb +1 -1
  45. data/lib/rails/commands/rake/rake_command.rb +9 -8
  46. data/lib/rails/commands/routes/routes_command.rb +37 -0
  47. data/lib/rails/commands/runner/runner_command.rb +13 -9
  48. data/lib/rails/commands/secrets/USAGE +6 -0
  49. data/lib/rails/commands/secrets/secrets_command.rb +3 -3
  50. data/lib/rails/commands/server/server_command.rb +92 -56
  51. data/lib/rails/commands/test/test_command.rb +2 -2
  52. data/lib/rails/configuration.rb +48 -19
  53. data/lib/rails/engine/configuration.rb +6 -2
  54. data/lib/rails/engine/updater.rb +1 -1
  55. data/lib/rails/engine.rb +63 -35
  56. data/lib/rails/gem_version.rb +2 -2
  57. data/lib/rails/generators/actions/create_migration.rb +5 -1
  58. data/lib/rails/generators/actions.rb +89 -56
  59. data/lib/rails/generators/app_base.rb +80 -108
  60. data/lib/rails/generators/app_name.rb +50 -0
  61. data/lib/rails/generators/base.rb +19 -12
  62. data/lib/rails/generators/database.rb +57 -0
  63. data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -2
  64. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -1
  65. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +7 -4
  66. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
  67. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +9 -1
  68. data/lib/rails/generators/erb.rb +0 -1
  69. data/lib/rails/generators/generated_attribute.rb +50 -31
  70. data/lib/rails/generators/migration.rb +3 -3
  71. data/lib/rails/generators/model_helpers.rb +33 -2
  72. data/lib/rails/generators/named_base.rb +3 -7
  73. data/lib/rails/generators/rails/app/USAGE +2 -1
  74. data/lib/rails/generators/rails/app/app_generator.rb +127 -84
  75. data/lib/rails/generators/rails/app/templates/Gemfile.tt +18 -21
  76. data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
  77. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
  78. data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +6 -0
  79. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
  80. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +23 -0
  81. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
  82. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +6 -5
  83. data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
  84. data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
  85. data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -9
  86. data/lib/rails/generators/rails/app/templates/bin/spring.tt +9 -0
  87. data/lib/rails/generators/rails/app/templates/bin/yarn.tt +11 -3
  88. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +16 -7
  89. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
  90. data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
  91. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +4 -5
  92. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +12 -11
  93. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +13 -12
  94. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
  95. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +13 -12
  96. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +12 -11
  97. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +16 -15
  98. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
  99. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +11 -10
  100. data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
  101. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +22 -5
  102. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +43 -17
  103. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +26 -7
  104. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
  105. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
  106. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +7 -0
  107. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
  108. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +63 -0
  109. data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
  110. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  111. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +13 -4
  112. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
  113. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
  114. data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
  115. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
  116. data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
  117. data/lib/rails/generators/rails/app/templates/gitignore.tt +10 -7
  118. data/lib/rails/generators/rails/app/templates/package.json.tt +8 -2
  119. data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -1
  120. data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
  121. data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
  122. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +9 -2
  123. data/lib/rails/generators/rails/assets/USAGE +3 -7
  124. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -1
  125. data/lib/rails/generators/rails/benchmark/USAGE +19 -0
  126. data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
  127. data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
  128. data/lib/rails/generators/rails/controller/USAGE +2 -2
  129. data/lib/rails/generators/rails/controller/controller_generator.rb +10 -39
  130. data/lib/rails/generators/rails/credentials/credentials_generator.rb +6 -7
  131. data/lib/rails/generators/rails/db/system/change/change_generator.rb +65 -0
  132. data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +10 -7
  133. data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -0
  134. data/lib/rails/generators/rails/generator/USAGE +2 -2
  135. data/lib/rails/generators/rails/generator/generator_generator.rb +0 -1
  136. data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
  137. data/lib/rails/generators/rails/helper/USAGE +2 -3
  138. data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
  139. data/lib/rails/generators/rails/integration_test/USAGE +2 -2
  140. data/lib/rails/generators/rails/migration/USAGE +4 -4
  141. data/lib/rails/generators/rails/model/USAGE +15 -16
  142. data/lib/rails/generators/rails/plugin/plugin_generator.rb +32 -56
  143. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +18 -18
  144. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
  145. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
  146. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -2
  147. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
  148. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
  149. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
  150. data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
  151. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
  152. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +14 -11
  153. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
  154. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
  155. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
  156. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
  157. data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
  158. data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
  159. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -4
  160. data/lib/rails/generators/rails/resource/USAGE +4 -4
  161. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
  162. data/lib/rails/generators/rails/scaffold/USAGE +5 -5
  163. data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
  164. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +19 -0
  165. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +2 -2
  166. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +2 -2
  167. data/lib/rails/generators/rails/system_test/USAGE +2 -2
  168. data/lib/rails/generators/rails/task/USAGE +3 -3
  169. data/lib/rails/generators/resource_helpers.rb +1 -6
  170. data/lib/rails/generators/test_case.rb +1 -1
  171. data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
  172. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
  173. data/lib/rails/generators/test_unit/generator/generator_generator.rb +0 -1
  174. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
  175. data/lib/rails/generators/test_unit/integration/integration_generator.rb +5 -0
  176. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
  177. data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
  178. data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
  179. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
  180. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
  181. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +3 -3
  182. data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
  183. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
  184. data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
  185. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +12 -3
  186. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
  187. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
  188. data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +10 -2
  189. data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
  190. data/lib/rails/generators/testing/assertions.rb +2 -2
  191. data/lib/rails/generators/testing/behaviour.rb +4 -2
  192. data/lib/rails/generators.rb +38 -24
  193. data/lib/rails/info.rb +4 -4
  194. data/lib/rails/info_controller.rb +2 -3
  195. data/lib/rails/mailers_controller.rb +10 -4
  196. data/lib/rails/paths.rb +26 -10
  197. data/lib/rails/rack/logger.rb +5 -6
  198. data/lib/rails/railtie/configurable.rb +0 -1
  199. data/lib/rails/railtie/configuration.rb +3 -3
  200. data/lib/rails/railtie.rb +33 -13
  201. data/lib/rails/ruby_version_check.rb +3 -3
  202. data/lib/rails/secrets.rb +0 -1
  203. data/lib/rails/source_annotation_extractor.rb +124 -117
  204. data/lib/rails/tasks/engine.rake +1 -4
  205. data/lib/rails/tasks/framework.rake +13 -3
  206. data/lib/rails/tasks/log.rake +0 -1
  207. data/lib/rails/tasks/misc.rake +1 -1
  208. data/lib/rails/tasks/statistics.rake +5 -1
  209. data/lib/rails/tasks/yarn.rake +14 -1
  210. data/lib/rails/tasks/zeitwerk.rake +69 -0
  211. data/lib/rails/tasks.rb +1 -4
  212. data/lib/rails/templates/rails/mailers/email.html.erb +11 -7
  213. data/lib/rails/templates/rails/welcome/index.html.erb +3 -3
  214. data/lib/rails/test_help.rb +11 -9
  215. data/lib/rails/test_unit/reporter.rb +3 -2
  216. data/lib/rails/test_unit/runner.rb +25 -8
  217. data/lib/rails/test_unit/testing.rake +7 -1
  218. data/lib/rails.rb +10 -8
  219. metadata +45 -39
  220. data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
  221. data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
  222. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
  223. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js.tt +0 -13
  224. data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
  225. data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -34
  226. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
  227. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
  228. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -35
  229. data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
  230. data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
  231. data/lib/rails/tasks/annotations.rake +0 -22
  232. data/lib/rails/tasks/dev.rake +0 -10
  233. data/lib/rails/tasks/initializers.rake +0 -8
  234. data/lib/rails/tasks/routes.rake +0 -31
data/lib/rails/paths.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
4
+
3
5
  module Rails
4
6
  module Paths
5
7
  # This object is an extended hash that behaves as root of the <tt>Rails::Paths</tt> system.
@@ -98,7 +100,6 @@ module Rails
98
100
  end
99
101
 
100
102
  private
101
-
102
103
  def filter_by(&block)
103
104
  all_paths.find_all(&block).flat_map { |path|
104
105
  paths = path.existent
@@ -113,10 +114,11 @@ module Rails
113
114
  attr_accessor :glob
114
115
 
115
116
  def initialize(root, current, paths, options = {})
116
- @paths = paths
117
- @current = current
118
- @root = root
119
- @glob = options[:glob]
117
+ @paths = paths
118
+ @current = current
119
+ @root = root
120
+ @glob = options[:glob]
121
+ @exclude = options[:exclude]
120
122
 
121
123
  options[:autoload_once] ? autoload_once! : skip_autoload_once!
122
124
  options[:eager_load] ? eager_load! : skip_eager_load!
@@ -180,6 +182,14 @@ module Rails
180
182
  @paths
181
183
  end
182
184
 
185
+ def paths
186
+ raise "You need to set a path root" unless @root.path
187
+
188
+ map do |p|
189
+ Pathname.new(@root.path).join(p)
190
+ end
191
+ end
192
+
183
193
  def extensions # :nodoc:
184
194
  $1.split(",") if @glob =~ /\{([\S]+)\}/
185
195
  end
@@ -189,13 +199,11 @@ module Rails
189
199
  raise "You need to set a path root" unless @root.path
190
200
  result = []
191
201
 
192
- each do |p|
193
- path = File.expand_path(p, @root.path)
202
+ each do |path|
203
+ path = File.expand_path(path, @root.path)
194
204
 
195
205
  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
206
+ result.concat files_in(path)
199
207
  else
200
208
  result << path
201
209
  end
@@ -222,6 +230,14 @@ module Rails
222
230
  end
223
231
 
224
232
  alias to_a expanded
233
+
234
+ private
235
+ def files_in(path)
236
+ files = Dir.glob(@glob, base: path)
237
+ files -= @exclude if @exclude
238
+ files.map! { |file| File.join(path, file) }
239
+ files.sort
240
+ end
225
241
  end
226
242
  end
227
243
  end
@@ -30,14 +30,13 @@ module Rails
30
30
  end
31
31
 
32
32
  private
33
-
34
33
  def call_app(request, env) # :doc:
35
34
  instrumenter = ActiveSupport::Notifications.instrumenter
36
35
  instrumenter.start "request.action_dispatch", request: request
37
36
  logger.info { started_request_message(request) }
38
- resp = @app.call(env)
39
- resp[2] = ::Rack::BodyProxy.new(resp[2]) { finish(request) }
40
- resp
37
+ status, headers, body = @app.call(env)
38
+ body = ::Rack::BodyProxy.new(body) { finish(request) }
39
+ [status, headers, body]
41
40
  rescue Exception
42
41
  finish(request)
43
42
  raise
@@ -48,9 +47,9 @@ module Rails
48
47
  # Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700
49
48
  def started_request_message(request) # :doc:
50
49
  'Started %s "%s" for %s at %s' % [
51
- request.request_method,
50
+ request.raw_request_method,
52
51
  request.filtered_path,
53
- request.ip,
52
+ request.remote_ip,
54
53
  Time.now.to_default_s ]
55
54
  end
56
55
 
@@ -27,7 +27,6 @@ module Rails
27
27
  end
28
28
 
29
29
  private
30
-
31
30
  def method_missing(*args, &block)
32
31
  instance.send(*args, &block)
33
32
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails/configuration"
4
+ require "active_support/core_ext/symbol/starts_ends_with"
4
5
 
5
6
  module Rails
6
7
  class Railtie
@@ -87,10 +88,9 @@ module Rails
87
88
  end
88
89
 
89
90
  private
90
-
91
91
  def method_missing(name, *args, &blk)
92
- if name.to_s =~ /=$/
93
- @@options[$`.to_sym] = args.first
92
+ if name.end_with?("=")
93
+ @@options[:"#{name[0..-2]}"] = args.first
94
94
  elsif @@options.key?(name)
95
95
  @@options[name]
96
96
  else
data/lib/rails/railtie.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails/initializable"
4
+ require "active_support/descendants_tracker"
4
5
  require "active_support/inflector"
5
6
  require "active_support/core_ext/module/introspection"
6
7
  require "active_support/core_ext/module/delegation"
@@ -42,7 +43,7 @@ module Rails
42
43
  # end
43
44
  #
44
45
  # # lib/my_gem.rb
45
- # require 'my_gem/railtie' if defined?(Rails)
46
+ # require "my_gem/railtie" if defined?(Rails::Railtie)
46
47
  #
47
48
  # == Initializers
48
49
  #
@@ -91,7 +92,7 @@ module Rails
91
92
  #
92
93
  # class MyRailtie < Rails::Railtie
93
94
  # rake_tasks do
94
- # load 'path/to/my_railtie.tasks'
95
+ # load "path/to/my_railtie.tasks"
95
96
  # end
96
97
  # end
97
98
  #
@@ -101,13 +102,30 @@ module Rails
101
102
  #
102
103
  # class MyRailtie < Rails::Railtie
103
104
  # generators do
104
- # require 'path/to/my_railtie_generator'
105
+ # require "path/to/my_railtie_generator"
105
106
  # end
106
107
  # end
107
108
  #
108
109
  # Since filenames on the load path are shared across gems, be sure that files you load
109
110
  # through a railtie have unique names.
110
111
  #
112
+ # == Run another program when the Rails server starts
113
+ #
114
+ # In development, it's very usual to have to run another process next to the Rails Server. In example
115
+ # you might want to start the Webpack or React server. Or maybe you need to run your job scheduler process
116
+ # like Sidekiq. This is usually done by opening a new shell and running the program from here.
117
+ #
118
+ # Rails allow you to specify a +server+ block which will get called when a Rails server starts.
119
+ # This way, your users don't need to remember to have to open a new shell and run another program, making
120
+ # this less confusing for everyone.
121
+ # It can be used like this:
122
+ #
123
+ # class MyRailtie < Rails::Railtie
124
+ # server do
125
+ # WebpackServer.start
126
+ # end
127
+ # end
128
+ #
111
129
  # == Application and Engine
112
130
  #
113
131
  # An engine is nothing more than a railtie with some initializers already set. And since
@@ -118,6 +136,7 @@ module Rails
118
136
  class Railtie
119
137
  autoload :Configuration, "rails/railtie/configuration"
120
138
 
139
+ extend ActiveSupport::DescendantsTracker
121
140
  include Initializable
122
141
 
123
142
  ABSTRACT_RAILTIES = %w(Rails::Railtie Rails::Engine Rails::Application)
@@ -127,13 +146,7 @@ module Rails
127
146
  delegate :config, to: :instance
128
147
 
129
148
  def subclasses
130
- @subclasses ||= []
131
- end
132
-
133
- def inherited(base)
134
- unless base.abstract_railtie?
135
- subclasses << base
136
- end
149
+ super.reject(&:abstract_railtie?)
137
150
  end
138
151
 
139
152
  def rake_tasks(&blk)
@@ -152,6 +165,10 @@ module Rails
152
165
  register_block_for(:generators, &blk)
153
166
  end
154
167
 
168
+ def server(&blk)
169
+ register_block_for(:server, &blk)
170
+ end
171
+
155
172
  def abstract_railtie?
156
173
  ABSTRACT_RAILTIES.include?(name)
157
174
  end
@@ -192,6 +209,7 @@ module Rails
192
209
  super
193
210
  end
194
211
  end
212
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
195
213
 
196
214
  # receives an instance variable identifier, set the variable value if is
197
215
  # blank and append given block to value, which will be used later in
@@ -224,11 +242,10 @@ module Rails
224
242
  end
225
243
 
226
244
  def railtie_namespace #:nodoc:
227
- @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:railtie_namespace) }
245
+ @railtie_namespace ||= self.class.module_parents.detect { |n| n.respond_to?(:railtie_namespace) }
228
246
  end
229
247
 
230
248
  protected
231
-
232
249
  def run_console_blocks(app) #:nodoc:
233
250
  each_registered_block(:console) { |block| block.call(app) }
234
251
  end
@@ -246,8 +263,11 @@ module Rails
246
263
  each_registered_block(:rake_tasks) { |block| instance_exec(app, &block) }
247
264
  end
248
265
 
249
- private
266
+ def run_server_blocks(app) #:nodoc:
267
+ each_registered_block(:server) { |block| block.call(app) }
268
+ end
250
269
 
270
+ private
251
271
  # run `&block` in every registered block in `#register_block_for`
252
272
  def each_registered_block(type, &block)
253
273
  klass = self.class
@@ -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,148 @@
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
+ module Rails
4
+ # Implements the logic behind <tt>Rails::Command::NotesCommand</tt>. See <tt>rails notes --help</tt> for usage information.
5
+ #
6
+ # Annotation objects are triplets <tt>:line</tt>, <tt>:tag</tt>, <tt>:text</tt> that
7
+ # represent the line where the annotation lives, its tag, and its text. Note
8
+ # the filename is not stored.
9
+ #
10
+ # Annotations are looked for in comments and modulus whitespace they have to
11
+ # start with the tag optionally followed by a colon. Everything up to the end
12
+ # of the line (or closing ERB comment tag) is considered to be their text.
13
+ class SourceAnnotationExtractor
14
+ class Annotation < Struct.new(:line, :tag, :text)
15
+ def self.directories
16
+ @@directories ||= %w(app config db lib test)
17
+ end
22
18
 
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
19
+ # Registers additional directories to be included
20
+ # Rails::SourceAnnotationExtractor::Annotation.register_directories("spec", "another")
21
+ def self.register_directories(*dirs)
22
+ directories.push(*dirs)
23
+ end
28
24
 
29
- def self.extensions
30
- @@extensions ||= {}
31
- end
25
+ def self.tags
26
+ @@tags ||= %w(OPTIMIZE FIXME TODO)
27
+ end
32
28
 
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
29
+ # Registers additional tags
30
+ # Rails::SourceAnnotationExtractor::Annotation.register_tags("TESTME", "DEPRECATEME")
31
+ def self.register_tags(*additional_tags)
32
+ tags.push(*additional_tags)
33
+ end
38
34
 
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*%>/ }
35
+ def self.extensions
36
+ @@extensions ||= {}
37
+ end
42
38
 
43
- # Returns a representation of the annotation that looks like this:
39
+ # Registers new Annotations File Extensions
40
+ # Rails::SourceAnnotationExtractor::Annotation.register_extensions("css", "scss", "sass", "less", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
41
+ def self.register_extensions(*exts, &block)
42
+ extensions[/\.(#{exts.join("|")})$/] = block
43
+ end
44
+
45
+ register_extensions("builder", "rb", "rake", "yml", "yaml", "ruby") { |tag| /#\s*(#{tag}):?\s*(.*)$/ }
46
+ register_extensions("css", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
47
+ register_extensions("erb") { |tag| /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/ }
48
+
49
+ # Returns a representation of the annotation that looks like this:
50
+ #
51
+ # [126] [TODO] This algorithm is simple and clearly correct, make it faster.
52
+ #
53
+ # If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
54
+ # Otherwise the string contains just line and text.
55
+ def to_s(options = {})
56
+ s = +"[#{line.to_s.rjust(options[:indent])}] "
57
+ s << "[#{tag}] " if options[:tag]
58
+ s << text
59
+ end
60
+ end
61
+
62
+ # Prints all annotations with tag +tag+ under the root directories +app+,
63
+ # +config+, +db+, +lib+, and +test+ (recursively).
44
64
  #
45
- # [126] [TODO] This algorithm is simple and clearly correct, make it faster.
65
+ # If +tag+ is <tt>nil</tt>, annotations with either default or registered tags are printed.
46
66
  #
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
67
+ # Specific directories can be explicitly set using the <tt>:dirs</tt> key in +options+.
68
+ #
69
+ # Rails::SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true
70
+ #
71
+ # If +options+ has a <tt>:tag</tt> flag, it will be passed to each annotation's +to_s+.
72
+ #
73
+ # See <tt>#find_in</tt> for a list of file extensions that will be taken into account.
74
+ #
75
+ # This class method is the single entry point for the `rails notes` command.
76
+ def self.enumerate(tag = nil, options = {})
77
+ tag ||= Annotation.tags.join("|")
78
+ extractor = new(tag)
79
+ dirs = options.delete(:dirs) || Annotation.directories
80
+ extractor.display(extractor.find(dirs), options)
53
81
  end
54
- end
55
82
 
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
83
+ attr_reader :tag
82
84
 
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
85
+ def initialize(tag)
86
+ @tag = tag
87
+ end
88
88
 
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
89
+ # Returns a hash that maps filenames under +dirs+ (recursively) to arrays
90
+ # with their annotations.
91
+ def find(dirs)
92
+ dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
93
+ end
105
94
 
106
- if extension
107
- pattern = extension.last.call(tag)
108
- results.update(extract_annotations_from(item, pattern)) if pattern
95
+ # Returns a hash that maps filenames under +dir+ (recursively) to arrays
96
+ # with their annotations. Files with extensions registered in
97
+ # <tt>Rails::SourceAnnotationExtractor::Annotation.extensions</tt> are
98
+ # taken into account. Only files with annotations are included.
99
+ def find_in(dir)
100
+ results = {}
101
+
102
+ Dir.glob("#{dir}/*") do |item|
103
+ next if File.basename(item).start_with?(".")
104
+
105
+ if File.directory?(item)
106
+ results.update(find_in(item))
107
+ else
108
+ extension = Annotation.extensions.detect do |regexp, _block|
109
+ regexp.match(item)
110
+ end
111
+
112
+ if extension
113
+ pattern = extension.last.call(tag)
114
+ results.update(extract_annotations_from(item, pattern)) if pattern
115
+ end
109
116
  end
110
117
  end
111
- end
112
118
 
113
- results
114
- end
119
+ results
120
+ end
115
121
 
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)
122
+ # If +file+ is the filename of a file that contains annotations this method returns
123
+ # a hash with a single entry that maps +file+ to an array of its annotations.
124
+ # Otherwise it returns an empty hash.
125
+ def extract_annotations_from(file, pattern)
126
+ lineno = 0
127
+ result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
128
+ lineno += 1
129
+ next list unless line =~ pattern
130
+ list << Annotation.new(lineno, $1, $2)
131
+ end
132
+ result.empty? ? {} : { file => result }
125
133
  end
126
- result.empty? ? {} : { file => result }
127
- end
128
134
 
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)}"
135
+ # Prints the mapping from filenames to annotations in +results+ ordered by filename.
136
+ # The +options+ hash is passed to each annotation's +to_s+.
137
+ def display(results, options = {})
138
+ options[:indent] = results.flat_map { |f, a| a.map(&:line) }.max.to_s.size
139
+ results.keys.sort.each do |file|
140
+ puts "#{file}:"
141
+ results[file].each do |note|
142
+ puts " * #{note.to_s(options)}"
143
+ end
144
+ puts
137
145
  end
138
- puts
139
146
  end
140
147
  end
141
148
  end
@@ -53,7 +53,7 @@ namespace :db do
53
53
  desc "Rolls the schema back to the previous version (specify steps w/ STEP=n)."
54
54
  app_task "rollback"
55
55
 
56
- desc "Create a db/schema.rb file that can be portably used against any database supported by Active Record"
56
+ desc "Creates a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`)"
57
57
  app_task "schema:dump"
58
58
 
59
59
  desc "Load a schema.rb file into the database"
@@ -65,9 +65,6 @@ namespace :db do
65
65
  desc "Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the database first)"
66
66
  app_task "setup"
67
67
 
68
- desc "Dump the database structure to an SQL file"
69
- app_task "structure:dump"
70
-
71
68
  desc "Retrieves the current schema version number"
72
69
  app_task "version"
73
70
 
@@ -2,13 +2,13 @@
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
9
9
  template = ENV["LOCATION"]
10
10
  raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank?
11
- template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
11
+ template = File.expand_path(template) unless %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}.match?(template)
12
12
  require "rails/generators"
13
13
  require "rails/generators/rails/app/app_generator"
14
14
  generator = Rails::Generators::AppGenerator.new [Rails.root], {}, { destination_root: Rails.root }
@@ -40,7 +40,7 @@ namespace :app do
40
40
  namespace :update do
41
41
  require "rails/app_updater"
42
42
 
43
- # desc "Update config/boot.rb from your current rails install"
43
+ # desc "Update config files from your current rails install"
44
44
  task :configs do
45
45
  Rails::AppUpdater.invoke_from_app_generator :create_boot_file
46
46
  Rails::AppUpdater.invoke_from_app_generator :update_config_files
@@ -51,8 +51,18 @@ 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
57
61
  end
62
+
63
+ namespace :binstub do
64
+ task :yarn do
65
+ Rails::AppUpdater.invoke_from_app_generator :update_bin_yarn
66
+ end
67
+ end
58
68
  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']
@@ -12,7 +12,7 @@ task about: :environment do
12
12
  end
13
13
 
14
14
  namespace :time do
15
- desc "List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)"
15
+ desc "List all time zones, list by two-letter country code (`bin/rails time:zones[US]`), or list by UTC offset (`bin/rails time:zones[-8]`)"
16
16
  task :zones, :country_or_offset do |t, args|
17
17
  zones, offset = ActiveSupport::TimeZone.all, nil
18
18
 
@@ -3,20 +3,24 @@
3
3
  # While global constants are bad, many 3rd party tools depend on this one (e.g
4
4
  # rspec-rails & cucumber-rails). So a deprecation warning is needed if we want
5
5
  # to remove it.
6
- STATS_DIRECTORIES = [
6
+ STATS_DIRECTORIES ||= [
7
7
  %w(Controllers app/controllers),
8
8
  %w(Helpers app/helpers),
9
9
  %w(Jobs app/jobs),
10
10
  %w(Models app/models),
11
11
  %w(Mailers app/mailers),
12
+ %w(Mailboxes app/mailboxes),
12
13
  %w(Channels app/channels),
13
14
  %w(JavaScripts app/assets/javascripts),
15
+ %w(JavaScript app/javascript),
14
16
  %w(Libraries lib/),
15
17
  %w(APIs app/apis),
16
18
  %w(Controller\ tests test/controllers),
17
19
  %w(Helper\ tests test/helpers),
18
20
  %w(Model\ tests test/models),
19
21
  %w(Mailer\ tests test/mailers),
22
+ %w(Mailbox\ tests test/mailboxes),
23
+ %w(Channel\ tests test/channels),
20
24
  %w(Job\ tests test/jobs),
21
25
  %w(Integration\ tests test/integration),
22
26
  %w(System\ tests test/system),