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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +234 -370
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +1 -1
- data/lib/minitest/rails_plugin.rb +16 -1
- data/lib/rails.rb +5 -8
- data/lib/rails/application.rb +49 -83
- data/lib/rails/application/bootstrap.rb +5 -5
- data/lib/rails/application/configuration.rb +71 -21
- data/lib/rails/application/default_middleware_stack.rb +5 -3
- data/lib/rails/application/finisher.rb +15 -2
- data/lib/rails/application/routes_reloader.rb +9 -2
- data/lib/rails/backtrace_cleaner.rb +12 -7
- data/lib/rails/code_statistics.rb +3 -3
- data/lib/rails/code_statistics_calculator.rb +6 -6
- data/lib/rails/command.rb +7 -1
- data/lib/rails/command/base.rb +1 -1
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +1 -1
- data/lib/rails/commands/credentials/USAGE +17 -2
- data/lib/rails/commands/credentials/credentials_command.rb +28 -4
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/db/system/change/change_command.rb +6 -1
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +61 -58
- data/lib/rails/commands/encrypted/encrypted_command.rb +4 -4
- data/lib/rails/commands/generate/generate_command.rb +1 -1
- data/lib/rails/commands/notes/notes_command.rb +1 -11
- data/lib/rails/commands/rake/rake_command.rb +9 -8
- data/lib/rails/commands/secrets/USAGE +9 -3
- data/lib/rails/commands/server/server_command.rb +14 -41
- data/lib/rails/commands/test/test_command.rb +2 -2
- data/lib/rails/configuration.rb +40 -10
- data/lib/rails/engine.rb +35 -32
- data/lib/rails/engine/configuration.rb +1 -0
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators.rb +29 -15
- data/lib/rails/generators/actions.rb +50 -29
- data/lib/rails/generators/actions/create_migration.rb +5 -0
- data/lib/rails/generators/app_base.rb +38 -21
- data/lib/rails/generators/base.rb +14 -11
- data/lib/rails/generators/database.rb +3 -4
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +3 -3
- data/lib/rails/generators/generated_attribute.rb +3 -9
- data/lib/rails/generators/migration.rb +2 -1
- data/lib/rails/generators/model_helpers.rb +26 -2
- data/lib/rails/generators/named_base.rb +1 -1
- data/lib/rails/generators/rails/app/USAGE +2 -1
- data/lib/rails/generators/rails/app/app_generator.rb +89 -15
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +11 -11
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +1 -1
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +11 -11
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +2 -1
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -4
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +13 -0
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +9 -3
- data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +14 -7
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +3 -4
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +17 -3
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +15 -5
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +67 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +6 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
- data/lib/rails/generators/rails/app/templates/package.json.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +5 -5
- data/lib/rails/generators/rails/assets/USAGE +2 -3
- data/lib/rails/generators/rails/benchmark/USAGE +19 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
- data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
- data/lib/rails/generators/rails/controller/USAGE +2 -2
- data/lib/rails/generators/rails/controller/controller_generator.rb +2 -40
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +1 -1
- data/lib/rails/generators/rails/generator/USAGE +2 -2
- data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
- data/lib/rails/generators/rails/helper/USAGE +2 -3
- data/lib/rails/generators/rails/integration_test/USAGE +2 -2
- data/lib/rails/generators/rails/migration/USAGE +4 -4
- data/lib/rails/generators/rails/model/USAGE +15 -16
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +25 -23
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +10 -19
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +0 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +13 -11
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
- data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -3
- data/lib/rails/generators/rails/resource/USAGE +4 -4
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
- data/lib/rails/generators/rails/scaffold/USAGE +5 -5
- data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +6 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
- data/lib/rails/generators/rails/system_test/USAGE +2 -2
- data/lib/rails/generators/rails/task/USAGE +3 -3
- data/lib/rails/generators/test_case.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/behaviour.rb +1 -1
- data/lib/rails/info.rb +1 -1
- data/lib/rails/info_controller.rb +1 -1
- data/lib/rails/mailers_controller.rb +1 -0
- data/lib/rails/paths.rb +14 -6
- data/lib/rails/rack/logger.rb +1 -1
- data/lib/rails/railtie.rb +32 -10
- data/lib/rails/railtie/configuration.rb +3 -2
- data/lib/rails/source_annotation_extractor.rb +1 -15
- data/lib/rails/tasks.rb +0 -4
- data/lib/rails/tasks/engine.rake +1 -4
- data/lib/rails/tasks/framework.rake +7 -1
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/statistics.rake +1 -1
- data/lib/rails/tasks/yarn.rake +14 -2
- data/lib/rails/templates/rails/mailers/email.html.erb +1 -0
- data/lib/rails/templates/rails/welcome/index.html.erb +1 -1
- data/lib/rails/test_unit/reporter.rb +2 -1
- data/lib/rails/test_unit/runner.rb +20 -3
- data/lib/rails/test_unit/testing.rake +6 -0
- metadata +27 -33
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +0 -45
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
- data/lib/rails/tasks/annotations.rake +0 -22
- data/lib/rails/tasks/dev.rake +0 -11
- data/lib/rails/tasks/initializers.rake +0 -9
- data/lib/rails/tasks/routes.rake +0 -9
data/lib/rails/engine/updater.rb
CHANGED
data/lib/rails/gem_version.rb
CHANGED
data/lib/rails/generators.rb
CHANGED
@@ -6,10 +6,8 @@ $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.inc
|
|
6
6
|
require "thor/group"
|
7
7
|
require "rails/command"
|
8
8
|
|
9
|
-
require "active_support"
|
10
|
-
require "active_support/core_ext/object/blank"
|
11
|
-
require "active_support/core_ext/kernel/singleton_class"
|
12
9
|
require "active_support/core_ext/array/extract_options"
|
10
|
+
require "active_support/core_ext/enumerable"
|
13
11
|
require "active_support/core_ext/hash/deep_merge"
|
14
12
|
require "active_support/core_ext/module/attribute_accessors"
|
15
13
|
require "active_support/core_ext/string/indent"
|
@@ -81,6 +79,7 @@ module Rails
|
|
81
79
|
templates_path.concat config.templates
|
82
80
|
templates_path.uniq!
|
83
81
|
hide_namespaces(*config.hidden_namespaces)
|
82
|
+
after_generate_callbacks.replace config.after_generate_callbacks
|
84
83
|
end
|
85
84
|
|
86
85
|
def templates_path #:nodoc:
|
@@ -95,6 +94,10 @@ module Rails
|
|
95
94
|
@options ||= DEFAULT_OPTIONS.dup
|
96
95
|
end
|
97
96
|
|
97
|
+
def after_generate_callbacks # :nodoc:
|
98
|
+
@after_generate_callbacks ||= []
|
99
|
+
end
|
100
|
+
|
98
101
|
# Hold configured generators fallbacks. If a plugin developer wants a
|
99
102
|
# generator group to fallback to another group in case of missing generators,
|
100
103
|
# they can add a fallback.
|
@@ -125,14 +128,8 @@ module Rails
|
|
125
128
|
template_engine: nil
|
126
129
|
)
|
127
130
|
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
# Remove the color from output.
|
134
|
-
def no_color!
|
135
|
-
Thor::Base.shell = Thor::Shell::Basic
|
131
|
+
options[:mailer] ||= {}
|
132
|
+
options[:mailer][:template_engine] ||= :erb
|
136
133
|
end
|
137
134
|
|
138
135
|
# Returns an array of generator namespaces that are hidden.
|
@@ -167,7 +164,9 @@ module Rails
|
|
167
164
|
"#{css}:scaffold",
|
168
165
|
"#{css}:assets",
|
169
166
|
"css:assets",
|
170
|
-
"css:scaffold"
|
167
|
+
"css:scaffold",
|
168
|
+
"action_text:install",
|
169
|
+
"action_mailbox:install"
|
171
170
|
]
|
172
171
|
end
|
173
172
|
end
|
@@ -214,7 +213,7 @@ module Rails
|
|
214
213
|
end
|
215
214
|
|
216
215
|
rails = groups.delete("rails")
|
217
|
-
rails.map! { |n| n.
|
216
|
+
rails.map! { |n| n.delete_prefix("rails:") }
|
218
217
|
rails.delete("app")
|
219
218
|
rails.delete("plugin")
|
220
219
|
rails.delete("encrypted_secrets")
|
@@ -257,7 +256,7 @@ module Rails
|
|
257
256
|
|
258
257
|
lookup(lookups)
|
259
258
|
|
260
|
-
namespaces =
|
259
|
+
namespaces = subclasses.index_by(&:namespace)
|
261
260
|
lookups.each do |namespace|
|
262
261
|
klass = namespaces[namespace]
|
263
262
|
return klass if klass
|
@@ -274,6 +273,7 @@ module Rails
|
|
274
273
|
if klass = find_by_namespace(names.pop, names.any? && names.join(":"))
|
275
274
|
args << "--help" if args.empty? && klass.arguments.any?(&:required?)
|
276
275
|
klass.start(args, config)
|
276
|
+
run_after_generate_callback if config[:behavior] == :invoke
|
277
277
|
else
|
278
278
|
options = sorted_groups.flat_map(&:last)
|
279
279
|
suggestion = Rails::Command::Spellchecker.suggest(namespace.to_s, from: options)
|
@@ -281,11 +281,16 @@ module Rails
|
|
281
281
|
|
282
282
|
puts <<~MSG
|
283
283
|
Could not find generator '#{namespace}'. #{suggestion_msg}
|
284
|
-
Run `rails generate --help` for more options.
|
284
|
+
Run `bin/rails generate --help` for more options.
|
285
285
|
MSG
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
289
|
+
def add_generated_file(file) # :nodoc:
|
290
|
+
(@@generated_files ||= []) << file
|
291
|
+
file
|
292
|
+
end
|
293
|
+
|
289
294
|
private
|
290
295
|
def print_list(base, namespaces) # :doc:
|
291
296
|
namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) }
|
@@ -319,6 +324,15 @@ module Rails
|
|
319
324
|
def file_lookup_paths # :doc:
|
320
325
|
@file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ]
|
321
326
|
end
|
327
|
+
|
328
|
+
def run_after_generate_callback
|
329
|
+
if defined?(@@generated_files) && !@@generated_files.empty?
|
330
|
+
@after_generate_callbacks.each do |callback|
|
331
|
+
callback.call(@@generated_files)
|
332
|
+
end
|
333
|
+
@@generated_files = []
|
334
|
+
end
|
335
|
+
end
|
322
336
|
end
|
323
337
|
end
|
324
338
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "shellwords"
|
4
|
+
require "active_support/core_ext/kernel/reporting"
|
3
5
|
require "active_support/core_ext/string/strip"
|
4
6
|
|
5
7
|
module Rails
|
@@ -40,8 +42,7 @@ module Rails
|
|
40
42
|
in_root do
|
41
43
|
str = "gem #{parts.join(", ")}"
|
42
44
|
str = indentation + str
|
43
|
-
|
44
|
-
append_file "Gemfile", str, verbose: false
|
45
|
+
append_file_with_newline "Gemfile", str, verbose: false
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
@@ -58,9 +59,9 @@ module Rails
|
|
58
59
|
log :gemfile, "group #{str}"
|
59
60
|
|
60
61
|
in_root do
|
61
|
-
|
62
|
+
append_file_with_newline "Gemfile", "\ngroup #{str} do", force: true
|
62
63
|
with_indentation(&block)
|
63
|
-
|
64
|
+
append_file_with_newline "Gemfile", "end", force: true
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
@@ -71,9 +72,13 @@ module Rails
|
|
71
72
|
log :github, "github #{str}"
|
72
73
|
|
73
74
|
in_root do
|
74
|
-
|
75
|
+
if @indentation.zero?
|
76
|
+
append_file_with_newline "Gemfile", "\ngithub #{str} do", force: true
|
77
|
+
else
|
78
|
+
append_file_with_newline "Gemfile", "#{indentation}github #{str} do", force: true
|
79
|
+
end
|
75
80
|
with_indentation(&block)
|
76
|
-
|
81
|
+
append_file_with_newline "Gemfile", "#{indentation}end", force: true
|
77
82
|
end
|
78
83
|
end
|
79
84
|
|
@@ -91,9 +96,9 @@ module Rails
|
|
91
96
|
|
92
97
|
in_root do
|
93
98
|
if block
|
94
|
-
|
99
|
+
append_file_with_newline "Gemfile", "\nsource #{quote(source)} do", force: true
|
95
100
|
with_indentation(&block)
|
96
|
-
|
101
|
+
append_file_with_newline "Gemfile", "end", force: true
|
97
102
|
else
|
98
103
|
prepend_file "Gemfile", "source #{quote(source)}\n", verbose: false
|
99
104
|
end
|
@@ -106,11 +111,11 @@ module Rails
|
|
106
111
|
# file in <tt>config/environments</tt>.
|
107
112
|
#
|
108
113
|
# environment do
|
109
|
-
# "config.
|
114
|
+
# "config.asset_host = 'cdn.provider.com'"
|
110
115
|
# end
|
111
116
|
#
|
112
117
|
# environment(nil, env: "development") do
|
113
|
-
# "config.
|
118
|
+
# "config.asset_host = 'localhost:3000'"
|
114
119
|
# end
|
115
120
|
def environment(data = nil, options = {})
|
116
121
|
sentinel = "class Application < Rails::Application\n"
|
@@ -222,10 +227,9 @@ module Rails
|
|
222
227
|
log :generate, what
|
223
228
|
|
224
229
|
options = args.extract_options!
|
225
|
-
options[:
|
226
|
-
argument = args.flat_map(&:to_s).join(" ")
|
230
|
+
options[:abort_on_failure] = !options[:inline]
|
227
231
|
|
228
|
-
|
232
|
+
rails_command "generate #{what} #{args.join(" ")}", options
|
229
233
|
end
|
230
234
|
|
231
235
|
# Runs the supplied rake task (invoked with 'rake ...')
|
@@ -245,13 +249,28 @@ module Rails
|
|
245
249
|
# rails_command("gems:install", sudo: true)
|
246
250
|
# rails_command("gems:install", capture: true)
|
247
251
|
def rails_command(command, options = {})
|
248
|
-
|
252
|
+
if options[:inline]
|
253
|
+
log :rails, command
|
254
|
+
command, *args = Shellwords.split(command)
|
255
|
+
in_root do
|
256
|
+
silence_warnings do
|
257
|
+
::Rails::Command.invoke(command, args, **options)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
else
|
261
|
+
execute_command :rails, command, options
|
262
|
+
end
|
249
263
|
end
|
250
264
|
|
251
265
|
# Make an entry in Rails routing file <tt>config/routes.rb</tt>
|
252
266
|
#
|
253
267
|
# route "root 'welcome#index'"
|
254
|
-
|
268
|
+
# route "root 'admin#index'", namespace: :admin
|
269
|
+
def route(routing_code, namespace: nil)
|
270
|
+
routing_code = Array(namespace).reverse.reduce(routing_code) do |code, ns|
|
271
|
+
"namespace :#{ns} do\n#{indent(code, 2)}\nend"
|
272
|
+
end
|
273
|
+
|
255
274
|
log :route, routing_code
|
256
275
|
sentinel = /\.routes\.draw do\s*\n/m
|
257
276
|
|
@@ -284,15 +303,15 @@ module Rails
|
|
284
303
|
# based on the executor parameter provided.
|
285
304
|
def execute_command(executor, command, options = {}) # :doc:
|
286
305
|
log executor, command
|
287
|
-
env = options[:env] || ENV["RAILS_ENV"] || "development"
|
288
|
-
rails_env = " RAILS_ENV=#{env}" unless options[:without_rails_env]
|
289
306
|
sudo = options[:sudo] && !Gem.win_platform? ? "sudo " : ""
|
290
|
-
config = {
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
307
|
+
config = {
|
308
|
+
env: { "RAILS_ENV" => (options[:env] || ENV["RAILS_ENV"] || "development") },
|
309
|
+
verbose: false,
|
310
|
+
capture: options[:capture],
|
311
|
+
abort_on_failure: options[:abort_on_failure],
|
312
|
+
}
|
313
|
+
|
314
|
+
in_root { run("#{sudo}#{extify(executor)} #{command}", config) }
|
296
315
|
end
|
297
316
|
|
298
317
|
# Add an extension to the given name based on the platform.
|
@@ -324,12 +343,7 @@ module Rails
|
|
324
343
|
# Returns optimized string with indentation
|
325
344
|
def optimize_indentation(value, amount = 0) # :doc:
|
326
345
|
return "#{value}\n" unless value.is_a?(String)
|
327
|
-
|
328
|
-
if value.lines.size > 1
|
329
|
-
value.strip_heredoc.indent(amount)
|
330
|
-
else
|
331
|
-
"#{value.strip.indent(amount)}\n"
|
332
|
-
end
|
346
|
+
"#{value.strip_heredoc.indent(amount).chomp}\n"
|
333
347
|
end
|
334
348
|
|
335
349
|
# Indent the +Gemfile+ to the depth of @indentation
|
@@ -344,6 +358,13 @@ module Rails
|
|
344
358
|
ensure
|
345
359
|
@indentation -= 1
|
346
360
|
end
|
361
|
+
|
362
|
+
# Append string to a file with a newline if necessary
|
363
|
+
def append_file_with_newline(path, str, options = {})
|
364
|
+
gsub_file path, /\n?\z/, options do |match|
|
365
|
+
match.end_with?("\n") ? "" : "\n#{str}\n"
|
366
|
+
end
|
367
|
+
end
|
347
368
|
end
|
348
369
|
end
|
349
370
|
end
|
@@ -19,6 +19,11 @@ module Rails
|
|
19
19
|
exists? && File.binread(existing_migration) == render
|
20
20
|
end
|
21
21
|
|
22
|
+
def invoke!
|
23
|
+
invoked_file = super
|
24
|
+
File.exist?(@destination) ? invoked_file : relative_existing_migration
|
25
|
+
end
|
26
|
+
|
22
27
|
def revoke!
|
23
28
|
say_destination = exists? ? relative_existing_migration : relative_destination
|
24
29
|
say_status :remove, :red, say_destination
|
@@ -52,6 +52,9 @@ module Rails
|
|
52
52
|
class_option :skip_active_record, type: :boolean, aliases: "-O", default: false,
|
53
53
|
desc: "Skip Active Record files"
|
54
54
|
|
55
|
+
class_option :skip_active_job, type: :boolean, default: false,
|
56
|
+
desc: "Skip Active Job"
|
57
|
+
|
55
58
|
class_option :skip_active_storage, type: :boolean, default: false,
|
56
59
|
desc: "Skip Active Storage files"
|
57
60
|
|
@@ -76,6 +79,9 @@ module Rails
|
|
76
79
|
class_option :skip_turbolinks, type: :boolean, default: false,
|
77
80
|
desc: "Skip turbolinks gem"
|
78
81
|
|
82
|
+
class_option :skip_jbuilder, type: :boolean, default: false,
|
83
|
+
desc: "Skip jbuilder gem"
|
84
|
+
|
79
85
|
class_option :skip_test, type: :boolean, aliases: "-T", default: false,
|
80
86
|
desc: "Skip test files"
|
81
87
|
|
@@ -86,10 +92,13 @@ module Rails
|
|
86
92
|
desc: "Skip bootsnap gem"
|
87
93
|
|
88
94
|
class_option :dev, type: :boolean, default: false,
|
89
|
-
desc: "
|
95
|
+
desc: "Set up the #{name} with Gemfile pointing to your Rails checkout"
|
90
96
|
|
91
97
|
class_option :edge, type: :boolean, default: false,
|
92
|
-
desc: "
|
98
|
+
desc: "Set up the #{name} with Gemfile pointing to Rails repository"
|
99
|
+
|
100
|
+
class_option :master, type: :boolean, default: false,
|
101
|
+
desc: "Set up the #{name} with Gemfile pointing to Rails repository master branch"
|
93
102
|
|
94
103
|
class_option :rc, type: :string, default: nil,
|
95
104
|
desc: "Path to file containing extra configuration options for rails command"
|
@@ -101,8 +110,9 @@ module Rails
|
|
101
110
|
desc: "Show this help message and quit"
|
102
111
|
end
|
103
112
|
|
104
|
-
def initialize(*
|
105
|
-
@
|
113
|
+
def initialize(positional_argv, option_argv, *)
|
114
|
+
@argv = [*positional_argv, *option_argv]
|
115
|
+
@gem_filter = lambda { |gem| true }
|
106
116
|
@extra_entries = []
|
107
117
|
super
|
108
118
|
end
|
@@ -152,7 +162,7 @@ module Rails
|
|
152
162
|
end
|
153
163
|
|
154
164
|
def build(meth, *args) # :doc:
|
155
|
-
builder.
|
165
|
+
builder.public_send(meth, *args) if builder.respond_to?(meth)
|
156
166
|
end
|
157
167
|
|
158
168
|
def create_root # :doc:
|
@@ -163,9 +173,14 @@ module Rails
|
|
163
173
|
end
|
164
174
|
|
165
175
|
def apply_rails_template # :doc:
|
176
|
+
original_argv = ARGV.dup
|
177
|
+
ARGV.replace(@argv)
|
178
|
+
|
166
179
|
apply rails_template if rails_template
|
167
180
|
rescue Thor::Error, LoadError, Errno::ENOENT => e
|
168
181
|
raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
|
182
|
+
ensure
|
183
|
+
ARGV.replace(original_argv)
|
169
184
|
end
|
170
185
|
|
171
186
|
def set_default_accessors! # :doc:
|
@@ -191,7 +206,7 @@ module Rails
|
|
191
206
|
def web_server_gemfile_entry # :doc:
|
192
207
|
return [] if options[:skip_puma]
|
193
208
|
comment = "Use Puma as the app server"
|
194
|
-
GemfileEntry.new("puma", "~>
|
209
|
+
GemfileEntry.new("puma", "~> 5.0", comment)
|
195
210
|
end
|
196
211
|
|
197
212
|
def include_all_railties? # :doc:
|
@@ -201,7 +216,8 @@ module Rails
|
|
201
216
|
:skip_action_mailer,
|
202
217
|
:skip_test,
|
203
218
|
:skip_sprockets,
|
204
|
-
:skip_action_cable
|
219
|
+
:skip_action_cable,
|
220
|
+
:skip_active_job
|
205
221
|
),
|
206
222
|
skip_active_storage?,
|
207
223
|
skip_action_mailbox?,
|
@@ -242,6 +258,10 @@ module Rails
|
|
242
258
|
options[:skip_action_text] || skip_active_storage?
|
243
259
|
end
|
244
260
|
|
261
|
+
def skip_dev_gems? # :doc:
|
262
|
+
options[:skip_dev_gems]
|
263
|
+
end
|
264
|
+
|
245
265
|
class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out)
|
246
266
|
def initialize(name, version, comment, options = {}, commented_out = false)
|
247
267
|
super
|
@@ -281,7 +301,11 @@ module Rails
|
|
281
301
|
]
|
282
302
|
elsif options.edge?
|
283
303
|
[
|
284
|
-
GemfileEntry.github("rails", "rails/rails"
|
304
|
+
GemfileEntry.github("rails", "rails/rails")
|
305
|
+
]
|
306
|
+
elsif options.master?
|
307
|
+
[
|
308
|
+
GemfileEntry.github("rails", "rails/rails", "master")
|
285
309
|
]
|
286
310
|
else
|
287
311
|
[GemfileEntry.version("rails",
|
@@ -312,14 +336,11 @@ module Rails
|
|
312
336
|
def webpacker_gemfile_entry
|
313
337
|
return [] if options[:skip_javascript]
|
314
338
|
|
315
|
-
|
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
|
339
|
+
GemfileEntry.version "webpacker", "~> 5.0", "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker"
|
320
340
|
end
|
321
341
|
|
322
342
|
def jbuilder_gemfile_entry
|
343
|
+
return [] if options[:skip_jbuilder]
|
323
344
|
comment = "Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder"
|
324
345
|
GemfileEntry.new "jbuilder", "~> 2.7", comment, {}, options[:api]
|
325
346
|
end
|
@@ -400,7 +421,7 @@ module Rails
|
|
400
421
|
end
|
401
422
|
|
402
423
|
def os_supports_listen_out_of_the_box?
|
403
|
-
RbConfig::CONFIG["host_os"]
|
424
|
+
/darwin|linux/.match?(RbConfig::CONFIG["host_os"])
|
404
425
|
end
|
405
426
|
|
406
427
|
def run_bundle
|
@@ -410,7 +431,9 @@ module Rails
|
|
410
431
|
def run_webpack
|
411
432
|
if webpack_install?
|
412
433
|
rails_command "webpacker:install"
|
413
|
-
|
434
|
+
if options[:webpack] && options[:webpack] != "webpack"
|
435
|
+
rails_command "webpacker:install:#{options[:webpack]}"
|
436
|
+
end
|
414
437
|
end
|
415
438
|
end
|
416
439
|
|
@@ -420,12 +443,6 @@ module Rails
|
|
420
443
|
end
|
421
444
|
end
|
422
445
|
|
423
|
-
def generate_spring_binstubs
|
424
|
-
if bundle_install? && spring_install?
|
425
|
-
bundle_command("exec spring binstub --all")
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
446
|
def empty_directory_with_keep_file(destination, config = {})
|
430
447
|
empty_directory(destination, config)
|
431
448
|
keep_file(destination)
|