railties 5.2.6.2 → 6.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of railties might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +183 -199
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +35 -28
- data/README.rdoc +1 -1
- data/lib/minitest/rails_plugin.rb +6 -10
- data/lib/rails/all.rb +4 -0
- data/lib/rails/api/generator.rb +2 -1
- data/lib/rails/api/task.rb +16 -0
- data/lib/rails/app_loader.rb +1 -1
- data/lib/rails/app_updater.rb +3 -1
- data/lib/rails/application/configuration.rb +54 -12
- data/lib/rails/application/default_middleware_stack.rb +2 -0
- data/lib/rails/application.rb +21 -45
- data/lib/rails/backtrace_cleaner.rb +5 -17
- data/lib/rails/code_statistics.rb +3 -3
- data/lib/rails/command/actions.rb +0 -10
- data/lib/rails/command/base.rb +1 -5
- data/lib/rails/command/behavior.rb +4 -46
- data/lib/rails/command/environment_argument.rb +1 -11
- data/lib/rails/command/spellchecker.rb +58 -0
- data/lib/rails/command.rb +11 -10
- data/lib/rails/commands/credentials/USAGE +19 -1
- data/lib/rails/commands/credentials/credentials_command.rb +42 -23
- data/lib/rails/commands/db/system/change/change_command.rb +20 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +2 -2
- data/lib/rails/commands/dev/dev_command.rb +17 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +2 -3
- data/lib/rails/commands/help/help_command.rb +1 -1
- data/lib/rails/commands/initializers/initializers_command.rb +16 -0
- data/lib/rails/commands/new/new_command.rb +2 -2
- data/lib/rails/commands/notes/notes_command.rb +39 -0
- data/lib/rails/commands/plugin/plugin_command.rb +1 -1
- data/lib/rails/commands/routes/routes_command.rb +37 -0
- data/lib/rails/commands/runner/runner_command.rb +6 -6
- data/lib/rails/commands/secrets/USAGE +3 -3
- data/lib/rails/commands/secrets/secrets_command.rb +3 -3
- data/lib/rails/commands/server/server_command.rb +109 -48
- data/lib/rails/configuration.rb +1 -7
- data/lib/rails/engine/configuration.rb +3 -1
- data/lib/rails/engine.rb +3 -9
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions.rb +48 -37
- data/lib/rails/generators/app_base.rb +49 -89
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/base.rb +0 -4
- data/lib/rails/generators/database.rb +57 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +1 -1
- data/lib/rails/generators/generated_attribute.rb +17 -17
- data/lib/rails/generators/model_helpers.rb +8 -1
- data/lib/rails/generators/named_base.rb +1 -5
- data/lib/rails/generators/rails/app/app_generator.rb +37 -72
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +3 -6
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
- data/lib/rails/generators/rails/app/templates/app/{assets/javascripts/cable.js.tt → javascript/channels/consumer.js} +2 -9
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +15 -0
- data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -5
- data/lib/rails/generators/rails/app/templates/bin/update.tt +6 -7
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +2 -0
- data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +6 -6
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -2
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +5 -12
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +4 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +33 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +3 -5
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
- data/lib/rails/generators/rails/app/templates/gitignore.tt +2 -7
- data/lib/rails/generators/rails/app/templates/package.json.tt +7 -1
- data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +7 -0
- data/lib/rails/generators/rails/assets/USAGE +1 -4
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -8
- data/lib/rails/generators/rails/controller/controller_generator.rb +11 -1
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +7 -8
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +55 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +4 -5
- data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +9 -18
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +1 -2
- data/lib/rails/generators/resource_helpers.rb +1 -6
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +6 -0
- data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +1 -1
- data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
- data/lib/rails/generators/testing/behaviour.rb +3 -0
- data/lib/rails/generators.rb +11 -12
- data/lib/rails/info.rb +2 -2
- data/lib/rails/info_controller.rb +1 -1
- data/lib/rails/mailers_controller.rb +1 -1
- data/lib/rails/paths.rb +19 -9
- data/lib/rails/railtie.rb +1 -1
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +0 -1
- data/lib/rails/source_annotation_extractor.rb +125 -117
- data/lib/rails/tasks/annotations.rake +9 -9
- data/lib/rails/tasks/dev.rake +5 -4
- data/lib/rails/tasks/framework.rake +5 -1
- data/lib/rails/tasks/initializers.rake +5 -4
- data/lib/rails/tasks/log.rake +0 -1
- data/lib/rails/tasks/routes.rake +4 -26
- data/lib/rails/tasks/statistics.rake +1 -0
- data/lib/rails/tasks/yarn.rake +1 -1
- data/lib/rails/templates/rails/welcome/index.html.erb +2 -2
- data/lib/rails/test_help.rb +11 -9
- data/lib/rails/test_unit/reporter.rb +1 -1
- data/lib/rails/test_unit/runner.rb +5 -5
- data/lib/rails/test_unit/testing.rake +1 -1
- metadata +33 -27
- data/lib/rails/commands/encrypted/USAGE +0 -28
- data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
- data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -38
- data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "fileutils"
|
4
|
-
require "optparse"
|
5
4
|
require "action_dispatch"
|
6
5
|
require "rails"
|
7
6
|
require "active_support/deprecation"
|
@@ -22,19 +21,6 @@ module Rails
|
|
22
21
|
set_environment
|
23
22
|
end
|
24
23
|
|
25
|
-
def app
|
26
|
-
@app ||= begin
|
27
|
-
app = super
|
28
|
-
if app.is_a?(Class)
|
29
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
30
|
-
Using `Rails::Application` subclass to start the server is deprecated and will be removed in Rails 6.0.
|
31
|
-
Please change `run #{app}` to `run Rails.application` in config.ru.
|
32
|
-
MSG
|
33
|
-
end
|
34
|
-
app.respond_to?(:to_app) ? app.to_app : app
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
24
|
def opt_parser
|
39
25
|
Options.new
|
40
26
|
end
|
@@ -43,18 +29,22 @@ module Rails
|
|
43
29
|
ENV["RAILS_ENV"] ||= options[:environment]
|
44
30
|
end
|
45
31
|
|
46
|
-
def start
|
47
|
-
print_boot_information
|
32
|
+
def start(after_stop_callback = nil)
|
48
33
|
trap(:INT) { exit }
|
49
34
|
create_tmp_directories
|
50
35
|
setup_dev_caching
|
51
36
|
log_to_stdout if options[:log_stdout]
|
52
37
|
|
53
|
-
super
|
38
|
+
super()
|
54
39
|
ensure
|
55
|
-
|
56
|
-
|
57
|
-
|
40
|
+
after_stop_callback.call if after_stop_callback
|
41
|
+
end
|
42
|
+
|
43
|
+
def serveable? # :nodoc:
|
44
|
+
server
|
45
|
+
true
|
46
|
+
rescue LoadError, NameError
|
47
|
+
false
|
58
48
|
end
|
59
49
|
|
60
50
|
def middleware
|
@@ -65,6 +55,10 @@ module Rails
|
|
65
55
|
super.merge(@default_options)
|
66
56
|
end
|
67
57
|
|
58
|
+
def served_url
|
59
|
+
"#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}" unless use_puma?
|
60
|
+
end
|
61
|
+
|
68
62
|
private
|
69
63
|
def setup_dev_caching
|
70
64
|
if options[:environment] == "development"
|
@@ -72,13 +66,6 @@ module Rails
|
|
72
66
|
end
|
73
67
|
end
|
74
68
|
|
75
|
-
def print_boot_information
|
76
|
-
url = "on #{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}" unless use_puma?
|
77
|
-
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
|
78
|
-
puts "=> Rails #{Rails.version} application starting in #{Rails.env} #{url}"
|
79
|
-
puts "=> Run `rails server -h` for more startup options"
|
80
|
-
end
|
81
|
-
|
82
69
|
def create_tmp_directories
|
83
70
|
%w(cache pids sockets).each do |dir_to_make|
|
84
71
|
FileUtils.mkdir_p(File.join(Rails.root, "tmp", dir_to_make))
|
@@ -97,10 +84,6 @@ module Rails
|
|
97
84
|
end
|
98
85
|
end
|
99
86
|
|
100
|
-
def restart_command
|
101
|
-
"bin/rails server #{ARGV.join(' ')}"
|
102
|
-
end
|
103
|
-
|
104
87
|
def use_puma?
|
105
88
|
server.to_s == "Rack::Handler::Puma"
|
106
89
|
end
|
@@ -108,8 +91,14 @@ module Rails
|
|
108
91
|
|
109
92
|
module Command
|
110
93
|
class ServerCommand < Base # :nodoc:
|
94
|
+
# Hard-coding a bunch of handlers here as we don't have a public way of
|
95
|
+
# querying them from the Rack::Handler registry.
|
96
|
+
RACK_SERVERS = %w(cgi fastcgi webrick lsws scgi thin puma unicorn)
|
97
|
+
|
111
98
|
DEFAULT_PORT = 3000
|
112
|
-
DEFAULT_PID_PATH = "tmp/pids/server.pid"
|
99
|
+
DEFAULT_PID_PATH = "tmp/pids/server.pid"
|
100
|
+
|
101
|
+
argument :using, optional: true
|
113
102
|
|
114
103
|
class_option :port, aliases: "-p", type: :numeric,
|
115
104
|
desc: "Runs Rails on the specified port - defaults to 3000.", banner: :port
|
@@ -122,29 +111,41 @@ module Rails
|
|
122
111
|
desc: "Runs server as a Daemon."
|
123
112
|
class_option :environment, aliases: "-e", type: :string,
|
124
113
|
desc: "Specifies the environment to run this server under (development/test/production).", banner: :name
|
114
|
+
class_option :using, aliases: "-u", type: :string,
|
115
|
+
desc: "Specifies the Rack server used to run the application (thin/puma/webrick).", banner: :name
|
125
116
|
class_option :pid, aliases: "-P", type: :string, default: DEFAULT_PID_PATH,
|
126
117
|
desc: "Specifies the PID file."
|
127
|
-
class_option
|
118
|
+
class_option :dev_caching, aliases: "-C", type: :boolean, default: nil,
|
128
119
|
desc: "Specifies whether to perform caching in development."
|
129
|
-
class_option
|
130
|
-
class_option
|
120
|
+
class_option :restart, type: :boolean, default: nil, hide: true
|
121
|
+
class_option :early_hints, type: :boolean, default: nil, desc: "Enables HTTP/2 early hints."
|
122
|
+
class_option :log_to_stdout, type: :boolean, default: nil, optional: true,
|
123
|
+
desc: "Whether to log to stdout. Enabled by default in development when not daemonized."
|
131
124
|
|
132
|
-
def initialize(args
|
133
|
-
@original_options = local_options
|
125
|
+
def initialize(args, local_options, *)
|
134
126
|
super
|
135
|
-
|
136
|
-
@
|
127
|
+
|
128
|
+
@original_options = local_options - %w( --restart )
|
129
|
+
deprecate_positional_rack_server_and_rewrite_to_option(@original_options)
|
137
130
|
end
|
138
131
|
|
139
132
|
def perform
|
140
133
|
set_application_directory!
|
141
134
|
prepare_restart
|
135
|
+
|
142
136
|
Rails::Server.new(server_options).tap do |server|
|
143
137
|
# Require application after server sets environment to propagate
|
144
138
|
# the --environment option.
|
145
139
|
require APP_PATH
|
146
140
|
Dir.chdir(Rails.application.root)
|
147
|
-
|
141
|
+
|
142
|
+
if server.serveable?
|
143
|
+
print_boot_information(server.server, server.served_url)
|
144
|
+
after_stop_callback = -> { say "Exiting" unless options[:daemon] }
|
145
|
+
server.start(after_stop_callback)
|
146
|
+
else
|
147
|
+
say rack_server_suggestion(using)
|
148
|
+
end
|
148
149
|
end
|
149
150
|
end
|
150
151
|
|
@@ -152,8 +153,8 @@ module Rails
|
|
152
153
|
def server_options
|
153
154
|
{
|
154
155
|
user_supplied_options: user_supplied_options,
|
155
|
-
server:
|
156
|
-
log_stdout:
|
156
|
+
server: using,
|
157
|
+
log_stdout: log_to_stdout?,
|
157
158
|
Port: port,
|
158
159
|
Host: host,
|
159
160
|
DoNotReverseLookup: true,
|
@@ -161,7 +162,7 @@ module Rails
|
|
161
162
|
environment: environment,
|
162
163
|
daemonize: options[:daemon],
|
163
164
|
pid: pid,
|
164
|
-
caching: options[
|
165
|
+
caching: options[:dev_caching],
|
165
166
|
restart_cmd: restart_command,
|
166
167
|
early_hints: early_hints
|
167
168
|
}
|
@@ -194,7 +195,7 @@ module Rails
|
|
194
195
|
name = :Port
|
195
196
|
when :binding
|
196
197
|
name = :Host
|
197
|
-
when :
|
198
|
+
when :dev_caching
|
198
199
|
name = :caching
|
199
200
|
when :daemonize
|
200
201
|
name = :daemon
|
@@ -202,7 +203,7 @@ module Rails
|
|
202
203
|
user_supplied_options << name
|
203
204
|
end
|
204
205
|
end
|
205
|
-
user_supplied_options << :Host if ENV["HOST"]
|
206
|
+
user_supplied_options << :Host if ENV["HOST"] || ENV["BINDING"]
|
206
207
|
user_supplied_options << :Port if ENV["PORT"]
|
207
208
|
user_supplied_options.uniq
|
208
209
|
end
|
@@ -217,7 +218,17 @@ module Rails
|
|
217
218
|
options[:binding]
|
218
219
|
else
|
219
220
|
default_host = environment == "development" ? "localhost" : "0.0.0.0"
|
220
|
-
|
221
|
+
|
222
|
+
if ENV["HOST"] && !ENV["BINDING"]
|
223
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
224
|
+
Using the `HOST` environment to specify the IP is deprecated and will be removed in Rails 6.1.
|
225
|
+
Please use `BINDING` environment instead.
|
226
|
+
MSG
|
227
|
+
|
228
|
+
return ENV["HOST"]
|
229
|
+
end
|
230
|
+
|
231
|
+
ENV.fetch("BINDING", default_host)
|
221
232
|
end
|
222
233
|
end
|
223
234
|
|
@@ -226,24 +237,74 @@ module Rails
|
|
226
237
|
end
|
227
238
|
|
228
239
|
def restart_command
|
229
|
-
"bin/rails server #{@
|
240
|
+
"bin/rails server #{@original_options.join(" ")} --restart"
|
230
241
|
end
|
231
242
|
|
232
243
|
def early_hints
|
233
244
|
options[:early_hints]
|
234
245
|
end
|
235
246
|
|
247
|
+
def log_to_stdout?
|
248
|
+
options.fetch(:log_to_stdout) do
|
249
|
+
options[:daemon].blank? && environment == "development"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
236
253
|
def pid
|
237
254
|
File.expand_path(options[:pid])
|
238
255
|
end
|
239
256
|
|
240
257
|
def self.banner(*)
|
241
|
-
"rails server [puma
|
258
|
+
"rails server [thin/puma/webrick] [options]"
|
242
259
|
end
|
243
260
|
|
244
261
|
def prepare_restart
|
245
262
|
FileUtils.rm_f(options[:pid]) if options[:restart]
|
246
263
|
end
|
264
|
+
|
265
|
+
def deprecate_positional_rack_server_and_rewrite_to_option(original_options)
|
266
|
+
if using
|
267
|
+
ActiveSupport::Deprecation.warn(<<~MSG)
|
268
|
+
Passing the Rack server name as a regular argument is deprecated
|
269
|
+
and will be removed in the next Rails version. Please, use the -u
|
270
|
+
option instead.
|
271
|
+
MSG
|
272
|
+
|
273
|
+
original_options.concat [ "-u", using ]
|
274
|
+
else
|
275
|
+
# Use positional internally to get around Thor's immutable options.
|
276
|
+
# TODO: Replace `using` occurrences with `options[:using]` after deprecation removal.
|
277
|
+
@using = options[:using]
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
def rack_server_suggestion(server)
|
282
|
+
if server.in?(RACK_SERVERS)
|
283
|
+
<<~MSG
|
284
|
+
Could not load server "#{server}". Maybe you need to the add it to the Gemfile?
|
285
|
+
|
286
|
+
gem "#{server}"
|
287
|
+
|
288
|
+
Run `rails server --help` for more options.
|
289
|
+
MSG
|
290
|
+
else
|
291
|
+
suggestion = Rails::Command::Spellchecker.suggest(server, from: RACK_SERVERS)
|
292
|
+
suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
|
293
|
+
|
294
|
+
<<~MSG
|
295
|
+
Could not find server "#{server}". #{suggestion_msg}
|
296
|
+
Run `rails server --help` for more options.
|
297
|
+
MSG
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def print_boot_information(server, url)
|
302
|
+
say <<~MSG
|
303
|
+
=> Booting #{ActiveSupport::Inflector.demodulize(server)}
|
304
|
+
=> Rails #{Rails.version} application starting in #{Rails.env} #{url}
|
305
|
+
=> Run `rails server --help` for more startup options
|
306
|
+
MSG
|
307
|
+
end
|
247
308
|
end
|
248
309
|
end
|
249
310
|
end
|
data/lib/rails/configuration.rb
CHANGED
@@ -38,7 +38,9 @@ module Rails
|
|
38
38
|
@paths ||= begin
|
39
39
|
paths = Rails::Paths::Root.new(@root)
|
40
40
|
|
41
|
-
paths.add "app", eager_load: true,
|
41
|
+
paths.add "app", eager_load: true,
|
42
|
+
glob: "{*,*/concerns}",
|
43
|
+
exclude: %w(assets javascript)
|
42
44
|
paths.add "app/assets", glob: "*"
|
43
45
|
paths.add "app/controllers", eager_load: true
|
44
46
|
paths.add "app/channels", eager_load: true, glob: "**/*_channel.rb"
|
data/lib/rails/engine.rb
CHANGED
@@ -531,9 +531,9 @@ module Rails
|
|
531
531
|
|
532
532
|
# Defines the routes for this engine. If a block is given to
|
533
533
|
# routes, it is appended to the engine.
|
534
|
-
def routes
|
534
|
+
def routes
|
535
535
|
@routes ||= ActionDispatch::Routing::RouteSet.new_with_config(config)
|
536
|
-
@routes.append(&
|
536
|
+
@routes.append(&Proc.new) if block_given?
|
537
537
|
@routes
|
538
538
|
end
|
539
539
|
|
@@ -548,13 +548,7 @@ module Rails
|
|
548
548
|
# Blog::Engine.load_seed
|
549
549
|
def load_seed
|
550
550
|
seed_file = paths["db/seeds.rb"].existent.first
|
551
|
-
|
552
|
-
|
553
|
-
if config.try(:active_job).try!(:queue_adapter) == :async
|
554
|
-
with_inline_jobs { load(seed_file) }
|
555
|
-
else
|
556
|
-
load(seed_file)
|
557
|
-
end
|
551
|
+
with_inline_jobs { load(seed_file) } if seed_file
|
558
552
|
end
|
559
553
|
|
560
554
|
# Add configured load paths to Ruby's load path, and remove duplicate entries.
|
data/lib/rails/gem_version.rb
CHANGED
@@ -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
|
-
@
|
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
|
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 =
|
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
|
-
|
56
|
-
|
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 #{
|
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
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
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
|
-
|
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,11 @@ 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!
|
214
225
|
argument = args.flat_map(&:to_s).join(" ")
|
215
226
|
|
216
|
-
|
227
|
+
execute_command :rails, "generate #{what} #{argument}", options
|
217
228
|
end
|
218
229
|
|
219
230
|
# Runs the supplied rake task (invoked with 'rake ...')
|
@@ -236,15 +247,6 @@ module Rails
|
|
236
247
|
execute_command :rails, command, options
|
237
248
|
end
|
238
249
|
|
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
250
|
# Make an entry in Rails routing file <tt>config/routes.rb</tt>
|
249
251
|
#
|
250
252
|
# route "root 'welcome#index'"
|
@@ -264,16 +266,6 @@ module Rails
|
|
264
266
|
log File.read(find_in_source_paths(path))
|
265
267
|
end
|
266
268
|
|
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
269
|
private
|
278
270
|
|
279
271
|
# Define log for backwards compatibility. If just one argument is sent,
|
@@ -296,7 +288,8 @@ module Rails
|
|
296
288
|
sudo = options[:sudo] && !Gem.win_platform? ? "sudo " : ""
|
297
289
|
config = { verbose: false }
|
298
290
|
|
299
|
-
config
|
291
|
+
config[:capture] = options[:capture] if options[:capture]
|
292
|
+
config[:abort_on_failure] = options[:abort_on_failure] if options[:abort_on_failure]
|
300
293
|
|
301
294
|
in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", config) }
|
302
295
|
end
|
@@ -313,6 +306,11 @@ module Rails
|
|
313
306
|
# Surround string with single quotes if there is no quotes.
|
314
307
|
# Otherwise fall back to double quotes
|
315
308
|
def quote(value) # :doc:
|
309
|
+
if value.respond_to? :each_pair
|
310
|
+
return value.map do |k, v|
|
311
|
+
"#{k}: #{quote(v)}"
|
312
|
+
end.join(", ")
|
313
|
+
end
|
316
314
|
return value.inspect unless value.is_a? String
|
317
315
|
|
318
316
|
if value.include?("'")
|
@@ -332,6 +330,19 @@ module Rails
|
|
332
330
|
"#{value.strip.indent(amount)}\n"
|
333
331
|
end
|
334
332
|
end
|
333
|
+
|
334
|
+
# Indent the +Gemfile+ to the depth of @indentation
|
335
|
+
def indentation # :doc:
|
336
|
+
" " * @indentation
|
337
|
+
end
|
338
|
+
|
339
|
+
# Manage +Gemfile+ indentation for a DSL action block
|
340
|
+
def with_indentation(&block) # :doc:
|
341
|
+
@indentation += 1
|
342
|
+
instance_eval(&block)
|
343
|
+
ensure
|
344
|
+
@indentation -= 1
|
345
|
+
end
|
335
346
|
end
|
336
347
|
end
|
337
348
|
end
|