railties 5.2.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +293 -89
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +39 -33
- data/README.rdoc +3 -3
- data/lib/minitest/rails_plugin.rb +24 -13
- data/lib/rails/all.rb +4 -0
- data/lib/rails/api/generator.rb +2 -1
- data/lib/rails/api/task.rb +17 -0
- data/lib/rails/app_loader.rb +2 -2
- data/lib/rails/app_updater.rb +4 -1
- data/lib/rails/application/bootstrap.rb +9 -17
- data/lib/rails/application/configuration.rb +177 -27
- data/lib/rails/application/default_middleware_stack.rb +7 -3
- data/lib/rails/application/dummy_erb_compiler.rb +18 -0
- data/lib/rails/application/finisher.rb +69 -2
- data/lib/rails/application/routes_reloader.rb +9 -19
- data/lib/rails/application.rb +96 -66
- data/lib/rails/application_controller.rb +0 -1
- data/lib/rails/autoloaders.rb +48 -0
- data/lib/rails/backtrace_cleaner.rb +14 -21
- data/lib/rails/code_statistics.rb +8 -6
- data/lib/rails/code_statistics_calculator.rb +6 -6
- data/lib/rails/command/actions.rb +10 -0
- data/lib/rails/command/base.rb +17 -5
- data/lib/rails/command/behavior.rb +8 -49
- data/lib/rails/command/environment_argument.rb +9 -16
- data/lib/rails/command/spellchecker.rb +57 -0
- data/lib/rails/command.rb +18 -11
- data/lib/rails/commands/console/console_command.rb +6 -0
- data/lib/rails/commands/credentials/USAGE +33 -0
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/credentials/credentials_command.rb +78 -21
- data/lib/rails/commands/db/system/change/change_command.rb +25 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +66 -51
- data/lib/rails/commands/dev/dev_command.rb +19 -0
- data/lib/rails/commands/encrypted/USAGE +28 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +5 -4
- data/lib/rails/commands/generate/generate_command.rb +1 -1
- data/lib/rails/commands/help/help_command.rb +1 -1
- data/lib/rails/commands/initializers/initializers_command.rb +23 -0
- data/lib/rails/commands/new/new_command.rb +2 -2
- data/lib/rails/commands/notes/notes_command.rb +29 -0
- data/lib/rails/commands/plugin/plugin_command.rb +1 -1
- data/lib/rails/commands/rake/rake_command.rb +9 -8
- data/lib/rails/commands/routes/routes_command.rb +37 -0
- data/lib/rails/commands/runner/runner_command.rb +13 -9
- data/lib/rails/commands/secrets/USAGE +6 -0
- data/lib/rails/commands/secrets/secrets_command.rb +3 -3
- data/lib/rails/commands/server/server_command.rb +92 -56
- data/lib/rails/commands/test/test_command.rb +2 -2
- data/lib/rails/configuration.rb +48 -19
- data/lib/rails/engine/configuration.rb +6 -2
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +63 -35
- data/lib/rails/gem_version.rb +2 -2
- data/lib/rails/generators/actions/create_migration.rb +5 -1
- data/lib/rails/generators/actions.rb +89 -56
- data/lib/rails/generators/app_base.rb +80 -108
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/base.rb +19 -12
- data/lib/rails/generators/database.rb +57 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -2
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -1
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +7 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +9 -1
- data/lib/rails/generators/erb.rb +0 -1
- data/lib/rails/generators/generated_attribute.rb +50 -31
- data/lib/rails/generators/migration.rb +3 -3
- data/lib/rails/generators/model_helpers.rb +33 -2
- data/lib/rails/generators/named_base.rb +3 -7
- data/lib/rails/generators/rails/app/USAGE +2 -1
- data/lib/rails/generators/rails/app/app_generator.rb +127 -84
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +18 -21
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +6 -0
- 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 +23 -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 +6 -5
- 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 +9 -9
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +9 -0
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +11 -3
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +16 -7
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +4 -5
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +13 -12
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +13 -12
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +16 -15
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +11 -10
- 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 +22 -5
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +43 -17
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +26 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -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/content_security_policy.rb.tt +7 -0
- 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 +63 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -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 +13 -4
- 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/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 +10 -7
- data/lib/rails/generators/rails/app/templates/package.json.tt +8 -2
- data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -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 +9 -2
- data/lib/rails/generators/rails/assets/USAGE +3 -7
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -1
- 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 +10 -39
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +6 -7
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +65 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +10 -7
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -0
- data/lib/rails/generators/rails/generator/USAGE +2 -2
- data/lib/rails/generators/rails/generator/generator_generator.rb +0 -1
- 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/helper/helper_generator.rb +5 -0
- 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 +32 -56
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +18 -18
- 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 +1 -2
- 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/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +14 -11
- 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/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 -4
- 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 +19 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +2 -2
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +2 -2
- data/lib/rails/generators/rails/system_test/USAGE +2 -2
- data/lib/rails/generators/rails/task/USAGE +3 -3
- data/lib/rails/generators/resource_helpers.rb +1 -6
- 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/generator_generator.rb +0 -1
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +5 -0
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +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 +3 -3
- 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/scaffold_generator.rb +12 -3
- 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/test_unit/scaffold/templates/system_test.rb.tt +10 -2
- data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
- data/lib/rails/generators/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/behaviour.rb +4 -2
- data/lib/rails/generators.rb +38 -24
- data/lib/rails/info.rb +4 -4
- data/lib/rails/info_controller.rb +2 -3
- data/lib/rails/mailers_controller.rb +10 -4
- data/lib/rails/paths.rb +26 -10
- data/lib/rails/rack/logger.rb +5 -6
- data/lib/rails/railtie/configurable.rb +0 -1
- data/lib/rails/railtie/configuration.rb +3 -3
- data/lib/rails/railtie.rb +33 -13
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +0 -1
- data/lib/rails/source_annotation_extractor.rb +124 -117
- data/lib/rails/tasks/engine.rake +1 -4
- data/lib/rails/tasks/framework.rake +13 -3
- data/lib/rails/tasks/log.rake +0 -1
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/statistics.rake +5 -1
- data/lib/rails/tasks/yarn.rake +14 -1
- data/lib/rails/tasks/zeitwerk.rake +69 -0
- data/lib/rails/tasks.rb +1 -4
- data/lib/rails/templates/rails/mailers/email.html.erb +11 -7
- data/lib/rails/templates/rails/welcome/index.html.erb +3 -3
- data/lib/rails/test_help.rb +11 -9
- data/lib/rails/test_unit/reporter.rb +3 -2
- data/lib/rails/test_unit/runner.rb +25 -8
- data/lib/rails/test_unit/testing.rake +7 -1
- data/lib/rails.rb +10 -8
- metadata +45 -39
- 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/app/assets/javascripts/cable.js.tt +0 -13
- data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
- data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -34
- 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_5_2.rb.tt +0 -35
- data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
- 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 -10
- data/lib/rails/tasks/initializers.rake +0 -8
- data/lib/rails/tasks/routes.rake +0 -31
data/lib/rails/paths.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "pathname"
|
4
|
+
|
3
5
|
module Rails
|
4
6
|
module Paths
|
5
7
|
# This object is an extended hash that behaves as root of the <tt>Rails::Paths</tt> system.
|
@@ -98,7 +100,6 @@ module Rails
|
|
98
100
|
end
|
99
101
|
|
100
102
|
private
|
101
|
-
|
102
103
|
def filter_by(&block)
|
103
104
|
all_paths.find_all(&block).flat_map { |path|
|
104
105
|
paths = path.existent
|
@@ -113,10 +114,11 @@ module Rails
|
|
113
114
|
attr_accessor :glob
|
114
115
|
|
115
116
|
def initialize(root, current, paths, options = {})
|
116
|
-
@paths
|
117
|
-
@current
|
118
|
-
@root
|
119
|
-
@glob
|
117
|
+
@paths = paths
|
118
|
+
@current = current
|
119
|
+
@root = root
|
120
|
+
@glob = options[:glob]
|
121
|
+
@exclude = options[:exclude]
|
120
122
|
|
121
123
|
options[:autoload_once] ? autoload_once! : skip_autoload_once!
|
122
124
|
options[:eager_load] ? eager_load! : skip_eager_load!
|
@@ -180,6 +182,14 @@ module Rails
|
|
180
182
|
@paths
|
181
183
|
end
|
182
184
|
|
185
|
+
def paths
|
186
|
+
raise "You need to set a path root" unless @root.path
|
187
|
+
|
188
|
+
map do |p|
|
189
|
+
Pathname.new(@root.path).join(p)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
183
193
|
def extensions # :nodoc:
|
184
194
|
$1.split(",") if @glob =~ /\{([\S]+)\}/
|
185
195
|
end
|
@@ -189,13 +199,11 @@ module Rails
|
|
189
199
|
raise "You need to set a path root" unless @root.path
|
190
200
|
result = []
|
191
201
|
|
192
|
-
each do |
|
193
|
-
path = File.expand_path(
|
202
|
+
each do |path|
|
203
|
+
path = File.expand_path(path, @root.path)
|
194
204
|
|
195
205
|
if @glob && File.directory?(path)
|
196
|
-
|
197
|
-
result.concat(Dir.glob(@glob).map { |file| File.join path, file }.sort)
|
198
|
-
end
|
206
|
+
result.concat files_in(path)
|
199
207
|
else
|
200
208
|
result << path
|
201
209
|
end
|
@@ -222,6 +230,14 @@ module Rails
|
|
222
230
|
end
|
223
231
|
|
224
232
|
alias to_a expanded
|
233
|
+
|
234
|
+
private
|
235
|
+
def files_in(path)
|
236
|
+
files = Dir.glob(@glob, base: path)
|
237
|
+
files -= @exclude if @exclude
|
238
|
+
files.map! { |file| File.join(path, file) }
|
239
|
+
files.sort
|
240
|
+
end
|
225
241
|
end
|
226
242
|
end
|
227
243
|
end
|
data/lib/rails/rack/logger.rb
CHANGED
@@ -30,14 +30,13 @@ module Rails
|
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
|
-
|
34
33
|
def call_app(request, env) # :doc:
|
35
34
|
instrumenter = ActiveSupport::Notifications.instrumenter
|
36
35
|
instrumenter.start "request.action_dispatch", request: request
|
37
36
|
logger.info { started_request_message(request) }
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
status, headers, body = @app.call(env)
|
38
|
+
body = ::Rack::BodyProxy.new(body) { finish(request) }
|
39
|
+
[status, headers, body]
|
41
40
|
rescue Exception
|
42
41
|
finish(request)
|
43
42
|
raise
|
@@ -48,9 +47,9 @@ module Rails
|
|
48
47
|
# Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700
|
49
48
|
def started_request_message(request) # :doc:
|
50
49
|
'Started %s "%s" for %s at %s' % [
|
51
|
-
request.
|
50
|
+
request.raw_request_method,
|
52
51
|
request.filtered_path,
|
53
|
-
request.
|
52
|
+
request.remote_ip,
|
54
53
|
Time.now.to_default_s ]
|
55
54
|
end
|
56
55
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rails/configuration"
|
4
|
+
require "active_support/core_ext/symbol/starts_ends_with"
|
4
5
|
|
5
6
|
module Rails
|
6
7
|
class Railtie
|
@@ -87,10 +88,9 @@ module Rails
|
|
87
88
|
end
|
88
89
|
|
89
90
|
private
|
90
|
-
|
91
91
|
def method_missing(name, *args, &blk)
|
92
|
-
if name.
|
93
|
-
@@options[
|
92
|
+
if name.end_with?("=")
|
93
|
+
@@options[:"#{name[0..-2]}"] = args.first
|
94
94
|
elsif @@options.key?(name)
|
95
95
|
@@options[name]
|
96
96
|
else
|
data/lib/rails/railtie.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rails/initializable"
|
4
|
+
require "active_support/descendants_tracker"
|
4
5
|
require "active_support/inflector"
|
5
6
|
require "active_support/core_ext/module/introspection"
|
6
7
|
require "active_support/core_ext/module/delegation"
|
@@ -42,7 +43,7 @@ module Rails
|
|
42
43
|
# end
|
43
44
|
#
|
44
45
|
# # lib/my_gem.rb
|
45
|
-
# require
|
46
|
+
# require "my_gem/railtie" if defined?(Rails::Railtie)
|
46
47
|
#
|
47
48
|
# == Initializers
|
48
49
|
#
|
@@ -91,7 +92,7 @@ module Rails
|
|
91
92
|
#
|
92
93
|
# class MyRailtie < Rails::Railtie
|
93
94
|
# rake_tasks do
|
94
|
-
# load
|
95
|
+
# load "path/to/my_railtie.tasks"
|
95
96
|
# end
|
96
97
|
# end
|
97
98
|
#
|
@@ -101,13 +102,30 @@ module Rails
|
|
101
102
|
#
|
102
103
|
# class MyRailtie < Rails::Railtie
|
103
104
|
# generators do
|
104
|
-
# require
|
105
|
+
# require "path/to/my_railtie_generator"
|
105
106
|
# end
|
106
107
|
# end
|
107
108
|
#
|
108
109
|
# Since filenames on the load path are shared across gems, be sure that files you load
|
109
110
|
# through a railtie have unique names.
|
110
111
|
#
|
112
|
+
# == Run another program when the Rails server starts
|
113
|
+
#
|
114
|
+
# In development, it's very usual to have to run another process next to the Rails Server. In example
|
115
|
+
# you might want to start the Webpack or React server. Or maybe you need to run your job scheduler process
|
116
|
+
# like Sidekiq. This is usually done by opening a new shell and running the program from here.
|
117
|
+
#
|
118
|
+
# Rails allow you to specify a +server+ block which will get called when a Rails server starts.
|
119
|
+
# This way, your users don't need to remember to have to open a new shell and run another program, making
|
120
|
+
# this less confusing for everyone.
|
121
|
+
# It can be used like this:
|
122
|
+
#
|
123
|
+
# class MyRailtie < Rails::Railtie
|
124
|
+
# server do
|
125
|
+
# WebpackServer.start
|
126
|
+
# end
|
127
|
+
# end
|
128
|
+
#
|
111
129
|
# == Application and Engine
|
112
130
|
#
|
113
131
|
# An engine is nothing more than a railtie with some initializers already set. And since
|
@@ -118,6 +136,7 @@ module Rails
|
|
118
136
|
class Railtie
|
119
137
|
autoload :Configuration, "rails/railtie/configuration"
|
120
138
|
|
139
|
+
extend ActiveSupport::DescendantsTracker
|
121
140
|
include Initializable
|
122
141
|
|
123
142
|
ABSTRACT_RAILTIES = %w(Rails::Railtie Rails::Engine Rails::Application)
|
@@ -127,13 +146,7 @@ module Rails
|
|
127
146
|
delegate :config, to: :instance
|
128
147
|
|
129
148
|
def subclasses
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
def inherited(base)
|
134
|
-
unless base.abstract_railtie?
|
135
|
-
subclasses << base
|
136
|
-
end
|
149
|
+
super.reject(&:abstract_railtie?)
|
137
150
|
end
|
138
151
|
|
139
152
|
def rake_tasks(&blk)
|
@@ -152,6 +165,10 @@ module Rails
|
|
152
165
|
register_block_for(:generators, &blk)
|
153
166
|
end
|
154
167
|
|
168
|
+
def server(&blk)
|
169
|
+
register_block_for(:server, &blk)
|
170
|
+
end
|
171
|
+
|
155
172
|
def abstract_railtie?
|
156
173
|
ABSTRACT_RAILTIES.include?(name)
|
157
174
|
end
|
@@ -192,6 +209,7 @@ module Rails
|
|
192
209
|
super
|
193
210
|
end
|
194
211
|
end
|
212
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
195
213
|
|
196
214
|
# receives an instance variable identifier, set the variable value if is
|
197
215
|
# blank and append given block to value, which will be used later in
|
@@ -224,11 +242,10 @@ module Rails
|
|
224
242
|
end
|
225
243
|
|
226
244
|
def railtie_namespace #:nodoc:
|
227
|
-
@railtie_namespace ||= self.class.
|
245
|
+
@railtie_namespace ||= self.class.module_parents.detect { |n| n.respond_to?(:railtie_namespace) }
|
228
246
|
end
|
229
247
|
|
230
248
|
protected
|
231
|
-
|
232
249
|
def run_console_blocks(app) #:nodoc:
|
233
250
|
each_registered_block(:console) { |block| block.call(app) }
|
234
251
|
end
|
@@ -246,8 +263,11 @@ module Rails
|
|
246
263
|
each_registered_block(:rake_tasks) { |block| instance_exec(app, &block) }
|
247
264
|
end
|
248
265
|
|
249
|
-
|
266
|
+
def run_server_blocks(app) #:nodoc:
|
267
|
+
each_registered_block(:server) { |block| block.call(app) }
|
268
|
+
end
|
250
269
|
|
270
|
+
private
|
251
271
|
# run `&block` in every registered block in `#register_block_for`
|
252
272
|
def each_registered_block(type, &block)
|
253
273
|
klass = self.class
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.
|
3
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5.0") && RUBY_ENGINE == "ruby"
|
4
4
|
desc = defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
|
5
5
|
abort <<-end_message
|
6
6
|
|
7
|
-
Rails
|
7
|
+
Rails 6 requires Ruby 2.5.0 or newer.
|
8
8
|
|
9
9
|
You're running
|
10
10
|
#{desc}
|
11
11
|
|
12
|
-
Please upgrade to Ruby 2.
|
12
|
+
Please upgrade to Ruby 2.5.0 or newer to continue.
|
13
13
|
|
14
14
|
end_message
|
15
15
|
end
|
data/lib/rails/secrets.rb
CHANGED
@@ -1,141 +1,148 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# the
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
Annotation = Struct.new(:line, :tag, :text) do
|
19
|
-
def self.directories
|
20
|
-
@@directories ||= %w(app config db lib test) + (ENV["SOURCE_ANNOTATION_DIRECTORIES"] || "").split(",")
|
21
|
-
end
|
3
|
+
module Rails
|
4
|
+
# Implements the logic behind <tt>Rails::Command::NotesCommand</tt>. See <tt>rails notes --help</tt> for usage information.
|
5
|
+
#
|
6
|
+
# Annotation objects are triplets <tt>:line</tt>, <tt>:tag</tt>, <tt>:text</tt> that
|
7
|
+
# represent the line where the annotation lives, its tag, and its text. Note
|
8
|
+
# the filename is not stored.
|
9
|
+
#
|
10
|
+
# Annotations are looked for in comments and modulus whitespace they have to
|
11
|
+
# start with the tag optionally followed by a colon. Everything up to the end
|
12
|
+
# of the line (or closing ERB comment tag) is considered to be their text.
|
13
|
+
class SourceAnnotationExtractor
|
14
|
+
class Annotation < Struct.new(:line, :tag, :text)
|
15
|
+
def self.directories
|
16
|
+
@@directories ||= %w(app config db lib test)
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
# Registers additional directories to be included
|
20
|
+
# Rails::SourceAnnotationExtractor::Annotation.register_directories("spec", "another")
|
21
|
+
def self.register_directories(*dirs)
|
22
|
+
directories.push(*dirs)
|
23
|
+
end
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
def self.tags
|
26
|
+
@@tags ||= %w(OPTIMIZE FIXME TODO)
|
27
|
+
end
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
# Registers additional tags
|
30
|
+
# Rails::SourceAnnotationExtractor::Annotation.register_tags("TESTME", "DEPRECATEME")
|
31
|
+
def self.register_tags(*additional_tags)
|
32
|
+
tags.push(*additional_tags)
|
33
|
+
end
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
def self.extensions
|
36
|
+
@@extensions ||= {}
|
37
|
+
end
|
42
38
|
|
43
|
-
|
39
|
+
# Registers new Annotations File Extensions
|
40
|
+
# Rails::SourceAnnotationExtractor::Annotation.register_extensions("css", "scss", "sass", "less", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
|
41
|
+
def self.register_extensions(*exts, &block)
|
42
|
+
extensions[/\.(#{exts.join("|")})$/] = block
|
43
|
+
end
|
44
|
+
|
45
|
+
register_extensions("builder", "rb", "rake", "yml", "yaml", "ruby") { |tag| /#\s*(#{tag}):?\s*(.*)$/ }
|
46
|
+
register_extensions("css", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
|
47
|
+
register_extensions("erb") { |tag| /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/ }
|
48
|
+
|
49
|
+
# Returns a representation of the annotation that looks like this:
|
50
|
+
#
|
51
|
+
# [126] [TODO] This algorithm is simple and clearly correct, make it faster.
|
52
|
+
#
|
53
|
+
# If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
|
54
|
+
# Otherwise the string contains just line and text.
|
55
|
+
def to_s(options = {})
|
56
|
+
s = +"[#{line.to_s.rjust(options[:indent])}] "
|
57
|
+
s << "[#{tag}] " if options[:tag]
|
58
|
+
s << text
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Prints all annotations with tag +tag+ under the root directories +app+,
|
63
|
+
# +config+, +db+, +lib+, and +test+ (recursively).
|
44
64
|
#
|
45
|
-
#
|
65
|
+
# If +tag+ is <tt>nil</tt>, annotations with either default or registered tags are printed.
|
46
66
|
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
67
|
+
# Specific directories can be explicitly set using the <tt>:dirs</tt> key in +options+.
|
68
|
+
#
|
69
|
+
# Rails::SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true
|
70
|
+
#
|
71
|
+
# If +options+ has a <tt>:tag</tt> flag, it will be passed to each annotation's +to_s+.
|
72
|
+
#
|
73
|
+
# See <tt>#find_in</tt> for a list of file extensions that will be taken into account.
|
74
|
+
#
|
75
|
+
# This class method is the single entry point for the `rails notes` command.
|
76
|
+
def self.enumerate(tag = nil, options = {})
|
77
|
+
tag ||= Annotation.tags.join("|")
|
78
|
+
extractor = new(tag)
|
79
|
+
dirs = options.delete(:dirs) || Annotation.directories
|
80
|
+
extractor.display(extractor.find(dirs), options)
|
53
81
|
end
|
54
|
-
end
|
55
82
|
|
56
|
-
|
57
|
-
# +config+, +db+, +lib+, and +test+ (recursively).
|
58
|
-
#
|
59
|
-
# Additional directories may be added using a comma-delimited list set using
|
60
|
-
# <tt>ENV['SOURCE_ANNOTATION_DIRECTORIES']</tt>.
|
61
|
-
#
|
62
|
-
# Directories may also be explicitly set using the <tt>:dirs</tt> key in +options+.
|
63
|
-
#
|
64
|
-
# SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true
|
65
|
-
#
|
66
|
-
# If +options+ has a <tt>:tag</tt> flag, it will be passed to each annotation's +to_s+.
|
67
|
-
#
|
68
|
-
# See <tt>#find_in</tt> for a list of file extensions that will be taken into account.
|
69
|
-
#
|
70
|
-
# This class method is the single entry point for the rake tasks.
|
71
|
-
def self.enumerate(tag, options = {})
|
72
|
-
extractor = new(tag)
|
73
|
-
dirs = options.delete(:dirs) || Annotation.directories
|
74
|
-
extractor.display(extractor.find(dirs), options)
|
75
|
-
end
|
76
|
-
|
77
|
-
attr_reader :tag
|
78
|
-
|
79
|
-
def initialize(tag)
|
80
|
-
@tag = tag
|
81
|
-
end
|
83
|
+
attr_reader :tag
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
|
87
|
-
end
|
85
|
+
def initialize(tag)
|
86
|
+
@tag = tag
|
87
|
+
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
results = {}
|
95
|
-
|
96
|
-
Dir.glob("#{dir}/*") do |item|
|
97
|
-
next if File.basename(item)[0] == ?.
|
98
|
-
|
99
|
-
if File.directory?(item)
|
100
|
-
results.update(find_in(item))
|
101
|
-
else
|
102
|
-
extension = Annotation.extensions.detect do |regexp, _block|
|
103
|
-
regexp.match(item)
|
104
|
-
end
|
89
|
+
# Returns a hash that maps filenames under +dirs+ (recursively) to arrays
|
90
|
+
# with their annotations.
|
91
|
+
def find(dirs)
|
92
|
+
dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
|
93
|
+
end
|
105
94
|
|
106
|
-
|
107
|
-
|
108
|
-
|
95
|
+
# Returns a hash that maps filenames under +dir+ (recursively) to arrays
|
96
|
+
# with their annotations. Files with extensions registered in
|
97
|
+
# <tt>Rails::SourceAnnotationExtractor::Annotation.extensions</tt> are
|
98
|
+
# taken into account. Only files with annotations are included.
|
99
|
+
def find_in(dir)
|
100
|
+
results = {}
|
101
|
+
|
102
|
+
Dir.glob("#{dir}/*") do |item|
|
103
|
+
next if File.basename(item).start_with?(".")
|
104
|
+
|
105
|
+
if File.directory?(item)
|
106
|
+
results.update(find_in(item))
|
107
|
+
else
|
108
|
+
extension = Annotation.extensions.detect do |regexp, _block|
|
109
|
+
regexp.match(item)
|
110
|
+
end
|
111
|
+
|
112
|
+
if extension
|
113
|
+
pattern = extension.last.call(tag)
|
114
|
+
results.update(extract_annotations_from(item, pattern)) if pattern
|
115
|
+
end
|
109
116
|
end
|
110
117
|
end
|
111
|
-
end
|
112
118
|
|
113
|
-
|
114
|
-
|
119
|
+
results
|
120
|
+
end
|
115
121
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
122
|
+
# If +file+ is the filename of a file that contains annotations this method returns
|
123
|
+
# a hash with a single entry that maps +file+ to an array of its annotations.
|
124
|
+
# Otherwise it returns an empty hash.
|
125
|
+
def extract_annotations_from(file, pattern)
|
126
|
+
lineno = 0
|
127
|
+
result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
|
128
|
+
lineno += 1
|
129
|
+
next list unless line =~ pattern
|
130
|
+
list << Annotation.new(lineno, $1, $2)
|
131
|
+
end
|
132
|
+
result.empty? ? {} : { file => result }
|
125
133
|
end
|
126
|
-
result.empty? ? {} : { file => result }
|
127
|
-
end
|
128
134
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
# Prints the mapping from filenames to annotations in +results+ ordered by filename.
|
136
|
+
# The +options+ hash is passed to each annotation's +to_s+.
|
137
|
+
def display(results, options = {})
|
138
|
+
options[:indent] = results.flat_map { |f, a| a.map(&:line) }.max.to_s.size
|
139
|
+
results.keys.sort.each do |file|
|
140
|
+
puts "#{file}:"
|
141
|
+
results[file].each do |note|
|
142
|
+
puts " * #{note.to_s(options)}"
|
143
|
+
end
|
144
|
+
puts
|
137
145
|
end
|
138
|
-
puts
|
139
146
|
end
|
140
147
|
end
|
141
148
|
end
|
data/lib/rails/tasks/engine.rake
CHANGED
@@ -53,7 +53,7 @@ namespace :db do
|
|
53
53
|
desc "Rolls the schema back to the previous version (specify steps w/ STEP=n)."
|
54
54
|
app_task "rollback"
|
55
55
|
|
56
|
-
desc "
|
56
|
+
desc "Creates a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`)"
|
57
57
|
app_task "schema:dump"
|
58
58
|
|
59
59
|
desc "Load a schema.rb file into the database"
|
@@ -65,9 +65,6 @@ namespace :db do
|
|
65
65
|
desc "Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the database first)"
|
66
66
|
app_task "setup"
|
67
67
|
|
68
|
-
desc "Dump the database structure to an SQL file"
|
69
|
-
app_task "structure:dump"
|
70
|
-
|
71
68
|
desc "Retrieves the current schema version number"
|
72
69
|
app_task "version"
|
73
70
|
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
namespace :app do
|
4
4
|
desc "Update configs and some other initially generated files (or use just update:configs or update:bin)"
|
5
|
-
task update: [ "update:configs", "update:bin", "update:upgrade_guide_info" ]
|
5
|
+
task update: [ "update:configs", "update:bin", "update:active_storage", "update:upgrade_guide_info" ]
|
6
6
|
|
7
7
|
desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
|
8
8
|
task template: :environment do
|
9
9
|
template = ENV["LOCATION"]
|
10
10
|
raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank?
|
11
|
-
template = File.expand_path(template)
|
11
|
+
template = File.expand_path(template) unless %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}.match?(template)
|
12
12
|
require "rails/generators"
|
13
13
|
require "rails/generators/rails/app/app_generator"
|
14
14
|
generator = Rails::Generators::AppGenerator.new [Rails.root], {}, { destination_root: Rails.root }
|
@@ -40,7 +40,7 @@ namespace :app do
|
|
40
40
|
namespace :update do
|
41
41
|
require "rails/app_updater"
|
42
42
|
|
43
|
-
# desc "Update config
|
43
|
+
# desc "Update config files from your current rails install"
|
44
44
|
task :configs do
|
45
45
|
Rails::AppUpdater.invoke_from_app_generator :create_boot_file
|
46
46
|
Rails::AppUpdater.invoke_from_app_generator :update_config_files
|
@@ -51,8 +51,18 @@ namespace :app do
|
|
51
51
|
Rails::AppUpdater.invoke_from_app_generator :update_bin_files
|
52
52
|
end
|
53
53
|
|
54
|
+
task :active_storage do
|
55
|
+
Rails::AppUpdater.invoke_from_app_generator :update_active_storage
|
56
|
+
end
|
57
|
+
|
54
58
|
task :upgrade_guide_info do
|
55
59
|
Rails::AppUpdater.invoke_from_app_generator :display_upgrade_guide_info
|
56
60
|
end
|
57
61
|
end
|
62
|
+
|
63
|
+
namespace :binstub do
|
64
|
+
task :yarn do
|
65
|
+
Rails::AppUpdater.invoke_from_app_generator :update_bin_yarn
|
66
|
+
end
|
67
|
+
end
|
58
68
|
end
|
data/lib/rails/tasks/log.rake
CHANGED
data/lib/rails/tasks/misc.rake
CHANGED
@@ -12,7 +12,7 @@ task about: :environment do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
namespace :time do
|
15
|
-
desc "List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)"
|
15
|
+
desc "List all time zones, list by two-letter country code (`bin/rails time:zones[US]`), or list by UTC offset (`bin/rails time:zones[-8]`)"
|
16
16
|
task :zones, :country_or_offset do |t, args|
|
17
17
|
zones, offset = ActiveSupport::TimeZone.all, nil
|
18
18
|
|
@@ -3,20 +3,24 @@
|
|
3
3
|
# While global constants are bad, many 3rd party tools depend on this one (e.g
|
4
4
|
# rspec-rails & cucumber-rails). So a deprecation warning is needed if we want
|
5
5
|
# to remove it.
|
6
|
-
STATS_DIRECTORIES
|
6
|
+
STATS_DIRECTORIES ||= [
|
7
7
|
%w(Controllers app/controllers),
|
8
8
|
%w(Helpers app/helpers),
|
9
9
|
%w(Jobs app/jobs),
|
10
10
|
%w(Models app/models),
|
11
11
|
%w(Mailers app/mailers),
|
12
|
+
%w(Mailboxes app/mailboxes),
|
12
13
|
%w(Channels app/channels),
|
13
14
|
%w(JavaScripts app/assets/javascripts),
|
15
|
+
%w(JavaScript app/javascript),
|
14
16
|
%w(Libraries lib/),
|
15
17
|
%w(APIs app/apis),
|
16
18
|
%w(Controller\ tests test/controllers),
|
17
19
|
%w(Helper\ tests test/helpers),
|
18
20
|
%w(Model\ tests test/models),
|
19
21
|
%w(Mailer\ tests test/mailers),
|
22
|
+
%w(Mailbox\ tests test/mailboxes),
|
23
|
+
%w(Channel\ tests test/channels),
|
20
24
|
%w(Job\ tests test/jobs),
|
21
25
|
%w(Integration\ tests test/integration),
|
22
26
|
%w(System\ tests test/system),
|