railties 5.2.7.1 → 6.1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +276 -158
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +39 -33
- data/README.rdoc +3 -3
- data/lib/minitest/rails_plugin.rb +23 -12
- data/lib/rails/all.rb +4 -0
- data/lib/rails/api/generator.rb +2 -1
- data/lib/rails/api/task.rb +18 -1
- data/lib/rails/app_loader.rb +2 -2
- data/lib/rails/app_updater.rb +3 -1
- data/lib/rails/application/bootstrap.rb +9 -17
- data/lib/rails/application/configuration.rb +184 -26
- 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 +68 -1
- data/lib/rails/application/routes_reloader.rb +9 -3
- data/lib/rails/application.rb +86 -65
- 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/base.rb +13 -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 +16 -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 +76 -19
- 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 +1 -1
- data/lib/rails/commands/encrypted/encrypted_command.rb +4 -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 +59 -49
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions/create_migration.rb +7 -1
- data/lib/rails/generators/actions.rb +89 -56
- data/lib/rails/generators/app_base.rb +90 -106
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/base.rb +15 -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 +120 -84
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +17 -20
- 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 +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 +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 +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/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +10 -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 +8 -8
- 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/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 +33 -56
- 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 +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 +8 -4
- 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/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 +8 -4
- data/lib/rails/paths.rb +26 -10
- data/lib/rails/rack/logger.rb +1 -2
- 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 +12 -2
- 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 -2
- data/lib/rails/tasks/zeitwerk.rake +69 -0
- data/lib/rails/tasks.rb +1 -4
- data/lib/rails/templates/rails/mailers/email.html.erb +1 -0
- 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 +46 -40
- 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 -38
- 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
@@ -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 <tt>rails notes</tt> 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 }
|
@@ -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),
|
data/lib/rails/tasks/yarn.rake
CHANGED
@@ -8,11 +8,23 @@ namespace :yarn do
|
|
8
8
|
node_env = ENV.fetch("NODE_ENV") do
|
9
9
|
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
yarn_flags =
|
13
|
+
if `#{RbConfig.ruby} "#{Rails.root}/bin/yarn" --version`.start_with?("1")
|
14
|
+
"--no-progress --frozen-lockfile"
|
15
|
+
else
|
16
|
+
"--immutable"
|
17
|
+
end
|
18
|
+
|
19
|
+
system({ "NODE_ENV" => node_env }, "#{RbConfig.ruby} \"#{Rails.root}/bin/yarn\" install #{yarn_flags}")
|
20
|
+
rescue Errno::ENOENT
|
21
|
+
$stderr.puts "bin/yarn was not found."
|
22
|
+
$stderr.puts "Please run `bundle exec rails app:update:bin` to create it."
|
23
|
+
exit 1
|
12
24
|
end
|
13
25
|
end
|
14
26
|
|
15
27
|
# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use.
|
16
|
-
if Rake::Task.task_defined?("assets:precompile")
|
28
|
+
if Rake::Task.task_defined?("assets:precompile") && File.exist?(Rails.root.join("bin", "yarn"))
|
17
29
|
Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
|
18
30
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ensure_zeitwerk_mode = ->() do
|
4
|
+
unless Rails.autoloaders.zeitwerk_enabled?
|
5
|
+
abort "Please, enable :zeitwerk mode in config/application.rb and try again."
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
eager_load = ->() do
|
10
|
+
puts "Hold on, I am eager loading the application."
|
11
|
+
Zeitwerk::Loader.eager_load_all
|
12
|
+
end
|
13
|
+
|
14
|
+
report_not_checked = ->(not_checked) do
|
15
|
+
puts
|
16
|
+
puts <<~EOS
|
17
|
+
WARNING: The following directories will only be checked if you configure
|
18
|
+
them to be eager loaded:
|
19
|
+
EOS
|
20
|
+
puts
|
21
|
+
|
22
|
+
not_checked.each { |dir| puts " #{dir}" }
|
23
|
+
puts
|
24
|
+
|
25
|
+
puts <<~EOS
|
26
|
+
You may verify them manually, or add them to config.eager_load_paths
|
27
|
+
in config/application.rb and run zeitwerk:check again.
|
28
|
+
EOS
|
29
|
+
puts
|
30
|
+
end
|
31
|
+
|
32
|
+
report = ->(not_checked) do
|
33
|
+
if not_checked.any?
|
34
|
+
report_not_checked[not_checked]
|
35
|
+
puts "Otherwise, all is good!"
|
36
|
+
else
|
37
|
+
puts "All is good!"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
namespace :zeitwerk do
|
42
|
+
desc "Checks project structure for Zeitwerk compatibility"
|
43
|
+
task check: :environment do
|
44
|
+
ensure_zeitwerk_mode[]
|
45
|
+
|
46
|
+
begin
|
47
|
+
eager_load[]
|
48
|
+
rescue NameError => e
|
49
|
+
if e.message =~ /expected file .*? to define constant [\w:]+/
|
50
|
+
abort $&.sub(/expected file #{Regexp.escape(Rails.root.to_s)}./, "expected file ")
|
51
|
+
else
|
52
|
+
raise
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
require "active_support/core_ext/object/try"
|
57
|
+
eager_load_paths = Rails.configuration.eager_load_namespaces.map do |eln|
|
58
|
+
# Quick regression fix for 6.0.3 to support namespaces that do not have
|
59
|
+
# eager load paths, like the recently added i18n. I'll rewrite this task.
|
60
|
+
eln.try(:config).try(:eager_load_paths)
|
61
|
+
end.compact.flatten
|
62
|
+
|
63
|
+
not_checked = ActiveSupport::Dependencies.autoload_paths - eager_load_paths
|
64
|
+
not_checked.select! { |dir| Dir.exist?(dir) }
|
65
|
+
not_checked.reject! { |dir| Dir.empty?(dir) }
|
66
|
+
|
67
|
+
report[not_checked]
|
68
|
+
end
|
69
|
+
end
|
data/lib/rails/tasks.rb
CHANGED
@@ -4,17 +4,14 @@ require "rake"
|
|
4
4
|
|
5
5
|
# Load Rails Rakefile extensions
|
6
6
|
%w(
|
7
|
-
annotations
|
8
|
-
dev
|
9
7
|
framework
|
10
|
-
initializers
|
11
8
|
log
|
12
9
|
middleware
|
13
10
|
misc
|
14
11
|
restart
|
15
|
-
routes
|
16
12
|
tmp
|
17
13
|
yarn
|
14
|
+
zeitwerk
|
18
15
|
).tap { |arr|
|
19
16
|
arr << "statistics" if Rake.application.current_scope.empty?
|
20
17
|
}.each do |task|
|