railties 5.2.8.1 → 6.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +405 -145
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +38 -32
  5. data/README.rdoc +3 -3
  6. data/lib/minitest/rails_plugin.rb +7 -11
  7. data/lib/rails/all.rb +4 -0
  8. data/lib/rails/api/generator.rb +2 -1
  9. data/lib/rails/api/task.rb +18 -1
  10. data/lib/rails/app_loader.rb +2 -2
  11. data/lib/rails/app_updater.rb +3 -1
  12. data/lib/rails/application/bootstrap.rb +4 -12
  13. data/lib/rails/application/configuration.rb +118 -13
  14. data/lib/rails/application/default_middleware_stack.rb +4 -2
  15. data/lib/rails/application/dummy_erb_compiler.rb +18 -0
  16. data/lib/rails/application/finisher.rb +54 -0
  17. data/lib/rails/application/routes_reloader.rb +0 -1
  18. data/lib/rails/application.rb +87 -39
  19. data/lib/rails/application_controller.rb +0 -1
  20. data/lib/rails/autoloaders.rb +48 -0
  21. data/lib/rails/backtrace_cleaner.rb +5 -17
  22. data/lib/rails/code_statistics.rb +5 -3
  23. data/lib/rails/command/base.rb +12 -4
  24. data/lib/rails/command/behavior.rb +8 -49
  25. data/lib/rails/command/environment_argument.rb +8 -15
  26. data/lib/rails/command/spellchecker.rb +57 -0
  27. data/lib/rails/command.rb +11 -10
  28. data/lib/rails/commands/console/console_command.rb +6 -0
  29. data/lib/rails/commands/credentials/USAGE +19 -1
  30. data/lib/rails/commands/credentials/credentials_command.rb +52 -19
  31. data/lib/rails/commands/db/system/change/change_command.rb +20 -0
  32. data/lib/rails/commands/dbconsole/dbconsole_command.rb +20 -8
  33. data/lib/rails/commands/dev/dev_command.rb +19 -0
  34. data/lib/rails/commands/encrypted/USAGE +1 -1
  35. data/lib/rails/commands/encrypted/encrypted_command.rb +2 -2
  36. data/lib/rails/commands/help/help_command.rb +1 -1
  37. data/lib/rails/commands/initializers/initializers_command.rb +23 -0
  38. data/lib/rails/commands/new/new_command.rb +2 -2
  39. data/lib/rails/commands/notes/notes_command.rb +39 -0
  40. data/lib/rails/commands/plugin/plugin_command.rb +1 -1
  41. data/lib/rails/commands/routes/routes_command.rb +37 -0
  42. data/lib/rails/commands/runner/runner_command.rb +13 -9
  43. data/lib/rails/commands/secrets/USAGE +3 -3
  44. data/lib/rails/commands/secrets/secrets_command.rb +3 -3
  45. data/lib/rails/commands/server/server_command.rb +113 -50
  46. data/lib/rails/configuration.rb +14 -15
  47. data/lib/rails/engine/configuration.rb +5 -2
  48. data/lib/rails/engine.rb +25 -18
  49. data/lib/rails/gem_version.rb +4 -4
  50. data/lib/rails/generators/actions/create_migration.rb +0 -1
  51. data/lib/rails/generators/actions.rb +52 -40
  52. data/lib/rails/generators/app_base.rb +54 -95
  53. data/lib/rails/generators/app_name.rb +50 -0
  54. data/lib/rails/generators/base.rb +3 -3
  55. data/lib/rails/generators/database.rb +58 -0
  56. data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -2
  57. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -1
  58. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +6 -3
  59. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
  60. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +9 -1
  61. data/lib/rails/generators/erb.rb +0 -1
  62. data/lib/rails/generators/generated_attribute.rb +53 -28
  63. data/lib/rails/generators/migration.rb +1 -2
  64. data/lib/rails/generators/model_helpers.rb +8 -1
  65. data/lib/rails/generators/named_base.rb +2 -6
  66. data/lib/rails/generators/rails/app/app_generator.rb +39 -75
  67. data/lib/rails/generators/rails/app/templates/Gemfile.tt +8 -11
  68. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
  69. data/lib/rails/generators/rails/app/templates/app/{assets/javascripts/cable.js.tt → javascript/channels/consumer.js} +2 -9
  70. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
  71. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +23 -0
  72. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
  73. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
  74. data/lib/rails/generators/rails/app/templates/bin/setup.tt +7 -7
  75. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +2 -0
  76. data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
  77. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +2 -2
  78. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +2 -2
  79. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
  80. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
  81. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
  82. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
  83. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +4 -4
  84. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
  85. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +6 -6
  86. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
  87. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +2 -2
  88. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +5 -2
  89. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +28 -12
  90. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +14 -6
  91. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
  92. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +7 -0
  93. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +45 -0
  94. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  95. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +4 -3
  96. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
  97. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
  98. data/lib/rails/generators/rails/app/templates/gitignore.tt +8 -7
  99. data/lib/rails/generators/rails/app/templates/package.json.tt +7 -1
  100. data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -1
  101. data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
  102. data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
  103. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +7 -0
  104. data/lib/rails/generators/rails/assets/USAGE +1 -4
  105. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -1
  106. data/lib/rails/generators/rails/controller/controller_generator.rb +10 -1
  107. data/lib/rails/generators/rails/credentials/credentials_generator.rb +7 -8
  108. data/lib/rails/generators/rails/db/system/change/change_generator.rb +65 -0
  109. data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +10 -7
  110. data/lib/rails/generators/rails/generator/generator_generator.rb +0 -1
  111. data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
  112. data/lib/rails/generators/rails/plugin/plugin_generator.rb +9 -34
  113. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -1
  114. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
  115. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
  116. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
  117. data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
  118. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +2 -1
  119. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
  120. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
  121. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +1 -2
  122. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +13 -0
  123. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
  124. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
  125. data/lib/rails/generators/resource_helpers.rb +1 -6
  126. data/lib/rails/generators/test_unit/generator/generator_generator.rb +0 -1
  127. data/lib/rails/generators/test_unit/integration/integration_generator.rb +5 -0
  128. data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
  129. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
  130. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
  131. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +8 -4
  132. data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
  133. data/lib/rails/generators/testing/behaviour.rb +3 -1
  134. data/lib/rails/generators.rb +11 -11
  135. data/lib/rails/info.rb +3 -3
  136. data/lib/rails/info_controller.rb +1 -2
  137. data/lib/rails/mailers_controller.rb +7 -4
  138. data/lib/rails/paths.rb +18 -10
  139. data/lib/rails/rack/logger.rb +1 -2
  140. data/lib/rails/railtie/configurable.rb +0 -1
  141. data/lib/rails/railtie/configuration.rb +0 -1
  142. data/lib/rails/railtie.rb +2 -3
  143. data/lib/rails/ruby_version_check.rb +3 -3
  144. data/lib/rails/secrets.rb +0 -1
  145. data/lib/rails/source_annotation_extractor.rb +138 -117
  146. data/lib/rails/tasks/annotations.rake +9 -9
  147. data/lib/rails/tasks/dev.rake +5 -4
  148. data/lib/rails/tasks/framework.rake +6 -2
  149. data/lib/rails/tasks/initializers.rake +5 -4
  150. data/lib/rails/tasks/log.rake +0 -1
  151. data/lib/rails/tasks/routes.rake +4 -26
  152. data/lib/rails/tasks/statistics.rake +4 -0
  153. data/lib/rails/tasks/yarn.rake +1 -1
  154. data/lib/rails/tasks/zeitwerk.rake +69 -0
  155. data/lib/rails/tasks.rb +1 -0
  156. data/lib/rails/templates/rails/welcome/index.html.erb +2 -2
  157. data/lib/rails/test_help.rb +11 -9
  158. data/lib/rails/test_unit/reporter.rb +1 -1
  159. data/lib/rails/test_unit/runner.rb +14 -6
  160. data/lib/rails/test_unit/testing.rake +1 -1
  161. data/lib/rails.rb +5 -0
  162. metadata +35 -22
  163. data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
  164. data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
  165. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
  166. data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
  167. data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -34
  168. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -38
  169. data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/string/strip"
4
+
3
5
  module Rails
4
6
  module Generators
5
7
  module Actions
6
8
  def initialize(*) # :nodoc:
7
9
  super
8
- @in_group = nil
9
- @after_bundle_callbacks = []
10
+ @indentation = 0
10
11
  end
11
12
 
12
13
  # Adds an entry into +Gemfile+ for the supplied gem.
@@ -34,13 +35,11 @@ module Rails
34
35
 
35
36
  log :gemfile, message
36
37
 
37
- options.each do |option, value|
38
- parts << "#{option}: #{quote(value)}"
39
- end
38
+ parts << quote(options) unless options.empty?
40
39
 
41
40
  in_root do
42
41
  str = "gem #{parts.join(", ")}"
43
- str = " " + str if @in_group
42
+ str = indentation + str
44
43
  str = "\n" + str
45
44
  append_file "Gemfile", str, verbose: false
46
45
  end
@@ -52,17 +51,29 @@ module Rails
52
51
  # gem "rspec-rails"
53
52
  # end
54
53
  def gem_group(*names, &block)
55
- name = names.map(&:inspect).join(", ")
56
- log :gemfile, "group #{name}"
54
+ options = names.extract_options!
55
+ str = names.map(&:inspect)
56
+ str << quote(options) unless options.empty?
57
+ str = str.join(", ")
58
+ log :gemfile, "group #{str}"
57
59
 
58
60
  in_root do
59
- append_file "Gemfile", "\ngroup #{name} do", force: true
61
+ append_file "Gemfile", "\ngroup #{str} do", force: true
62
+ with_indentation(&block)
63
+ append_file "Gemfile", "\nend\n", force: true
64
+ end
65
+ end
60
66
 
61
- @in_group = true
62
- instance_eval(&block)
63
- @in_group = false
67
+ def github(repo, options = {}, &block)
68
+ str = [quote(repo)]
69
+ str << quote(options) unless options.empty?
70
+ str = str.join(", ")
71
+ log :github, "github #{str}"
64
72
 
65
- append_file "Gemfile", "\nend\n", force: true
73
+ in_root do
74
+ append_file "Gemfile", "\n#{indentation}github #{str} do", force: true
75
+ with_indentation(&block)
76
+ append_file "Gemfile", "\n#{indentation}end", force: true
66
77
  end
67
78
  end
68
79
 
@@ -81,9 +92,7 @@ module Rails
81
92
  in_root do
82
93
  if block
83
94
  append_file "Gemfile", "\nsource #{quote(source)} do", force: true
84
- @in_group = true
85
- instance_eval(&block)
86
- @in_group = false
95
+ with_indentation(&block)
87
96
  append_file "Gemfile", "\nend\n", force: true
88
97
  else
89
98
  prepend_file "Gemfile", "source #{quote(source)}\n", verbose: false
@@ -211,9 +220,12 @@ module Rails
211
220
  # generate(:authenticated, "user session")
212
221
  def generate(what, *args)
213
222
  log :generate, what
223
+
224
+ options = args.extract_options!
225
+ options[:without_rails_env] = true
214
226
  argument = args.flat_map(&:to_s).join(" ")
215
227
 
216
- in_root { run_ruby_script("bin/rails generate #{what} #{argument}", verbose: false) }
228
+ execute_command :rails, "generate #{what} #{argument}", options
217
229
  end
218
230
 
219
231
  # Runs the supplied rake task (invoked with 'rake ...')
@@ -236,15 +248,6 @@ module Rails
236
248
  execute_command :rails, command, options
237
249
  end
238
250
 
239
- # Just run the capify command in root
240
- #
241
- # capify!
242
- def capify!
243
- ActiveSupport::Deprecation.warn("`capify!` is deprecated and will be removed in the next version of Rails.")
244
- log :capify, ""
245
- in_root { run("#{extify(:capify)} .", verbose: false) }
246
- end
247
-
248
251
  # Make an entry in Rails routing file <tt>config/routes.rb</tt>
249
252
  #
250
253
  # route "root 'welcome#index'"
@@ -264,18 +267,7 @@ module Rails
264
267
  log File.read(find_in_source_paths(path))
265
268
  end
266
269
 
267
- # Registers a callback to be executed after bundle and spring binstubs
268
- # have run.
269
- #
270
- # after_bundle do
271
- # git add: '.'
272
- # end
273
- def after_bundle(&block)
274
- @after_bundle_callbacks << block
275
- end
276
-
277
270
  private
278
-
279
271
  # Define log for backwards compatibility. If just one argument is sent,
280
272
  # invoke say, otherwise invoke say_status. Differently from say and
281
273
  # similarly to say_status, this method respects the quiet? option given.
@@ -292,13 +284,15 @@ module Rails
292
284
  # based on the executor parameter provided.
293
285
  def execute_command(executor, command, options = {}) # :doc:
294
286
  log executor, command
295
- env = options[:env] || ENV["RAILS_ENV"] || "development"
287
+ env = options[:env] || ENV["RAILS_ENV"] || "development"
288
+ rails_env = " RAILS_ENV=#{env}" unless options[:without_rails_env]
296
289
  sudo = options[:sudo] && !Gem.win_platform? ? "sudo " : ""
297
290
  config = { verbose: false }
298
291
 
299
- config.merge!(capture: options[:capture]) if options[:capture]
292
+ config[:capture] = options[:capture] if options[:capture]
293
+ config[:abort_on_failure] = options[:abort_on_failure] if options[:abort_on_failure]
300
294
 
301
- in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", config) }
295
+ in_root { run("#{sudo}#{extify(executor)} #{command}#{rails_env}", config) }
302
296
  end
303
297
 
304
298
  # Add an extension to the given name based on the platform.
@@ -313,6 +307,11 @@ module Rails
313
307
  # Surround string with single quotes if there is no quotes.
314
308
  # Otherwise fall back to double quotes
315
309
  def quote(value) # :doc:
310
+ if value.respond_to? :each_pair
311
+ return value.map do |k, v|
312
+ "#{k}: #{quote(v)}"
313
+ end.join(", ")
314
+ end
316
315
  return value.inspect unless value.is_a? String
317
316
 
318
317
  if value.include?("'")
@@ -332,6 +331,19 @@ module Rails
332
331
  "#{value.strip.indent(amount)}\n"
333
332
  end
334
333
  end
334
+
335
+ # Indent the +Gemfile+ to the depth of @indentation
336
+ def indentation # :doc:
337
+ " " * @indentation
338
+ end
339
+
340
+ # Manage +Gemfile+ indentation for a DSL action block
341
+ def with_indentation(&block) # :doc:
342
+ @indentation += 1
343
+ instance_eval(&block)
344
+ ensure
345
+ @indentation -= 1
346
+ end
335
347
  end
336
348
  end
337
349
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "fileutils"
4
4
  require "digest/md5"
5
- require "active_support/core_ext/string/strip"
6
5
  require "rails/version" unless defined?(Rails::VERSION)
7
6
  require "open-uri"
8
7
  require "uri"
@@ -12,9 +11,8 @@ require "active_support/core_ext/array/extract_options"
12
11
  module Rails
13
12
  module Generators
14
13
  class AppBase < Base # :nodoc:
15
- DATABASES = %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver )
16
- JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
17
- DATABASES.concat(JDBC_DATABASES)
14
+ include Database
15
+ include AppName
18
16
 
19
17
  attr_accessor :rails_template
20
18
  add_shebang_option!
@@ -32,9 +30,6 @@ module Rails
32
30
  class_option :database, type: :string, aliases: "-d", default: "sqlite3",
33
31
  desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
34
32
 
35
- class_option :skip_yarn, type: :boolean, default: false,
36
- desc: "Don't use Yarn for managing JavaScript dependencies"
37
-
38
33
  class_option :skip_gemfile, type: :boolean, default: false,
39
34
  desc: "Don't create a Gemfile"
40
35
 
@@ -48,6 +43,12 @@ module Rails
48
43
  default: false,
49
44
  desc: "Skip Action Mailer files"
50
45
 
46
+ class_option :skip_action_mailbox, type: :boolean, default: false,
47
+ desc: "Skip Action Mailbox gem"
48
+
49
+ class_option :skip_action_text, type: :boolean, default: false,
50
+ desc: "Skip Action Text gem"
51
+
51
52
  class_option :skip_active_record, type: :boolean, aliases: "-O", default: false,
52
53
  desc: "Skip Active Record files"
53
54
 
@@ -69,10 +70,7 @@ module Rails
69
70
  class_option :skip_listen, type: :boolean, default: false,
70
71
  desc: "Don't generate configuration that depends on the listen gem"
71
72
 
72
- class_option :skip_coffee, type: :boolean, default: false,
73
- desc: "Don't use CoffeeScript"
74
-
75
- class_option :skip_javascript, type: :boolean, aliases: "-J", default: false,
73
+ class_option :skip_javascript, type: :boolean, aliases: "-J", default: name == "plugin",
76
74
  desc: "Skip JavaScript files"
77
75
 
78
76
  class_option :skip_turbolinks, type: :boolean, default: false,
@@ -107,11 +105,9 @@ module Rails
107
105
  @gem_filter = lambda { |gem| true }
108
106
  @extra_entries = []
109
107
  super
110
- convert_database_option_for_jruby
111
108
  end
112
109
 
113
110
  private
114
-
115
111
  def gemfile_entry(name, *args) # :doc:
116
112
  options = args.extract_options!
117
113
  version = args.first
@@ -131,7 +127,7 @@ module Rails
131
127
  def gemfile_entries # :doc:
132
128
  [rails_gemfile_entry,
133
129
  database_gemfile_entry,
134
- webserver_gemfile_entry,
130
+ web_server_gemfile_entry,
135
131
  assets_gemfile_entry,
136
132
  webpacker_gemfile_entry,
137
133
  javascript_gemfile_entry,
@@ -192,10 +188,10 @@ module Rails
192
188
  "Use #{options[:database]} as the database for Active Record"
193
189
  end
194
190
 
195
- def webserver_gemfile_entry # :doc:
191
+ def web_server_gemfile_entry # :doc:
196
192
  return [] if options[:skip_puma]
197
193
  comment = "Use Puma as the app server"
198
- GemfileEntry.new("puma", "~> 3.11", comment)
194
+ GemfileEntry.new("puma", "~> 4.1", comment)
199
195
  end
200
196
 
201
197
  def include_all_railties? # :doc:
@@ -207,7 +203,9 @@ module Rails
207
203
  :skip_sprockets,
208
204
  :skip_action_cable
209
205
  ),
210
- skip_active_storage?
206
+ skip_active_storage?,
207
+ skip_action_mailbox?,
208
+ skip_action_text?
211
209
  ].flatten.none?
212
210
  end
213
211
 
@@ -236,6 +234,14 @@ module Rails
236
234
  options[:skip_active_storage] || options[:skip_active_record]
237
235
  end
238
236
 
237
+ def skip_action_mailbox? # :doc:
238
+ options[:skip_action_mailbox] || skip_active_storage?
239
+ end
240
+
241
+ def skip_action_text? # :doc:
242
+ options[:skip_action_text] || skip_active_storage?
243
+ end
244
+
239
245
  class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out)
240
246
  def initialize(name, version, comment, options = {}, commented_out = false)
241
247
  super
@@ -275,12 +281,12 @@ module Rails
275
281
  ]
276
282
  elsif options.edge?
277
283
  [
278
- GemfileEntry.github("rails", "rails/rails", "5-2-stable")
284
+ GemfileEntry.github("rails", "rails/rails", "6-0-stable")
279
285
  ]
280
286
  else
281
287
  [GemfileEntry.version("rails",
282
288
  rails_version_specifier,
283
- "Bundle edge Rails instead: gem 'rails', github: 'rails/rails'")]
289
+ "Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'")]
284
290
  end
285
291
  end
286
292
 
@@ -297,90 +303,33 @@ module Rails
297
303
  end
298
304
  end
299
305
 
300
- def gem_for_database
301
- # %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql )
302
- case options[:database]
303
- when "mysql" then ["mysql2", [">= 0.4.4", "< 0.6.0"]]
304
- when "postgresql" then ["pg", [">= 0.18", "< 2.0"]]
305
- when "oracle" then ["activerecord-oracle_enhanced-adapter", nil]
306
- when "frontbase" then ["ruby-frontbase", nil]
307
- when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
308
- when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
309
- when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
310
- when "jdbcpostgresql" then ["activerecord-jdbcpostgresql-adapter", nil]
311
- when "jdbc" then ["activerecord-jdbc-adapter", nil]
312
- else [options[:database], nil]
313
- end
314
- end
315
-
316
- def convert_database_option_for_jruby
317
- if defined?(JRUBY_VERSION)
318
- opt = options.dup
319
- case opt[:database]
320
- when "postgresql" then opt[:database] = "jdbcpostgresql"
321
- when "mysql" then opt[:database] = "jdbcmysql"
322
- when "sqlite3" then opt[:database] = "jdbcsqlite3"
323
- end
324
- self.options = opt.freeze
325
- end
326
- end
327
-
328
306
  def assets_gemfile_entry
329
307
  return [] if options[:skip_sprockets]
330
308
 
331
- gems = []
332
- gems << GemfileEntry.version("sass-rails", "~> 5.0",
333
- "Use SCSS for stylesheets")
334
-
335
- if !options[:skip_javascript]
336
- gems << GemfileEntry.version("uglifier",
337
- ">= 1.3.0",
338
- "Use Uglifier as compressor for JavaScript assets")
339
- end
340
-
341
- gems
309
+ GemfileEntry.version("sass-rails", ">= 6", "Use SCSS for stylesheets")
342
310
  end
343
311
 
344
312
  def webpacker_gemfile_entry
345
- return [] unless options[:webpack]
313
+ return [] if options[:skip_javascript]
346
314
 
347
- comment = "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker"
348
- GemfileEntry.new "webpacker", nil, comment
315
+ if options.dev? || options.edge?
316
+ GemfileEntry.github "webpacker", "rails/webpacker", nil, "Use development version of Webpacker"
317
+ else
318
+ GemfileEntry.version "webpacker", "~> 4.0", "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker"
319
+ end
349
320
  end
350
321
 
351
322
  def jbuilder_gemfile_entry
352
323
  comment = "Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder"
353
- GemfileEntry.new "jbuilder", "~> 2.5", comment, {}, options[:api]
354
- end
355
-
356
- def coffee_gemfile_entry
357
- GemfileEntry.version "coffee-rails", "~> 4.2", "Use CoffeeScript for .coffee assets and views"
324
+ GemfileEntry.new "jbuilder", "~> 2.7", comment, {}, options[:api]
358
325
  end
359
326
 
360
327
  def javascript_gemfile_entry
361
- if options[:skip_javascript] || options[:skip_sprockets]
328
+ if options[:skip_javascript] || options[:skip_turbolinks]
362
329
  []
363
330
  else
364
- gems = [javascript_runtime_gemfile_entry]
365
- gems << coffee_gemfile_entry unless options[:skip_coffee]
366
-
367
- unless options[:skip_turbolinks]
368
- gems << GemfileEntry.version("turbolinks", "~> 5",
369
- "Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks")
370
- end
371
-
372
- gems
373
- end
374
- end
375
-
376
- def javascript_runtime_gemfile_entry
377
- comment = "See https://github.com/rails/execjs#readme for more supported runtimes"
378
- if defined?(JRUBY_VERSION)
379
- GemfileEntry.version "therubyrhino", nil, comment
380
- elsif RUBY_PLATFORM =~ /mingw|mswin/
381
- GemfileEntry.version "duktape", nil, comment
382
- else
383
- GemfileEntry.new "mini_racer", nil, comment, { platforms: :ruby }, true
331
+ [ GemfileEntry.version("turbolinks", "~> 5",
332
+ "Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks") ]
384
333
  end
385
334
  end
386
335
 
@@ -400,7 +349,7 @@ module Rails
400
349
  gems
401
350
  end
402
351
 
403
- def bundle_command(command)
352
+ def bundle_command(command, env = {})
404
353
  say_status :run, "bundle #{command}"
405
354
 
406
355
  # We are going to shell out rather than invoking Bundler::CLI.new(command)
@@ -413,16 +362,16 @@ module Rails
413
362
 
414
363
  require "bundler"
415
364
  Bundler.with_original_env do
416
- exec_bundle_command(_bundle_command, command)
365
+ exec_bundle_command(_bundle_command, command, env)
417
366
  end
418
367
  end
419
368
 
420
- def exec_bundle_command(bundle_command, command)
369
+ def exec_bundle_command(bundle_command, command, env)
421
370
  full_command = %Q["#{Gem.ruby}" "#{bundle_command}" #{command}]
422
371
  if options[:quiet]
423
- system(full_command, out: File::NULL)
372
+ system(env, full_command, out: File::NULL)
424
373
  else
425
- system(full_command)
374
+ system(env, full_command)
426
375
  end
427
376
  end
428
377
 
@@ -434,6 +383,10 @@ module Rails
434
383
  !options[:skip_spring] && !options.dev? && Process.respond_to?(:fork) && !RUBY_PLATFORM.include?("cygwin")
435
384
  end
436
385
 
386
+ def webpack_install?
387
+ !(options[:skip_javascript] || options[:skip_webpack_install])
388
+ end
389
+
437
390
  def depends_on_system_test?
438
391
  !(options[:skip_system_test] || options[:skip_test] || options[:api])
439
392
  end
@@ -451,13 +404,19 @@ module Rails
451
404
  end
452
405
 
453
406
  def run_bundle
454
- bundle_command("install") if bundle_install?
407
+ bundle_command("install", "BUNDLE_IGNORE_MESSAGES" => "1") if bundle_install?
455
408
  end
456
409
 
457
410
  def run_webpack
458
- if !(webpack = options[:webpack]).nil?
411
+ if webpack_install?
459
412
  rails_command "webpacker:install"
460
- rails_command "webpacker:install:#{webpack}" unless webpack == "webpack"
413
+ rails_command "webpacker:install:#{options[:webpack]}" if options[:webpack] && options[:webpack] != "webpack"
414
+ end
415
+ end
416
+
417
+ def generate_bundler_binstub
418
+ if bundle_install?
419
+ bundle_command("binstubs bundler")
461
420
  end
462
421
  end
463
422
 
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Generators
5
+ module AppName # :nodoc:
6
+ RESERVED_NAMES = %w(application destroy plugin runner test)
7
+
8
+ private
9
+ def app_name
10
+ @app_name ||= original_app_name.tr('\\', "").tr("-. ", "_")
11
+ end
12
+
13
+ def original_app_name
14
+ @original_app_name ||= defined_app_const_base? ? defined_app_name : File.basename(destination_root)
15
+ end
16
+
17
+ def defined_app_name
18
+ defined_app_const_base.underscore
19
+ end
20
+
21
+ def defined_app_const_base
22
+ Rails.respond_to?(:application) && defined?(Rails::Application) &&
23
+ Rails.application.is_a?(Rails::Application) && Rails.application.class.name.chomp("::Application")
24
+ end
25
+
26
+ alias :defined_app_const_base? :defined_app_const_base
27
+
28
+ def app_const_base
29
+ @app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, "_").squeeze("_").camelize
30
+ end
31
+ alias :camelized :app_const_base
32
+
33
+ def app_const
34
+ @app_const ||= "#{app_const_base}::Application"
35
+ end
36
+
37
+ def valid_const?
38
+ if /^\d/.match?(app_const)
39
+ raise Error, "Invalid application name #{original_app_name}. Please give a name which does not start with numbers."
40
+ elsif RESERVED_NAMES.include?(original_app_name)
41
+ raise Error, "Invalid application name #{original_app_name}. Please give a " \
42
+ "name which does not match one of the reserved rails " \
43
+ "words: #{RESERVED_NAMES.join(", ")}"
44
+ elsif Object.const_defined?(app_const_base)
45
+ raise Error, "Invalid application name #{original_app_name}, constant #{app_const_base} is already in use. Please choose another application name."
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -249,11 +249,11 @@ module Rails
249
249
  end
250
250
 
251
251
  private
252
-
253
252
  # Check whether the given class names are already taken by user
254
253
  # application or Ruby on Rails.
255
254
  def class_collisions(*class_names)
256
255
  return unless behavior == :invoke
256
+ return if options.force?
257
257
 
258
258
  class_names.flatten.each do |class_name|
259
259
  class_name = class_name.to_s
@@ -266,8 +266,8 @@ module Rails
266
266
 
267
267
  if last && last.const_defined?(last_name.camelize, false)
268
268
  raise Error, "The name '#{class_name}' is either already used in your application " \
269
- "or reserved by Ruby on Rails. Please choose an alternative and run " \
270
- "this generator again."
269
+ "or reserved by Ruby on Rails. Please choose an alternative or use " \
270
+ "--force to skip this check and run this generator again."
271
271
  end
272
272
  end
273
273
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Generators
5
+ module Database # :nodoc:
6
+ JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
7
+ DATABASES = %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver ) + JDBC_DATABASES
8
+
9
+ def initialize(*)
10
+ super
11
+ convert_database_option_for_jruby
12
+ end
13
+
14
+ def gem_for_database(database = options[:database])
15
+ case database
16
+ when "mysql" then ["mysql2", [">= 0.4.4"]]
17
+ when "postgresql" then ["pg", [">= 0.18", "< 2.0"]]
18
+ when "sqlite3" then ["sqlite3", ["~> 1.4"]]
19
+ when "oracle" then ["activerecord-oracle_enhanced-adapter", nil]
20
+ when "frontbase" then ["ruby-frontbase", nil]
21
+ when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
22
+ when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
23
+ when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
24
+ when "jdbcpostgresql" then ["activerecord-jdbcpostgresql-adapter", nil]
25
+ when "jdbc" then ["activerecord-jdbc-adapter", nil]
26
+ else [database, nil]
27
+ end
28
+ end
29
+
30
+ def convert_database_option_for_jruby
31
+ if defined?(JRUBY_VERSION)
32
+ opt = options.dup
33
+ case opt[:database]
34
+ when "postgresql" then opt[:database] = "jdbcpostgresql"
35
+ when "mysql" then opt[:database] = "jdbcmysql"
36
+ when "sqlite3" then opt[:database] = "jdbcsqlite3"
37
+ end
38
+ self.options = opt.freeze
39
+ end
40
+ end
41
+
42
+ private
43
+ def mysql_socket
44
+ @mysql_socket ||= [
45
+ "/tmp/mysql.sock", # default
46
+ "/var/run/mysqld/mysqld.sock", # debian/gentoo
47
+ "/var/tmp/mysql.sock", # freebsd
48
+ "/var/lib/mysql/mysql.sock", # fedora
49
+ "/opt/local/lib/mysql/mysql.sock", # fedora
50
+ "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
51
+ "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
52
+ "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
53
+ "/opt/lampp/var/mysql/mysql.sock" # xampp for linux
54
+ ].find { |f| File.exist?(f) } unless Gem.win_platform?
55
+ end
56
+ end
57
+ end
58
+ end
@@ -29,13 +29,12 @@ module Erb # :nodoc:
29
29
  end
30
30
 
31
31
  private
32
-
33
32
  def formats
34
33
  [:text, :html]
35
34
  end
36
35
 
37
36
  def file_name
38
- @_file_name ||= super.gsub(/_mailer/i, "")
37
+ @_file_name ||= super.sub(/_mailer\z/i, "")
39
38
  end
40
39
  end
41
40
  end
@@ -24,7 +24,6 @@ module Erb # :nodoc:
24
24
  end
25
25
 
26
26
  private
27
-
28
27
  def available_views
29
28
  %w(index edit show new _form)
30
29
  end
@@ -4,9 +4,9 @@
4
4
  <h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
5
5
 
6
6
  <ul>
7
- <%% <%= singular_table_name %>.errors.full_messages.each do |message| %>
8
- <li><%%= message %></li>
9
- <%% end %>
7
+ <%% <%= singular_table_name %>.errors.full_messages.each do |message| %>
8
+ <li><%%= message %></li>
9
+ <%% end %>
10
10
  </ul>
11
11
  </div>
12
12
  <%% end %>
@@ -21,6 +21,9 @@
21
21
  <div class="field">
22
22
  <%%= form.label :password_confirmation %>
23
23
  <%%= form.password_field :password_confirmation %>
24
+ <% elsif attribute.attachments? -%>
25
+ <%%= form.label :<%= attribute.column_name %> %>
26
+ <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true %>
24
27
  <% else -%>
25
28
  <%%= form.label :<%= attribute.column_name %> %>
26
29
  <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %>
@@ -16,7 +16,7 @@
16
16
  <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
17
17
  <tr>
18
18
  <% attributes.reject(&:password_digest?).each do |attribute| -%>
19
- <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
19
+ <td><%%= <%= singular_table_name %>.<%= attribute.column_name %> %></td>
20
20
  <% end -%>
21
21
  <td><%%= link_to 'Show', <%= model_resource_name %> %></td>
22
22
  <td><%%= link_to 'Edit', edit_<%= singular_route_name %>_path(<%= singular_table_name %>) %></td>
@@ -3,7 +3,15 @@
3
3
  <% attributes.reject(&:password_digest?).each do |attribute| -%>
4
4
  <p>
5
5
  <strong><%= attribute.human_name %>:</strong>
6
- <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
6
+ <% if attribute.attachment? -%>
7
+ <%%= link_to @<%= singular_table_name %>.<%= attribute.column_name %>.filename, @<%= singular_table_name %>.<%= attribute.column_name %> if @<%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
8
+ <% elsif attribute.attachments? -%>
9
+ <%% @<%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
10
+ <div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
11
+ <%% end %>
12
+ <% else -%>
13
+ <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>
14
+ <% end -%>
7
15
  </p>
8
16
 
9
17
  <% end -%>