railties 6.0.4.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 -420
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +1 -1
- data/README.rdoc +1 -1
- data/lib/minitest/rails_plugin.rb +16 -1
- data/lib/rails/api/task.rb +1 -1
- data/lib/rails/application/bootstrap.rb +5 -5
- data/lib/rails/application/configuration.rb +72 -22
- 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/application.rb +45 -79
- 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/base.rb +1 -1
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +1 -1
- data/lib/rails/command.rb +7 -1
- data/lib/rails/commands/credentials/USAGE +17 -2
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/credentials/credentials_command.rb +28 -4
- 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 +3 -13
- 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/configuration.rb +1 -0
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +35 -32
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators/actions/create_migration.rb +5 -0
- data/lib/rails/generators/actions.rb +50 -29
- data/lib/rails/generators/app_base.rb +39 -22
- 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/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/config.ru.tt +2 -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/generators.rb +29 -15
- 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/railtie/configuration.rb +3 -2
- data/lib/rails/railtie.rb +31 -10
- data/lib/rails/source_annotation_extractor.rb +1 -15
- 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/tasks.rb +0 -4
- 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 +12 -3
- data/lib/rails/test_unit/testing.rake +6 -0
- data/lib/rails.rb +5 -8
- metadata +24 -30
- 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
@@ -3,8 +3,8 @@
|
|
3
3
|
require "fileutils"
|
4
4
|
require "action_dispatch"
|
5
5
|
require "rails"
|
6
|
-
require "active_support/deprecation"
|
7
6
|
require "active_support/core_ext/string/filters"
|
7
|
+
require "active_support/core_ext/symbol/starts_ends_with"
|
8
8
|
require "rails/dev_caching"
|
9
9
|
require "rails/command/environment_argument"
|
10
10
|
|
@@ -96,12 +96,10 @@ module Rails
|
|
96
96
|
|
97
97
|
# Hard-coding a bunch of handlers here as we don't have a public way of
|
98
98
|
# querying them from the Rack::Handler registry.
|
99
|
-
RACK_SERVERS = %w(cgi fastcgi webrick lsws scgi thin puma unicorn)
|
99
|
+
RACK_SERVERS = %w(cgi fastcgi webrick lsws scgi thin puma unicorn falcon)
|
100
100
|
|
101
101
|
DEFAULT_PORT = 3000
|
102
|
-
|
103
|
-
|
104
|
-
argument :using, optional: true
|
102
|
+
DEFAULT_PIDFILE = "tmp/pids/server.pid"
|
105
103
|
|
106
104
|
class_option :port, aliases: "-p", type: :numeric,
|
107
105
|
desc: "Runs Rails on the specified port - defaults to 3000.", banner: :port
|
@@ -114,8 +112,8 @@ module Rails
|
|
114
112
|
desc: "Runs server as a Daemon."
|
115
113
|
class_option :using, aliases: "-u", type: :string,
|
116
114
|
desc: "Specifies the Rack server used to run the application (thin/puma/webrick).", banner: :name
|
117
|
-
class_option :pid, aliases: "-P", type: :string,
|
118
|
-
desc: "Specifies the PID file."
|
115
|
+
class_option :pid, aliases: "-P", type: :string,
|
116
|
+
desc: "Specifies the PID file - defaults to #{DEFAULT_PIDFILE}."
|
119
117
|
class_option :dev_caching, aliases: "-C", type: :boolean, default: nil,
|
120
118
|
desc: "Specifies whether to perform caching in development."
|
121
119
|
class_option :restart, type: :boolean, default: nil, hide: true
|
@@ -127,7 +125,6 @@ module Rails
|
|
127
125
|
super
|
128
126
|
|
129
127
|
@original_options = local_options - %w( --restart )
|
130
|
-
deprecate_positional_rack_server_and_rewrite_to_option(@original_options)
|
131
128
|
end
|
132
129
|
|
133
130
|
def perform
|
@@ -146,7 +143,7 @@ module Rails
|
|
146
143
|
after_stop_callback = -> { say "Exiting" unless options[:daemon] }
|
147
144
|
server.start(after_stop_callback)
|
148
145
|
else
|
149
|
-
say rack_server_suggestion(using)
|
146
|
+
say rack_server_suggestion(options[:using])
|
150
147
|
end
|
151
148
|
end
|
152
149
|
end
|
@@ -155,7 +152,7 @@ module Rails
|
|
155
152
|
def server_options
|
156
153
|
{
|
157
154
|
user_supplied_options: user_supplied_options,
|
158
|
-
server: using,
|
155
|
+
server: options[:using],
|
159
156
|
log_stdout: log_to_stdout?,
|
160
157
|
Port: port,
|
161
158
|
Host: host,
|
@@ -178,7 +175,7 @@ module Rails
|
|
178
175
|
# ["-p3001", "-C", "--binding", "127.0.0.1"] # => {"-p"=>true, "-C"=>true, "--binding"=>true}
|
179
176
|
user_flag = {}
|
180
177
|
@original_options.each do |command|
|
181
|
-
if command.
|
178
|
+
if command.start_with?("--")
|
182
179
|
option = command.split("=")[0]
|
183
180
|
user_flag[option] = true
|
184
181
|
elsif command =~ /\A(-.)/
|
@@ -207,6 +204,7 @@ module Rails
|
|
207
204
|
end
|
208
205
|
user_supplied_options << :Host if ENV["HOST"] || ENV["BINDING"]
|
209
206
|
user_supplied_options << :Port if ENV["PORT"]
|
207
|
+
user_supplied_options << :pid if ENV["PIDFILE"]
|
210
208
|
user_supplied_options.uniq
|
211
209
|
end
|
212
210
|
end
|
@@ -221,15 +219,6 @@ module Rails
|
|
221
219
|
else
|
222
220
|
default_host = environment == "development" ? "localhost" : "0.0.0.0"
|
223
221
|
|
224
|
-
if ENV["HOST"] && !ENV["BINDING"]
|
225
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
226
|
-
Using the `HOST` environment variable to specify the IP is deprecated and will be removed in Rails 6.1.
|
227
|
-
Please use `BINDING` environment variable instead.
|
228
|
-
MSG
|
229
|
-
|
230
|
-
return ENV["HOST"]
|
231
|
-
end
|
232
|
-
|
233
222
|
ENV.fetch("BINDING", default_host)
|
234
223
|
end
|
235
224
|
end
|
@@ -253,7 +242,7 @@ module Rails
|
|
253
242
|
end
|
254
243
|
|
255
244
|
def pid
|
256
|
-
File.expand_path(options[:pid])
|
245
|
+
File.expand_path(options[:pid] || ENV.fetch("PIDFILE", DEFAULT_PIDFILE))
|
257
246
|
end
|
258
247
|
|
259
248
|
def self.banner(*)
|
@@ -261,23 +250,7 @@ module Rails
|
|
261
250
|
end
|
262
251
|
|
263
252
|
def prepare_restart
|
264
|
-
FileUtils.rm_f(
|
265
|
-
end
|
266
|
-
|
267
|
-
def deprecate_positional_rack_server_and_rewrite_to_option(original_options)
|
268
|
-
if using
|
269
|
-
ActiveSupport::Deprecation.warn(<<~MSG.squish)
|
270
|
-
Passing the Rack server name as a regular argument is deprecated
|
271
|
-
and will be removed in the next Rails version. Please, use the -u
|
272
|
-
option instead.
|
273
|
-
MSG
|
274
|
-
|
275
|
-
original_options.concat [ "-u", using ]
|
276
|
-
else
|
277
|
-
# Use positional internally to get around Thor's immutable options.
|
278
|
-
# TODO: Replace `using` occurrences with `options[:using]` after deprecation removal.
|
279
|
-
@using = options[:using]
|
280
|
-
end
|
253
|
+
FileUtils.rm_f(pid) if options[:restart]
|
281
254
|
end
|
282
255
|
|
283
256
|
def rack_server_suggestion(server)
|
@@ -287,7 +260,7 @@ module Rails
|
|
287
260
|
|
288
261
|
gem "#{server}"
|
289
262
|
|
290
|
-
Run `rails server --help` for more options.
|
263
|
+
Run `bin/rails server --help` for more options.
|
291
264
|
MSG
|
292
265
|
else
|
293
266
|
suggestion = Rails::Command::Spellchecker.suggest(server, from: RACK_SERVERS)
|
@@ -295,7 +268,7 @@ module Rails
|
|
295
268
|
|
296
269
|
<<~MSG
|
297
270
|
Could not find server "#{server}". #{suggestion_msg}
|
298
|
-
Run `rails server --help` for more options.
|
271
|
+
Run `bin/rails server --help` for more options.
|
299
272
|
MSG
|
300
273
|
end
|
301
274
|
end
|
@@ -304,7 +277,7 @@ module Rails
|
|
304
277
|
say <<~MSG
|
305
278
|
=> Booting #{ActiveSupport::Inflector.demodulize(server)}
|
306
279
|
=> Rails #{Rails.version} application starting in #{Rails.env} #{url}
|
307
|
-
=> Run `rails server --help` for more startup options
|
280
|
+
=> Run `bin/rails server --help` for more startup options
|
308
281
|
MSG
|
309
282
|
end
|
310
283
|
end
|
@@ -29,8 +29,8 @@ module Rails
|
|
29
29
|
def perform(*)
|
30
30
|
$LOAD_PATH << Rails::Command.root.join("test").to_s
|
31
31
|
|
32
|
-
Rails::TestUnit::Runner.parse_options(
|
33
|
-
Rails::TestUnit::Runner.run(
|
32
|
+
Rails::TestUnit::Runner.parse_options(args)
|
33
|
+
Rails::TestUnit::Runner.run(args)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
data/lib/rails/configuration.rb
CHANGED
@@ -30,6 +30,15 @@ module Rails
|
|
30
30
|
#
|
31
31
|
# config.middleware.swap ActionDispatch::Flash, Magical::Unicorns
|
32
32
|
#
|
33
|
+
# Middlewares can be moved from one place to another:
|
34
|
+
#
|
35
|
+
# config.middleware.move_before ActionDispatch::Flash, Magical::Unicorns
|
36
|
+
#
|
37
|
+
# This will move the <tt>Magical::Unicorns</tt> middleware before the
|
38
|
+
# <tt>ActionDispatch::Flash</tt>. You can also move it after:
|
39
|
+
#
|
40
|
+
# config.middleware.move_after ActionDispatch::Flash, Magical::Unicorns
|
41
|
+
#
|
33
42
|
# And finally they can also be removed from the stack completely:
|
34
43
|
#
|
35
44
|
# config.middleware.delete ActionDispatch::Flash
|
@@ -41,33 +50,43 @@ module Rails
|
|
41
50
|
end
|
42
51
|
|
43
52
|
def insert_before(*args, &block)
|
44
|
-
@operations << -> middleware { middleware.
|
53
|
+
@operations << -> middleware { middleware.insert_before(*args, &block) }
|
45
54
|
end
|
46
55
|
ruby2_keywords(:insert_before) if respond_to?(:ruby2_keywords, true)
|
47
56
|
|
48
57
|
alias :insert :insert_before
|
49
58
|
|
50
59
|
def insert_after(*args, &block)
|
51
|
-
@operations << -> middleware { middleware.
|
60
|
+
@operations << -> middleware { middleware.insert_after(*args, &block) }
|
52
61
|
end
|
53
62
|
ruby2_keywords(:insert_after) if respond_to?(:ruby2_keywords, true)
|
54
63
|
|
55
64
|
def swap(*args, &block)
|
56
|
-
@operations << -> middleware { middleware.
|
65
|
+
@operations << -> middleware { middleware.swap(*args, &block) }
|
57
66
|
end
|
58
67
|
ruby2_keywords(:swap) if respond_to?(:ruby2_keywords, true)
|
59
68
|
|
60
69
|
def use(*args, &block)
|
61
|
-
@operations << -> middleware { middleware.
|
70
|
+
@operations << -> middleware { middleware.use(*args, &block) }
|
62
71
|
end
|
63
72
|
ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
|
64
73
|
|
65
74
|
def delete(*args, &block)
|
66
|
-
@delete_operations << -> middleware { middleware.
|
75
|
+
@delete_operations << -> middleware { middleware.delete(*args, &block) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def move_before(*args, &block)
|
79
|
+
@delete_operations << -> middleware { middleware.move_before(*args, &block) }
|
80
|
+
end
|
81
|
+
|
82
|
+
alias :move :move_before
|
83
|
+
|
84
|
+
def move_after(*args, &block)
|
85
|
+
@delete_operations << -> middleware { middleware.move_after(*args, &block) }
|
67
86
|
end
|
68
87
|
|
69
88
|
def unshift(*args, &block)
|
70
|
-
@operations << -> middleware { middleware.
|
89
|
+
@operations << -> middleware { middleware.unshift(*args, &block) }
|
71
90
|
end
|
72
91
|
ruby2_keywords(:unshift) if respond_to?(:ruby2_keywords, true)
|
73
92
|
|
@@ -89,7 +108,7 @@ module Rails
|
|
89
108
|
|
90
109
|
class Generators #:nodoc:
|
91
110
|
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging, :api_only
|
92
|
-
attr_reader :hidden_namespaces
|
111
|
+
attr_reader :hidden_namespaces, :after_generate_callbacks
|
93
112
|
|
94
113
|
def initialize
|
95
114
|
@aliases = Hash.new { |h, k| h[k] = {} }
|
@@ -99,6 +118,7 @@ module Rails
|
|
99
118
|
@colorize_logging = true
|
100
119
|
@api_only = false
|
101
120
|
@hidden_namespaces = []
|
121
|
+
@after_generate_callbacks = []
|
102
122
|
end
|
103
123
|
|
104
124
|
def initialize_copy(source)
|
@@ -112,10 +132,20 @@ module Rails
|
|
112
132
|
@hidden_namespaces << namespace
|
113
133
|
end
|
114
134
|
|
115
|
-
def
|
116
|
-
|
135
|
+
def after_generate(&block)
|
136
|
+
@after_generate_callbacks << block
|
137
|
+
end
|
117
138
|
|
118
|
-
|
139
|
+
def method_missing(method, *args)
|
140
|
+
method = method.to_s.delete_suffix("=").to_sym
|
141
|
+
|
142
|
+
if args.empty?
|
143
|
+
if method == :rails
|
144
|
+
return @options[method]
|
145
|
+
else
|
146
|
+
return @options[:rails][method]
|
147
|
+
end
|
148
|
+
end
|
119
149
|
|
120
150
|
if method == :rails || args.first.is_a?(Hash)
|
121
151
|
namespace, configuration = method, args.shift
|
data/lib/rails/engine/updater.rb
CHANGED
data/lib/rails/engine.rb
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
require "rails/railtie"
|
4
4
|
require "rails/engine/railties"
|
5
|
+
require "active_support/callbacks"
|
5
6
|
require "active_support/core_ext/module/delegation"
|
7
|
+
require "active_support/core_ext/object/try"
|
6
8
|
require "pathname"
|
7
9
|
require "thread"
|
8
10
|
|
@@ -35,10 +37,10 @@ module Rails
|
|
35
37
|
#
|
36
38
|
# == Configuration
|
37
39
|
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
40
|
+
# Like railties, engines can access a config object which contains configuration shared by
|
41
|
+
# all railties and the application.
|
42
|
+
# Additionally, each engine can access <tt>autoload_paths</tt>, <tt>eager_load_paths</tt> and
|
43
|
+
# <tt>autoload_once_paths</tt> settings which are scoped to that engine.
|
42
44
|
#
|
43
45
|
# class MyEngine < Rails::Engine
|
44
46
|
# # Add a load path for this specific Engine
|
@@ -112,7 +114,7 @@ module Rails
|
|
112
114
|
# == Endpoint
|
113
115
|
#
|
114
116
|
# An engine can also be a Rack application. It can be useful if you have a Rack application that
|
115
|
-
# you would like to
|
117
|
+
# you would like to provide with some of the +Engine+'s features.
|
116
118
|
#
|
117
119
|
# To do that, use the +endpoint+ method:
|
118
120
|
#
|
@@ -122,7 +124,7 @@ module Rails
|
|
122
124
|
# end
|
123
125
|
# end
|
124
126
|
#
|
125
|
-
# Now you can mount your engine in application's routes
|
127
|
+
# Now you can mount your engine in application's routes:
|
126
128
|
#
|
127
129
|
# Rails.application.routes.draw do
|
128
130
|
# mount MyEngine::Engine => "/engine"
|
@@ -228,7 +230,7 @@ module Rails
|
|
228
230
|
# resources :articles
|
229
231
|
# end
|
230
232
|
#
|
231
|
-
# If +MyEngine+ is isolated,
|
233
|
+
# If +MyEngine+ is isolated, the routes above will point to
|
232
234
|
# <tt>MyEngine::ArticlesController</tt>. You also don't need to use longer
|
233
235
|
# URL helpers like +my_engine_articles_path+. Instead, you should simply use
|
234
236
|
# +articles_path+, like you would do with your main application.
|
@@ -313,7 +315,7 @@ module Rails
|
|
313
315
|
# helper MyEngine::Engine.helpers
|
314
316
|
# end
|
315
317
|
#
|
316
|
-
# It will include all of the helpers from engine's directory. Take into account
|
318
|
+
# It will include all of the helpers from engine's directory. Take into account this does
|
317
319
|
# not include helpers defined in controllers with helper_method or other similar solutions,
|
318
320
|
# only helpers defined in the helpers directory will be included.
|
319
321
|
#
|
@@ -362,7 +364,7 @@ module Rails
|
|
362
364
|
base.called_from = begin
|
363
365
|
call_stack = caller_locations.map { |l| l.absolute_path || l.path }
|
364
366
|
|
365
|
-
File.dirname(call_stack.detect { |p| p
|
367
|
+
File.dirname(call_stack.detect { |p| !p.match?(%r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack]) })
|
366
368
|
end
|
367
369
|
end
|
368
370
|
|
@@ -421,6 +423,9 @@ module Rails
|
|
421
423
|
end
|
422
424
|
end
|
423
425
|
|
426
|
+
include ActiveSupport::Callbacks
|
427
|
+
define_callbacks :load_seed
|
428
|
+
|
424
429
|
delegate :middleware, :root, :paths, to: :config
|
425
430
|
delegate :engine_name, :isolated?, to: :class
|
426
431
|
|
@@ -469,6 +474,13 @@ module Rails
|
|
469
474
|
self
|
470
475
|
end
|
471
476
|
|
477
|
+
# Invoke the server registered hooks.
|
478
|
+
# Check <tt>Rails::Railtie.server</tt> for more info.
|
479
|
+
def load_server(app = self)
|
480
|
+
run_server_blocks(app)
|
481
|
+
self
|
482
|
+
end
|
483
|
+
|
472
484
|
def eager_load!
|
473
485
|
# Already done by Zeitwerk::Loader.eager_load_all. We need this guard to
|
474
486
|
# easily provide a compatible API for both zeitwerk and classic modes.
|
@@ -551,12 +563,12 @@ module Rails
|
|
551
563
|
# Blog::Engine.load_seed
|
552
564
|
def load_seed
|
553
565
|
seed_file = paths["db/seeds.rb"].existent.first
|
554
|
-
|
566
|
+
run_callbacks(:load_seed) { load(seed_file) } if seed_file
|
567
|
+
end
|
555
568
|
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
load(seed_file)
|
569
|
+
initializer :load_environment_config, before: :load_environment_hook, group: :all do
|
570
|
+
paths["config/environments"].existent.each do |environment|
|
571
|
+
require environment
|
560
572
|
end
|
561
573
|
end
|
562
574
|
|
@@ -587,10 +599,13 @@ module Rails
|
|
587
599
|
|
588
600
|
initializer :add_routing_paths do |app|
|
589
601
|
routing_paths = paths["config/routes.rb"].existent
|
602
|
+
external_paths = self.paths["config/routes"].paths
|
603
|
+
routes.draw_paths.concat(external_paths)
|
590
604
|
|
591
605
|
if routes? || routing_paths.any?
|
592
606
|
app.routes_reloader.paths.unshift(*routing_paths)
|
593
607
|
app.routes_reloader.route_sets << routes
|
608
|
+
app.routes_reloader.external_routes.unshift(*external_paths)
|
594
609
|
end
|
595
610
|
end
|
596
611
|
|
@@ -608,12 +623,6 @@ module Rails
|
|
608
623
|
end
|
609
624
|
end
|
610
625
|
|
611
|
-
initializer :load_environment_config, before: :load_environment_hook, group: :all do
|
612
|
-
paths["config/environments"].existent.each do |environment|
|
613
|
-
require environment
|
614
|
-
end
|
615
|
-
end
|
616
|
-
|
617
626
|
initializer :prepend_helpers_path do |app|
|
618
627
|
if !isolated? || (app == self)
|
619
628
|
app.config.helpers_paths.unshift(*paths["app/helpers"].existent)
|
@@ -626,6 +635,12 @@ module Rails
|
|
626
635
|
end
|
627
636
|
end
|
628
637
|
|
638
|
+
initializer :wrap_executor_around_load_seed do |app|
|
639
|
+
self.class.set_callback(:load_seed, :around) do |engine, seeds_block|
|
640
|
+
app.executor.wrap(&seeds_block)
|
641
|
+
end
|
642
|
+
end
|
643
|
+
|
629
644
|
initializer :engines_blank_point do
|
630
645
|
# We need this initializer so all extra initializers added in engines are
|
631
646
|
# consistently executed after all the initializers above across all engines.
|
@@ -667,18 +682,6 @@ module Rails
|
|
667
682
|
end
|
668
683
|
end
|
669
684
|
|
670
|
-
def with_inline_jobs
|
671
|
-
queue_adapter = config.active_job.queue_adapter
|
672
|
-
ActiveSupport.on_load(:active_job) do
|
673
|
-
self.queue_adapter = :inline
|
674
|
-
end
|
675
|
-
yield
|
676
|
-
ensure
|
677
|
-
ActiveSupport.on_load(:active_job) do
|
678
|
-
self.queue_adapter = queue_adapter
|
679
|
-
end
|
680
|
-
end
|
681
|
-
|
682
685
|
def has_migrations?
|
683
686
|
paths["db/migrate"].existent.any?
|
684
687
|
end
|
data/lib/rails/gem_version.rb
CHANGED
@@ -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
|
@@ -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
|