railties 6.0.3.3 → 6.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +234 -370
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +1 -1
  5. data/lib/minitest/rails_plugin.rb +16 -1
  6. data/lib/rails.rb +5 -8
  7. data/lib/rails/application.rb +49 -83
  8. data/lib/rails/application/bootstrap.rb +5 -5
  9. data/lib/rails/application/configuration.rb +71 -21
  10. data/lib/rails/application/default_middleware_stack.rb +5 -3
  11. data/lib/rails/application/finisher.rb +15 -2
  12. data/lib/rails/application/routes_reloader.rb +9 -2
  13. data/lib/rails/backtrace_cleaner.rb +12 -7
  14. data/lib/rails/code_statistics.rb +3 -3
  15. data/lib/rails/code_statistics_calculator.rb +6 -6
  16. data/lib/rails/command.rb +7 -1
  17. data/lib/rails/command/base.rb +1 -1
  18. data/lib/rails/command/behavior.rb +1 -1
  19. data/lib/rails/command/environment_argument.rb +1 -1
  20. data/lib/rails/commands/credentials/USAGE +17 -2
  21. data/lib/rails/commands/credentials/credentials_command.rb +28 -4
  22. data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
  23. data/lib/rails/commands/db/system/change/change_command.rb +6 -1
  24. data/lib/rails/commands/dbconsole/dbconsole_command.rb +61 -58
  25. data/lib/rails/commands/encrypted/encrypted_command.rb +4 -4
  26. data/lib/rails/commands/generate/generate_command.rb +1 -1
  27. data/lib/rails/commands/notes/notes_command.rb +1 -11
  28. data/lib/rails/commands/rake/rake_command.rb +9 -8
  29. data/lib/rails/commands/secrets/USAGE +9 -3
  30. data/lib/rails/commands/server/server_command.rb +14 -41
  31. data/lib/rails/commands/test/test_command.rb +2 -2
  32. data/lib/rails/configuration.rb +40 -10
  33. data/lib/rails/engine.rb +35 -32
  34. data/lib/rails/engine/configuration.rb +1 -0
  35. data/lib/rails/engine/updater.rb +1 -1
  36. data/lib/rails/gem_version.rb +3 -3
  37. data/lib/rails/generators.rb +29 -15
  38. data/lib/rails/generators/actions.rb +50 -29
  39. data/lib/rails/generators/actions/create_migration.rb +5 -0
  40. data/lib/rails/generators/app_base.rb +38 -21
  41. data/lib/rails/generators/base.rb +14 -11
  42. data/lib/rails/generators/database.rb +3 -4
  43. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +3 -3
  44. data/lib/rails/generators/generated_attribute.rb +3 -9
  45. data/lib/rails/generators/migration.rb +2 -1
  46. data/lib/rails/generators/model_helpers.rb +26 -2
  47. data/lib/rails/generators/named_base.rb +1 -1
  48. data/lib/rails/generators/rails/app/USAGE +2 -1
  49. data/lib/rails/generators/rails/app/app_generator.rb +89 -15
  50. data/lib/rails/generators/rails/app/templates/Gemfile.tt +11 -11
  51. data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
  52. data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +1 -1
  53. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +11 -11
  54. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +2 -1
  55. data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
  56. data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
  57. data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -4
  58. data/lib/rails/generators/rails/app/templates/bin/spring.tt +13 -0
  59. data/lib/rails/generators/rails/app/templates/bin/yarn.tt +9 -3
  60. data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
  61. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +14 -7
  62. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
  63. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +3 -4
  64. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +10 -9
  65. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +11 -10
  66. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +10 -9
  67. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +11 -10
  68. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -10
  69. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +10 -9
  70. data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
  71. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +17 -3
  72. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +15 -5
  73. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -1
  74. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
  75. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
  76. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +67 -0
  77. data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
  78. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +6 -1
  79. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
  80. data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
  81. data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
  82. data/lib/rails/generators/rails/app/templates/package.json.tt +1 -1
  83. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +5 -5
  84. data/lib/rails/generators/rails/assets/USAGE +2 -3
  85. data/lib/rails/generators/rails/benchmark/USAGE +19 -0
  86. data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
  87. data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
  88. data/lib/rails/generators/rails/controller/USAGE +2 -2
  89. data/lib/rails/generators/rails/controller/controller_generator.rb +2 -40
  90. data/lib/rails/generators/rails/credentials/credentials_generator.rb +1 -1
  91. data/lib/rails/generators/rails/generator/USAGE +2 -2
  92. data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
  93. data/lib/rails/generators/rails/helper/USAGE +2 -3
  94. data/lib/rails/generators/rails/integration_test/USAGE +2 -2
  95. data/lib/rails/generators/rails/migration/USAGE +4 -4
  96. data/lib/rails/generators/rails/model/USAGE +15 -16
  97. data/lib/rails/generators/rails/plugin/plugin_generator.rb +25 -23
  98. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +10 -19
  99. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
  100. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
  101. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +0 -1
  102. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
  103. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +13 -11
  104. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
  105. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
  107. data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
  108. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -3
  109. data/lib/rails/generators/rails/resource/USAGE +4 -4
  110. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
  111. data/lib/rails/generators/rails/scaffold/USAGE +5 -5
  112. data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
  113. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +6 -0
  114. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
  115. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
  116. data/lib/rails/generators/rails/system_test/USAGE +2 -2
  117. data/lib/rails/generators/rails/task/USAGE +3 -3
  118. data/lib/rails/generators/test_case.rb +1 -1
  119. data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
  120. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
  121. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
  122. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
  123. data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
  124. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
  125. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +1 -1
  126. data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
  127. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
  128. data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
  129. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
  130. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
  131. data/lib/rails/generators/testing/assertions.rb +2 -2
  132. data/lib/rails/generators/testing/behaviour.rb +1 -1
  133. data/lib/rails/info.rb +1 -1
  134. data/lib/rails/info_controller.rb +1 -1
  135. data/lib/rails/mailers_controller.rb +1 -0
  136. data/lib/rails/paths.rb +14 -6
  137. data/lib/rails/rack/logger.rb +1 -1
  138. data/lib/rails/railtie.rb +32 -10
  139. data/lib/rails/railtie/configuration.rb +3 -2
  140. data/lib/rails/source_annotation_extractor.rb +1 -15
  141. data/lib/rails/tasks.rb +0 -4
  142. data/lib/rails/tasks/engine.rake +1 -4
  143. data/lib/rails/tasks/framework.rake +7 -1
  144. data/lib/rails/tasks/misc.rake +1 -1
  145. data/lib/rails/tasks/statistics.rake +1 -1
  146. data/lib/rails/tasks/yarn.rake +14 -2
  147. data/lib/rails/templates/rails/mailers/email.html.erb +1 -0
  148. data/lib/rails/templates/rails/welcome/index.html.erb +1 -1
  149. data/lib/rails/test_unit/reporter.rb +2 -1
  150. data/lib/rails/test_unit/runner.rb +20 -3
  151. data/lib/rails/test_unit/testing.rake +6 -0
  152. metadata +27 -33
  153. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
  154. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
  155. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +0 -45
  156. data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
  157. data/lib/rails/tasks/annotations.rake +0 -22
  158. data/lib/rails/tasks/dev.rake +0 -11
  159. data/lib/rails/tasks/initializers.rake +0 -9
  160. data/lib/rails/tasks/routes.rake +0 -9
@@ -19,7 +19,9 @@ module Rails
19
19
  include Rails::Generators::Actions
20
20
 
21
21
  class_option :skip_namespace, type: :boolean, default: false,
22
- desc: "Skip namespace (affects only isolated applications)"
22
+ desc: "Skip namespace (affects only isolated engines)"
23
+ class_option :skip_collision_check, type: :boolean, default: false,
24
+ desc: "Skip collision check"
23
25
 
24
26
  add_runtime_options!
25
27
  strict_args_position!
@@ -51,7 +53,7 @@ module Rails
51
53
  # is removed.
52
54
  def self.namespace(name = nil)
53
55
  return super if name
54
- @namespace ||= super.sub(/_generator$/, "").sub(/:generators:/, ":")
56
+ @namespace ||= super.delete_suffix("_generator").sub(/:generators:/, ":")
55
57
  end
56
58
 
57
59
  # Convenience method to hide this generator from the available ones when
@@ -77,7 +79,7 @@ module Rails
77
79
  #
78
80
  # For example, if the user invoke the controller generator as:
79
81
  #
80
- # rails generate controller Account --test-framework=test_unit
82
+ # bin/rails generate controller Account --test-framework=test_unit
81
83
  #
82
84
  # The controller generator will then try to invoke the following generators:
83
85
  #
@@ -132,11 +134,11 @@ module Rails
132
134
  # All hooks come with switches for user interface. If you do not want
133
135
  # to use any test framework, you can do:
134
136
  #
135
- # rails generate controller Account --skip-test-framework
137
+ # bin/rails generate controller Account --skip-test-framework
136
138
  #
137
139
  # Or similarly:
138
140
  #
139
- # rails generate controller Account --no-test-framework
141
+ # bin/rails generate controller Account --no-test-framework
140
142
  #
141
143
  # ==== Boolean hooks
142
144
  #
@@ -148,7 +150,7 @@ module Rails
148
150
  #
149
151
  # Then, if you want webrat to be invoked, just supply:
150
152
  #
151
- # rails generate controller Account --webrat
153
+ # bin/rails generate controller Account --webrat
152
154
  #
153
155
  # The hooks lookup is similar as above:
154
156
  #
@@ -235,7 +237,7 @@ module Rails
235
237
  # Invoke source_root so the default_source_root is set.
236
238
  base.source_root
237
239
 
238
- if base.name && base.name !~ /Base$/
240
+ if base.name && !base.name.end_with?("Base")
239
241
  Rails::Generators.subclasses << base
240
242
 
241
243
  Rails::Generators.templates_path.each do |path|
@@ -253,6 +255,7 @@ module Rails
253
255
  # application or Ruby on Rails.
254
256
  def class_collisions(*class_names)
255
257
  return unless behavior == :invoke
258
+ return if options.skip_collision_check?
256
259
  return if options.force?
257
260
 
258
261
  class_names.flatten.each do |class_name|
@@ -266,8 +269,8 @@ module Rails
266
269
 
267
270
  if last && last.const_defined?(last_name.camelize, false)
268
271
  raise Error, "The name '#{class_name}' is either already used in your application " \
269
- "or reserved by Ruby on Rails. Please choose an alternative or use " \
270
- "--force to skip this check and run this generator again."
272
+ "or reserved by Ruby on Rails. Please choose an alternative or use --skip-collision-check " \
273
+ "or --force to skip this check and run this generator again."
271
274
  end
272
275
  end
273
276
  end
@@ -316,7 +319,7 @@ module Rails
316
319
 
317
320
  # Use Rails default banner.
318
321
  def self.banner # :doc:
319
- "rails generate #{namespace.sub(/^rails:/, '')} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ")
322
+ "rails generate #{namespace.delete_prefix("rails:")} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ")
320
323
  end
321
324
 
322
325
  # Sets the base_name taking into account the current class namespace.
@@ -333,7 +336,7 @@ module Rails
333
336
  def self.generator_name # :doc:
334
337
  @generator_name ||= begin
335
338
  if generator = name.to_s.split("::").last
336
- generator.sub!(/Generator$/, "")
339
+ generator.delete_suffix!("Generator")
337
340
  generator.underscore
338
341
  end
339
342
  end
@@ -4,7 +4,7 @@ module Rails
4
4
  module Generators
5
5
  module Database # :nodoc:
6
6
  JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
7
- DATABASES = %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver ) + JDBC_DATABASES
7
+ DATABASES = %w( mysql postgresql sqlite3 oracle sqlserver ) + JDBC_DATABASES
8
8
 
9
9
  def initialize(*)
10
10
  super
@@ -13,11 +13,10 @@ module Rails
13
13
 
14
14
  def gem_for_database(database = options[:database])
15
15
  case database
16
- when "mysql" then ["mysql2", [">= 0.4.4"]]
17
- when "postgresql" then ["pg", [">= 0.18", "< 2.0"]]
16
+ when "mysql" then ["mysql2", ["~> 0.5"]]
17
+ when "postgresql" then ["pg", ["~> 1.1"]]
18
18
  when "sqlite3" then ["sqlite3", ["~> 1.4"]]
19
19
  when "oracle" then ["activerecord-oracle_enhanced-adapter", nil]
20
- when "frontbase" then ["ruby-frontbase", nil]
21
20
  when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
22
21
  when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
23
22
  when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
@@ -1,11 +1,11 @@
1
- <%%= form_with(model: <%= model_resource_name %>, local: true) do |form| %>
1
+ <%%= form_with(model: <%= model_resource_name %>) do |form| %>
2
2
  <%% if <%= singular_table_name %>.errors.any? %>
3
3
  <div id="error_explanation">
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>
7
+ <%% <%= singular_table_name %>.errors.each do |error| %>
8
+ <li><%%= error.full_message %></li>
9
9
  <%% end %>
10
10
  </ul>
11
11
  </div>
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/time"
4
- require "active_support/deprecation"
5
4
 
6
5
  module Rails
7
6
  module Generators
@@ -52,11 +51,6 @@ module Rails
52
51
  provided_options = $2.split(/[,.-]/)
53
52
  options = Hash[provided_options.map { |opt| [opt.to_sym, true] }]
54
53
 
55
- if options[:required]
56
- ActiveSupport::Deprecation.warn("Passing {required} option has no effect on the model generator. It will be removed in Rails 6.1.\n")
57
- options.delete(:required)
58
- end
59
-
60
54
  return type, options
61
55
  else
62
56
  return type, {}
@@ -107,11 +101,11 @@ module Rails
107
101
  end
108
102
 
109
103
  def plural_name
110
- name.sub(/_id$/, "").pluralize
104
+ name.delete_suffix("_id").pluralize
111
105
  end
112
106
 
113
107
  def singular_name
114
- name.sub(/_id$/, "").singularize
108
+ name.delete_suffix("_id").singularize
115
109
  end
116
110
 
117
111
  def human_name
@@ -131,7 +125,7 @@ module Rails
131
125
  end
132
126
 
133
127
  def foreign_key?
134
- !!(name =~ /_id$/)
128
+ name.end_with?("_id")
135
129
  end
136
130
 
137
131
  def reference?
@@ -62,13 +62,14 @@ module Rails
62
62
  dir, base = File.split(destination)
63
63
  numbered_destination = File.join(dir, ["%migration_number%", base].join("_"))
64
64
 
65
- create_migration numbered_destination, nil, config do
65
+ file = create_migration numbered_destination, nil, config do
66
66
  if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
67
67
  ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(context)
68
68
  else
69
69
  ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
70
70
  end
71
71
  end
72
+ Rails::Generators.add_generated_file(file)
72
73
  end
73
74
  end
74
75
  end
@@ -11,6 +11,11 @@ module Rails
11
11
  [WARNING] Rails cannot recover singular form from its plural form '%s'.
12
12
  Please setup custom inflection rules for this noun before running the generator in config/initializers/inflections.rb.
13
13
  WARNING
14
+ INFLECTION_IMPOSSIBLE_ERROR_MESSAGE = <<~ERROR
15
+ Rails cannot recover the underscored form from its camelcase form '%s'.
16
+ Please use an underscored name instead, either '%s' or '%s'.
17
+ Or setup custom inflection rules for this noun before running the generator in config/initializers/inflections.rb.
18
+ ERROR
14
19
  mattr_accessor :skip_warn
15
20
 
16
21
  def self.included(base) #:nodoc:
@@ -19,7 +24,7 @@ module Rails
19
24
 
20
25
  def initialize(args, *_options)
21
26
  super
22
- if name == name.pluralize && name.singularize != name.pluralize && !options[:force_plural]
27
+ if plural_model_name?(name) && !options[:force_plural]
23
28
  singular = name.singularize
24
29
  unless ModelHelpers.skip_warn
25
30
  say PLURAL_MODEL_NAME_WARN_MESSAGE % [name, singular]
@@ -27,11 +32,30 @@ module Rails
27
32
  name.replace singular
28
33
  assign_names!(name)
29
34
  end
30
- if name.singularize != name.pluralize.singularize && ! ModelHelpers.skip_warn
35
+ if inflection_impossible?(name)
36
+ option1 = name.singularize.underscore
37
+ option2 = name.pluralize.underscore.singularize
38
+ raise Error, INFLECTION_IMPOSSIBLE_ERROR_MESSAGE % [name, option1, option2]
39
+ end
40
+ if irregular_model_name?(name) && ! ModelHelpers.skip_warn
31
41
  say IRREGULAR_MODEL_NAME_WARN_MESSAGE % [name.pluralize]
32
42
  end
33
43
  ModelHelpers.skip_warn = true
34
44
  end
45
+
46
+ private
47
+ def plural_model_name?(name)
48
+ name == name.pluralize && name.singularize != name.pluralize
49
+ end
50
+
51
+ def irregular_model_name?(name)
52
+ name.singularize != name.pluralize.singularize
53
+ end
54
+
55
+ def inflection_impossible?(name)
56
+ name != name.underscore &&
57
+ name.singularize.underscore != name.pluralize.underscore.singularize
58
+ end
35
59
  end
36
60
  end
37
61
  end
@@ -22,7 +22,7 @@ module Rails
22
22
  no_tasks do
23
23
  def template(source, *args, &block)
24
24
  inside_template do
25
- super
25
+ Rails::Generators.add_generated_file(super)
26
26
  end
27
27
  end
28
28
 
@@ -3,7 +3,8 @@ Description:
3
3
  directory structure and configuration at the path you specify.
4
4
 
5
5
  You can specify extra command-line arguments to be used every time
6
- 'rails new' runs in the .railsrc configuration file in your home directory.
6
+ 'rails new' runs in the .railsrc configuration file in your home directory,
7
+ or in $XDG_CONFIG_HOME/rails/railsrc if XDG_CONFIG_HOME is set.
7
8
 
8
9
  Note that the arguments specified in the .railsrc file don't affect the
9
10
  defaults values shown above in this help message.
@@ -66,6 +66,10 @@ module Rails
66
66
  template "gitignore", ".gitignore"
67
67
  end
68
68
 
69
+ def gitattributes
70
+ template "gitattributes", ".gitattributes"
71
+ end
72
+
69
73
  def version_control
70
74
  if !options[:skip_git] && !options[:pretend]
71
75
  run "git init", capture: options[:quiet], abort_on_failure: false
@@ -90,14 +94,23 @@ module Rails
90
94
  "#{shebang}\n" + content
91
95
  end
92
96
  chmod "bin", 0755 & ~File.umask, verbose: false
97
+
98
+ remove_file "bin/spring" unless spring_install?
99
+ remove_file "bin/yarn" if options[:skip_javascript]
93
100
  end
94
101
 
95
102
  def bin_when_updating
96
103
  bin
104
+ end
97
105
 
98
- if options[:skip_javascript]
99
- remove_file "bin/yarn"
106
+ def yarn_when_updating
107
+ return if File.exist?("bin/yarn")
108
+
109
+ template "bin/yarn" do |content|
110
+ "#{shebang}\n" + content
100
111
  end
112
+
113
+ chmod "bin", 0755 & ~File.umask, verbose: false
101
114
  end
102
115
 
103
116
  def config
@@ -125,10 +138,12 @@ module Rails
125
138
  rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
126
139
  assets_config_exist = File.exist?("config/initializers/assets.rb")
127
140
  csp_config_exist = File.exist?("config/initializers/content_security_policy.rb")
141
+ permissions_policy_config_exist = File.exist?("config/initializers/permissions_policy.rb")
128
142
 
129
143
  @config_target_version = Rails.application.config.loaded_config_version || "5.0"
130
144
 
131
145
  config
146
+ configru
132
147
 
133
148
  unless cookie_serializer_config_exist
134
149
  gsub_file "config/initializers/cookies_serializer.rb", /json(?!,)/, "marshal"
@@ -158,6 +173,10 @@ module Rails
158
173
  unless csp_config_exist
159
174
  remove_file "config/initializers/content_security_policy.rb"
160
175
  end
176
+
177
+ unless permissions_policy_config_exist
178
+ remove_file "config/initializers/permissions_policy.rb"
179
+ end
161
180
  end
162
181
  end
163
182
 
@@ -205,7 +224,6 @@ module Rails
205
224
  end
206
225
 
207
226
  def test
208
- empty_directory_with_keep_file "test/fixtures"
209
227
  empty_directory_with_keep_file "test/fixtures/files"
210
228
  empty_directory_with_keep_file "test/controllers"
211
229
  empty_directory_with_keep_file "test/mailers"
@@ -244,7 +262,9 @@ module Rails
244
262
  # can change in Ruby 1.8.7 when we FileUtils.cd.
245
263
  RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__)
246
264
 
247
- class AppGenerator < AppBase # :nodoc:
265
+ class AppGenerator < AppBase
266
+ # :stopdoc:
267
+
248
268
  WEBPACKS = %w( react vue angular elm stimulus )
249
269
 
250
270
  add_shared_options_for "application"
@@ -256,6 +276,9 @@ module Rails
256
276
  class_option :api, type: :boolean,
257
277
  desc: "Preconfigure smaller stack for API only apps"
258
278
 
279
+ class_option :minimal, type: :boolean,
280
+ desc: "Preconfigure a minimal rails app"
281
+
259
282
  class_option :skip_bundle, type: :boolean, aliases: "-B", default: false,
260
283
  desc: "Don't run bundle install"
261
284
 
@@ -278,6 +301,29 @@ module Rails
278
301
  self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze
279
302
  end
280
303
 
304
+ if options[:minimal]
305
+ self.options = options.merge(
306
+ skip_action_cable: true,
307
+ skip_action_mailer: true,
308
+ skip_action_mailbox: true,
309
+ skip_action_text: true,
310
+ skip_active_job: true,
311
+ skip_active_storage: true,
312
+ skip_bootsnap: true,
313
+ skip_dev_gems: true,
314
+ skip_javascript: true,
315
+ skip_jbuilder: true,
316
+ skip_spring: true,
317
+ skip_system_test: true,
318
+ skip_webpack_install: true,
319
+ skip_turbolinks: true).tap do |option|
320
+ if option[:webpack]
321
+ option[:skip_webpack_install] = false
322
+ option[:skip_javascript] = false
323
+ end
324
+ end.freeze
325
+ end
326
+
281
327
  @after_bundle_callbacks = []
282
328
  end
283
329
 
@@ -289,8 +335,13 @@ module Rails
289
335
  build(:rakefile)
290
336
  build(:ruby_version)
291
337
  build(:configru)
292
- build(:gitignore) unless options[:skip_git]
293
- build(:gemfile) unless options[:skip_gemfile]
338
+
339
+ unless options[:skip_git]
340
+ build(:gitignore)
341
+ build(:gitattributes)
342
+ end
343
+
344
+ build(:gemfile) unless options[:skip_gemfile]
294
345
  build(:version_control)
295
346
  build(:package_json) unless options[:skip_javascript]
296
347
  end
@@ -308,9 +359,14 @@ module Rails
308
359
  end
309
360
  remove_task :update_bin_files
310
361
 
362
+ def update_bin_yarn
363
+ build(:yarn_when_updating)
364
+ end
365
+ remove_task :update_bin_yarn
366
+
311
367
  def update_active_storage
312
368
  unless skip_active_storage?
313
- rails_command "active_storage:update"
369
+ rails_command "active_storage:update", inline: true
314
370
  end
315
371
  end
316
372
  remove_task :update_active_storage
@@ -420,11 +476,18 @@ module Rails
420
476
  end
421
477
 
422
478
  def delete_js_folder_skipping_javascript
423
- if options[:skip_javascript]
479
+ if options[:skip_javascript] && !options[:minimal]
424
480
  remove_dir "app/javascript"
425
481
  end
426
482
  end
427
483
 
484
+ def delete_js_packs_when_minimal_skipping_webpack
485
+ if options[:minimal] && options[:skip_webpack_install]
486
+ remove_dir "app/javascript/packs"
487
+ keep_file "app/javascript"
488
+ end
489
+ end
490
+
428
491
  def delete_assets_initializer_skipping_sprockets
429
492
  if options[:skip_sprockets]
430
493
  remove_file "config/initializers/assets.rb"
@@ -437,6 +500,12 @@ module Rails
437
500
  end
438
501
  end
439
502
 
503
+ def delete_active_job_folder_if_skipping_active_job
504
+ if options[:skip_active_job]
505
+ remove_dir "app/jobs"
506
+ end
507
+ end
508
+
440
509
  def delete_action_mailer_files_skipping_action_mailer
441
510
  if options[:skip_action_mailer]
442
511
  remove_file "app/views/layouts/mailer.html.erb"
@@ -458,6 +527,7 @@ module Rails
458
527
  if options[:api]
459
528
  remove_file "config/initializers/cookies_serializer.rb"
460
529
  remove_file "config/initializers/content_security_policy.rb"
530
+ remove_file "config/initializers/permissions_policy.rb"
461
531
  end
462
532
  end
463
533
 
@@ -469,20 +539,16 @@ module Rails
469
539
 
470
540
  def delete_new_framework_defaults
471
541
  unless options[:update]
472
- remove_file "config/initializers/new_framework_defaults_6_0.rb"
542
+ remove_file "config/initializers/new_framework_defaults_6_1.rb"
473
543
  end
474
544
  end
475
545
 
476
- def delete_bin_yarn
477
- remove_file "bin/yarn" if options[:skip_javascript]
478
- end
479
-
480
546
  def finish_template
481
547
  build(:leftovers)
482
548
  end
483
549
 
484
550
  public_task :apply_rails_template, :run_bundle
485
- public_task :generate_bundler_binstub, :generate_spring_binstubs
551
+ public_task :generate_bundler_binstub
486
552
  public_task :run_webpack
487
553
 
488
554
  def run_after_bundle_callbacks
@@ -493,6 +559,8 @@ module Rails
493
559
  "rails new #{arguments.map(&:usage).join(' ')} [options]"
494
560
  end
495
561
 
562
+ # :startdoc:
563
+
496
564
  private
497
565
  # Define file as an alias to create_file for backwards compatibility.
498
566
  def file(*args, &block)
@@ -534,7 +602,13 @@ module Rails
534
602
  end
535
603
 
536
604
  def self.default_rc_file
537
- File.expand_path("~/.railsrc")
605
+ xdg_config_home = ENV["XDG_CONFIG_HOME"].presence || "~/.config"
606
+ xdg_railsrc = File.expand_path("rails/railsrc", xdg_config_home)
607
+ if File.exist?(xdg_railsrc)
608
+ xdg_railsrc
609
+ else
610
+ File.expand_path("~/.railsrc")
611
+ end
538
612
  end
539
613
 
540
614
  private