railties 6.1.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +121 -276
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +16 -16
- data/README.rdoc +1 -2
- data/lib/rails/all.rb +0 -1
- data/lib/rails/api/task.rb +1 -1
- data/lib/rails/app_updater.rb +3 -5
- data/lib/rails/application/bootstrap.rb +21 -5
- data/lib/rails/application/configuration.rb +79 -33
- data/lib/rails/application/default_middleware_stack.rb +7 -3
- data/lib/rails/application/finisher.rb +42 -85
- data/lib/rails/application/routes_reloader.rb +8 -0
- data/lib/rails/application.rb +32 -51
- data/lib/rails/application_controller.rb +2 -2
- data/lib/rails/autoloaders/inflector.rb +21 -0
- data/lib/rails/autoloaders.rb +12 -16
- data/lib/rails/code_statistics.rb +2 -2
- data/lib/rails/code_statistics_calculator.rb +10 -1
- data/lib/rails/command/base.rb +26 -12
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +1 -1
- data/lib/rails/command.rb +11 -10
- data/lib/rails/commands/credentials/USAGE +4 -2
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +26 -16
- data/lib/rails/commands/credentials/credentials_command.rb +8 -3
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +10 -11
- data/lib/rails/commands/help/USAGE +3 -2
- data/lib/rails/commands/notes/notes_command.rb +2 -2
- data/lib/rails/commands/runner/runner_command.rb +3 -2
- data/lib/rails/commands/server/server_command.rb +2 -5
- data/lib/rails/configuration.rb +18 -23
- data/lib/rails/engine/configuration.rb +3 -3
- data/lib/rails/engine.rb +18 -24
- data/lib/rails/gem_version.rb +2 -2
- data/lib/rails/generators/actions/create_migration.rb +4 -4
- data/lib/rails/generators/actions.rb +35 -13
- data/lib/rails/generators/app_base.rb +140 -102
- data/lib/rails/generators/app_name.rb +1 -1
- data/lib/rails/generators/base.rb +9 -13
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +8 -8
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +11 -28
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
- data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +17 -0
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +8 -17
- data/lib/rails/generators/erb.rb +1 -1
- data/lib/rails/generators/generated_attribute.rb +45 -9
- data/lib/rails/generators/migration.rb +2 -6
- data/lib/rails/generators/model_helpers.rb +1 -1
- data/lib/rails/generators/named_base.rb +11 -11
- data/lib/rails/generators/rails/app/app_generator.rb +54 -93
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +42 -52
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +3 -9
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +1 -4
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +0 -3
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -14
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +0 -1
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +3 -3
- 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 +5 -5
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +6 -12
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +11 -38
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -11
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +19 -25
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +117 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +3 -3
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +4 -1
- data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +0 -5
- data/lib/rails/generators/rails/app/templates/gitignore.tt +3 -1
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
- data/lib/rails/generators/rails/controller/controller_generator.rb +1 -2
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +0 -4
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +1 -1
- data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +42 -24
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +7 -3
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +11 -20
- data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +4 -5
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -5
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +2 -7
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +0 -19
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -5
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +6 -10
- data/lib/rails/generators/resource_helpers.rb +2 -2
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +5 -5
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +7 -7
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +9 -11
- data/lib/rails/generators/testing/behaviour.rb +3 -4
- data/lib/rails/generators.rb +9 -22
- data/lib/rails/info.rb +1 -1
- data/lib/rails/info_controller.rb +1 -3
- data/lib/rails/initializable.rb +1 -1
- data/lib/rails/mailers_controller.rb +2 -4
- data/lib/rails/rack/logger.rb +0 -1
- data/lib/rails/railtie/configuration.rb +1 -2
- data/lib/rails/railtie.rb +31 -14
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +4 -1
- data/lib/rails/source_annotation_extractor.rb +1 -1
- data/lib/rails/tasks/framework.rake +2 -8
- data/lib/rails/tasks/statistics.rake +3 -1
- data/lib/rails/tasks/tmp.rake +8 -1
- data/lib/rails/tasks/yarn.rake +10 -7
- data/lib/rails/tasks/zeitwerk.rake +2 -10
- data/lib/rails/templates/layouts/application.html.erb +15 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +13 -11
- data/lib/rails/templates/rails/welcome/index.html.erb +62 -47
- data/lib/rails/test_unit/railtie.rb +0 -4
- data/lib/rails/test_unit/runner.rb +16 -9
- data/lib/rails/test_unit/testing.rake +4 -9
- data/lib/rails/welcome_controller.rb +1 -0
- data/lib/rails.rb +5 -0
- metadata +33 -36
- data/lib/rails/command/spellchecker.rb +0 -57
- data/lib/rails/generators/css/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -18
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +0 -6
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +0 -5
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +0 -23
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +0 -9
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -18
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb.tt +0 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +0 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb.tt +0 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb.tt +0 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -63
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +0 -16
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +0 -6
- data/lib/rails/generators/rails/app/templates/package.json.tt +0 -11
- data/lib/rails/generators/rails/assets/USAGE +0 -16
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -26
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
@@ -31,7 +31,7 @@ module Rails
|
|
31
31
|
sslcapath: "--ssl-capath",
|
32
32
|
sslcipher: "--ssl-cipher",
|
33
33
|
sslkey: "--ssl-key"
|
34
|
-
}.
|
34
|
+
}.filter_map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }
|
35
35
|
|
36
36
|
if config[:password] && @options[:include_password]
|
37
37
|
args << "--password=#{config[:password]}"
|
@@ -44,10 +44,14 @@ module Rails
|
|
44
44
|
find_cmd_and_exec(["mysql", "mysql5"], *args)
|
45
45
|
|
46
46
|
when /^postgres|^postgis/
|
47
|
-
ENV["PGUSER"]
|
48
|
-
ENV["PGHOST"]
|
49
|
-
ENV["PGPORT"]
|
50
|
-
ENV["PGPASSWORD"]
|
47
|
+
ENV["PGUSER"] = config[:username] if config[:username]
|
48
|
+
ENV["PGHOST"] = config[:host] if config[:host]
|
49
|
+
ENV["PGPORT"] = config[:port].to_s if config[:port]
|
50
|
+
ENV["PGPASSWORD"] = config[:password].to_s if config[:password] && @options[:include_password]
|
51
|
+
ENV["PGSSLMODE"] = config[:sslmode].to_s if config[:sslmode]
|
52
|
+
ENV["PGSSLCERT"] = config[:sslcert].to_s if config[:sslcert]
|
53
|
+
ENV["PGSSLKEY"] = config[:sslkey].to_s if config[:sslkey]
|
54
|
+
ENV["PGSSLROOTCERT"] = config[:sslrootcert].to_s if config[:sslrootcert]
|
51
55
|
find_cmd_and_exec("psql", db_config.database)
|
52
56
|
|
53
57
|
when "sqlite3"
|
@@ -90,11 +94,6 @@ module Rails
|
|
90
94
|
end
|
91
95
|
end
|
92
96
|
|
93
|
-
def config
|
94
|
-
db_config.configuration_hash
|
95
|
-
end
|
96
|
-
deprecate config: "please use db_config.configuration_hash"
|
97
|
-
|
98
97
|
def db_config
|
99
98
|
return @db_config if defined?(@db_config)
|
100
99
|
|
@@ -102,7 +101,7 @@ module Rails
|
|
102
101
|
# first time around to show a consistent error message to people
|
103
102
|
# relying on 2-level database configuration.
|
104
103
|
|
105
|
-
@db_config = configurations.configs_for(env_name: environment, name: database)
|
104
|
+
@db_config = configurations.configs_for(env_name: environment, name: database, include_hidden: true)
|
106
105
|
|
107
106
|
unless @db_config
|
108
107
|
raise ActiveRecord::AdapterNotSpecified,
|
@@ -6,10 +6,11 @@ The most common rails commands are:
|
|
6
6
|
test:system Run system tests
|
7
7
|
dbconsole Start a console for the database specified in config/database.yml
|
8
8
|
(short-cut alias: "db")
|
9
|
-
<% unless engine?
|
9
|
+
<% unless engine? -%>
|
10
10
|
new Create a new Rails application. "rails new my_app" creates a
|
11
11
|
new application called MyApp in "./my_app"
|
12
|
-
|
12
|
+
plugin new Create a new Rails railtie or engine
|
13
|
+
<% end -%>
|
13
14
|
|
14
15
|
All commands can be run with -h (or --help) for more information.
|
15
16
|
In addition to those commands, there are:
|
@@ -5,7 +5,7 @@ require "rails/source_annotation_extractor"
|
|
5
5
|
module Rails
|
6
6
|
module Command
|
7
7
|
class NotesCommand < Base # :nodoc:
|
8
|
-
class_option :annotations, aliases: "-a", desc: "Filter by specific annotations, e.g. Foobar TODO", type: :array
|
8
|
+
class_option :annotations, aliases: "-a", desc: "Filter by specific annotations, e.g. Foobar TODO", type: :array
|
9
9
|
|
10
10
|
def perform(*)
|
11
11
|
require_application_and_environment!
|
@@ -15,7 +15,7 @@ module Rails
|
|
15
15
|
|
16
16
|
private
|
17
17
|
def display_annotations
|
18
|
-
annotations = options[:annotations]
|
18
|
+
annotations = options[:annotations] || Rails::SourceAnnotationExtractor::Annotation.tags
|
19
19
|
tag = (annotations.length > 1)
|
20
20
|
|
21
21
|
Rails::SourceAnnotationExtractor.enumerate annotations.join("|"), tag: tag, dirs: directories
|
@@ -38,8 +38,9 @@ module Rails
|
|
38
38
|
if code_or_file == "-"
|
39
39
|
eval($stdin.read, TOPLEVEL_BINDING, "stdin")
|
40
40
|
elsif File.exist?(code_or_file)
|
41
|
-
|
42
|
-
|
41
|
+
expanded_file_path = File.expand_path code_or_file
|
42
|
+
$0 = expanded_file_path
|
43
|
+
Kernel.load expanded_file_path
|
43
44
|
else
|
44
45
|
begin
|
45
46
|
eval(code_or_file, TOPLEVEL_BINDING, __FILE__, __LINE__)
|
@@ -4,7 +4,6 @@ require "fileutils"
|
|
4
4
|
require "action_dispatch"
|
5
5
|
require "rails"
|
6
6
|
require "active_support/core_ext/string/filters"
|
7
|
-
require "active_support/core_ext/symbol/starts_ends_with"
|
8
7
|
require "rails/dev_caching"
|
9
8
|
require "rails/command/environment_argument"
|
10
9
|
|
@@ -263,11 +262,9 @@ module Rails
|
|
263
262
|
Run `bin/rails server --help` for more options.
|
264
263
|
MSG
|
265
264
|
else
|
266
|
-
|
267
|
-
suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
|
268
|
-
|
265
|
+
error = CorrectableError.new("Could not find server '#{server}'.", server, RACK_SERVERS)
|
269
266
|
<<~MSG
|
270
|
-
|
267
|
+
#{error.message}
|
271
268
|
Run `bin/rails server --help` for more options.
|
272
269
|
MSG
|
273
270
|
end
|
data/lib/rails/configuration.rb
CHANGED
@@ -49,48 +49,43 @@ module Rails
|
|
49
49
|
@delete_operations = delete_operations
|
50
50
|
end
|
51
51
|
|
52
|
-
def insert_before(
|
53
|
-
@operations << -> middleware { middleware.insert_before(
|
52
|
+
def insert_before(...)
|
53
|
+
@operations << -> middleware { middleware.insert_before(...) }
|
54
54
|
end
|
55
|
-
ruby2_keywords(:insert_before) if respond_to?(:ruby2_keywords, true)
|
56
55
|
|
57
56
|
alias :insert :insert_before
|
58
57
|
|
59
|
-
def insert_after(
|
60
|
-
@operations << -> middleware { middleware.insert_after(
|
58
|
+
def insert_after(...)
|
59
|
+
@operations << -> middleware { middleware.insert_after(...) }
|
61
60
|
end
|
62
|
-
ruby2_keywords(:insert_after) if respond_to?(:ruby2_keywords, true)
|
63
61
|
|
64
|
-
def swap(
|
65
|
-
@operations << -> middleware { middleware.swap(
|
62
|
+
def swap(...)
|
63
|
+
@operations << -> middleware { middleware.swap(...) }
|
66
64
|
end
|
67
|
-
ruby2_keywords(:swap) if respond_to?(:ruby2_keywords, true)
|
68
65
|
|
69
|
-
def use(
|
70
|
-
@operations << -> middleware { middleware.use(
|
66
|
+
def use(...)
|
67
|
+
@operations << -> middleware { middleware.use(...) }
|
71
68
|
end
|
72
|
-
ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
|
73
69
|
|
74
|
-
def delete(
|
75
|
-
@delete_operations << -> middleware { middleware.delete(
|
70
|
+
def delete(...)
|
71
|
+
@delete_operations << -> middleware { middleware.delete(...) }
|
76
72
|
end
|
77
73
|
|
78
|
-
def move_before(
|
79
|
-
@delete_operations << -> middleware { middleware.move_before(
|
74
|
+
def move_before(...)
|
75
|
+
@delete_operations << -> middleware { middleware.move_before(...) }
|
80
76
|
end
|
81
77
|
|
82
78
|
alias :move :move_before
|
83
79
|
|
84
|
-
def move_after(
|
85
|
-
@delete_operations << -> middleware { middleware.move_after(
|
80
|
+
def move_after(...)
|
81
|
+
@delete_operations << -> middleware { middleware.move_after(...) }
|
86
82
|
end
|
87
83
|
|
88
|
-
def unshift(
|
89
|
-
@operations << -> middleware { middleware.unshift(
|
84
|
+
def unshift(...)
|
85
|
+
@operations << -> middleware { middleware.unshift(...) }
|
90
86
|
end
|
91
|
-
ruby2_keywords(:unshift) if respond_to?(:ruby2_keywords, true)
|
92
87
|
|
93
|
-
def merge_into(other)
|
88
|
+
def merge_into(other) # :nodoc:
|
94
89
|
(@operations + @delete_operations).each do |operation|
|
95
90
|
operation.call(other)
|
96
91
|
end
|
@@ -106,7 +101,7 @@ module Rails
|
|
106
101
|
attr_reader :operations, :delete_operations
|
107
102
|
end
|
108
103
|
|
109
|
-
class Generators
|
104
|
+
class Generators # :nodoc:
|
110
105
|
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging, :api_only
|
111
106
|
attr_reader :hidden_namespaces, :after_generate_callbacks
|
112
107
|
|
@@ -44,7 +44,7 @@ module Rails
|
|
44
44
|
exclude: ["assets", javascript_path]
|
45
45
|
paths.add "app/assets", glob: "*"
|
46
46
|
paths.add "app/controllers", eager_load: true
|
47
|
-
paths.add "app/channels", eager_load: true
|
47
|
+
paths.add "app/channels", eager_load: true
|
48
48
|
paths.add "app/helpers", eager_load: true
|
49
49
|
paths.add "app/models", eager_load: true
|
50
50
|
paths.add "app/mailers", eager_load: true
|
@@ -55,9 +55,9 @@ module Rails
|
|
55
55
|
paths.add "lib/tasks", glob: "**/*.rake"
|
56
56
|
|
57
57
|
paths.add "config"
|
58
|
-
paths.add "config/environments", glob: "#{Rails.env}.rb"
|
58
|
+
paths.add "config/environments", glob: -"#{Rails.env}.rb"
|
59
59
|
paths.add "config/initializers", glob: "**/*.rb"
|
60
|
-
paths.add "config/locales", glob: "
|
60
|
+
paths.add "config/locales", glob: "**/*.{rb,yml}"
|
61
61
|
paths.add "config/routes.rb"
|
62
62
|
paths.add "config/routes", glob: "**/*.rb"
|
63
63
|
|
data/lib/rails/engine.rb
CHANGED
@@ -33,7 +33,7 @@ module Rails
|
|
33
33
|
# Then ensure that this file is loaded at the top of your <tt>config/application.rb</tt>
|
34
34
|
# (or in your +Gemfile+) and it will automatically load models, controllers and helpers
|
35
35
|
# inside +app+, load routes at <tt>config/routes.rb</tt>, load locales at
|
36
|
-
# <tt>config/locales
|
36
|
+
# <tt>config/locales/**/*</tt>, and load tasks at <tt>lib/tasks/**/*</tt>.
|
37
37
|
#
|
38
38
|
# == Configuration
|
39
39
|
#
|
@@ -482,17 +482,8 @@ module Rails
|
|
482
482
|
end
|
483
483
|
|
484
484
|
def eager_load!
|
485
|
-
# Already done by Zeitwerk::Loader.eager_load_all.
|
486
|
-
#
|
487
|
-
return if Rails.autoloaders.zeitwerk_enabled?
|
488
|
-
|
489
|
-
config.eager_load_paths.each do |load_path|
|
490
|
-
# Starts after load_path plus a slash, ends before ".rb".
|
491
|
-
relname_range = (load_path.to_s.length + 1)...-3
|
492
|
-
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
|
493
|
-
require_dependency file[relname_range]
|
494
|
-
end
|
495
|
-
end
|
485
|
+
# Already done by Zeitwerk::Loader.eager_load_all. By now, we leave the
|
486
|
+
# method as a no-op for backwards compatibility.
|
496
487
|
end
|
497
488
|
|
498
489
|
def railties
|
@@ -579,11 +570,6 @@ module Rails
|
|
579
570
|
$LOAD_PATH.uniq!
|
580
571
|
end
|
581
572
|
|
582
|
-
# Set the paths from which Rails will automatically load source files,
|
583
|
-
# and the load_once paths.
|
584
|
-
#
|
585
|
-
# This needs to be an initializer, since it needs to run once
|
586
|
-
# per engine and get the engine as a block parameter.
|
587
573
|
initializer :set_autoload_paths, before: :bootstrap_hook do
|
588
574
|
ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
|
589
575
|
ActiveSupport::Dependencies.autoload_once_paths.unshift(*_all_autoload_once_paths)
|
@@ -665,12 +651,12 @@ module Rails
|
|
665
651
|
end
|
666
652
|
end
|
667
653
|
|
668
|
-
def routes?
|
654
|
+
def routes? # :nodoc:
|
669
655
|
@routes
|
670
656
|
end
|
671
657
|
|
672
658
|
protected
|
673
|
-
def run_tasks_blocks(*)
|
659
|
+
def run_tasks_blocks(*) # :nodoc:
|
674
660
|
super
|
675
661
|
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
|
676
662
|
end
|
@@ -686,7 +672,7 @@ module Rails
|
|
686
672
|
paths["db/migrate"].existent.any?
|
687
673
|
end
|
688
674
|
|
689
|
-
def self.find_root_with_flag(flag, root_path, default = nil)
|
675
|
+
def self.find_root_with_flag(flag, root_path, default = nil) # :nodoc:
|
690
676
|
while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
|
691
677
|
parent = File.dirname(root_path)
|
692
678
|
root_path = parent != root_path && parent
|
@@ -703,17 +689,25 @@ module Rails
|
|
703
689
|
end
|
704
690
|
|
705
691
|
def _all_autoload_once_paths
|
706
|
-
config.autoload_once_paths
|
692
|
+
config.autoload_once_paths.uniq
|
707
693
|
end
|
708
694
|
|
709
695
|
def _all_autoload_paths
|
710
|
-
@_all_autoload_paths ||=
|
696
|
+
@_all_autoload_paths ||= begin
|
697
|
+
autoload_paths = config.autoload_paths
|
698
|
+
autoload_paths += config.eager_load_paths
|
699
|
+
autoload_paths -= config.autoload_once_paths
|
700
|
+
autoload_paths.uniq
|
701
|
+
end
|
711
702
|
end
|
712
703
|
|
713
704
|
def _all_load_paths(add_autoload_paths_to_load_path)
|
714
705
|
@_all_load_paths ||= begin
|
715
|
-
load_paths
|
716
|
-
|
706
|
+
load_paths = config.paths.load_paths
|
707
|
+
if add_autoload_paths_to_load_path
|
708
|
+
load_paths += _all_autoload_paths
|
709
|
+
load_paths += _all_autoload_once_paths
|
710
|
+
end
|
717
711
|
load_paths.uniq
|
718
712
|
end
|
719
713
|
end
|
data/lib/rails/gem_version.rb
CHANGED
@@ -6,7 +6,7 @@ require "thor/actions"
|
|
6
6
|
module Rails
|
7
7
|
module Generators
|
8
8
|
module Actions
|
9
|
-
class CreateMigration < Thor::Actions::CreateFile
|
9
|
+
class CreateMigration < Thor::Actions::CreateFile # :nodoc:
|
10
10
|
def migration_dir
|
11
11
|
File.dirname(@destination)
|
12
12
|
end
|
@@ -20,6 +20,8 @@ module Rails
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def invoke!
|
23
|
+
return super if pretend?
|
24
|
+
|
23
25
|
invoked_file = super
|
24
26
|
File.exist?(@destination) ? invoked_file : relative_existing_migration
|
25
27
|
end
|
@@ -37,10 +39,8 @@ module Rails
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def existing_migration
|
40
|
-
@existing_migration ||=
|
41
|
-
@base.class.migration_exists?(migration_dir, migration_file_name) ||
|
42
|
+
@existing_migration ||= @base.class.migration_exists?(migration_dir, migration_file_name) ||
|
42
43
|
File.exist?(@destination) && @destination
|
43
|
-
end
|
44
44
|
end
|
45
45
|
alias :exists? :existing_migration
|
46
46
|
|
@@ -18,6 +18,7 @@ module Rails
|
|
18
18
|
# gem "technoweenie-restful-authentication", lib: "restful-authentication", source: "http://gems.github.com/"
|
19
19
|
# gem "rails", "3.0", git: "https://github.com/rails/rails"
|
20
20
|
# gem "RedCloth", ">= 4.1.0", "< 4.2.0"
|
21
|
+
# gem "rspec", comment: "Put this comment above the gem declaration"
|
21
22
|
def gem(*args)
|
22
23
|
options = args.extract_options!
|
23
24
|
name, *versions = args
|
@@ -26,6 +27,9 @@ module Rails
|
|
26
27
|
# otherwise use name (version).
|
27
28
|
parts, message = [ quote(name) ], name.dup
|
28
29
|
|
30
|
+
# Output a comment above the gem declaration.
|
31
|
+
comment = options.delete(:comment)
|
32
|
+
|
29
33
|
if versions = versions.any? ? versions : options.delete(:version)
|
30
34
|
_versions = Array(versions)
|
31
35
|
_versions.each do |version|
|
@@ -40,9 +44,17 @@ module Rails
|
|
40
44
|
parts << quote(options) unless options.empty?
|
41
45
|
|
42
46
|
in_root do
|
43
|
-
str =
|
44
|
-
|
45
|
-
|
47
|
+
str = []
|
48
|
+
if comment
|
49
|
+
comment.each_line do |comment_line|
|
50
|
+
str << indentation
|
51
|
+
str << "# #{comment_line}"
|
52
|
+
end
|
53
|
+
str << "\n"
|
54
|
+
end
|
55
|
+
str << indentation
|
56
|
+
str << "gem #{parts.join(", ")}"
|
57
|
+
append_file_with_newline "Gemfile", str.join, verbose: false
|
46
58
|
end
|
47
59
|
end
|
48
60
|
|
@@ -268,14 +280,25 @@ module Rails
|
|
268
280
|
# route "root 'admin#index'", namespace: :admin
|
269
281
|
def route(routing_code, namespace: nil)
|
270
282
|
routing_code = Array(namespace).reverse.reduce(routing_code) do |code, ns|
|
271
|
-
"namespace :#{ns} do\n#{
|
283
|
+
"namespace :#{ns} do\n#{optimize_indentation(code, 2)}end"
|
272
284
|
end
|
273
285
|
|
274
286
|
log :route, routing_code
|
275
|
-
|
287
|
+
|
288
|
+
after_pattern = Array(namespace).each_with_index.reverse_each.reduce(nil) do |pattern, (ns, i)|
|
289
|
+
margin = "\\#{i + 1}[ ]{2}"
|
290
|
+
"(?:(?:^[ ]*\n|^#{margin}.*\n)*?^(#{margin})namespace :#{ns} do\n#{pattern})?"
|
291
|
+
end.then do |pattern|
|
292
|
+
/^([ ]*).+\.routes\.draw do[ ]*\n#{pattern}/
|
293
|
+
end
|
276
294
|
|
277
295
|
in_root do
|
278
|
-
|
296
|
+
if existing = match_file("config/routes.rb", after_pattern)
|
297
|
+
base_indent, *, prev_indent = existing.captures.compact.map(&:length)
|
298
|
+
routing_code = optimize_indentation(routing_code, base_indent + 2).lines.grep_v(/^[ ]{,#{prev_indent}}\S/).join
|
299
|
+
end
|
300
|
+
|
301
|
+
inject_into_file "config/routes.rb", routing_code, after: after_pattern, verbose: false, force: false
|
279
302
|
end
|
280
303
|
end
|
281
304
|
|
@@ -323,8 +346,7 @@ module Rails
|
|
323
346
|
end
|
324
347
|
end
|
325
348
|
|
326
|
-
#
|
327
|
-
# Otherwise fall back to double quotes
|
349
|
+
# Always returns value in double quotes.
|
328
350
|
def quote(value) # :doc:
|
329
351
|
if value.respond_to? :each_pair
|
330
352
|
return value.map do |k, v|
|
@@ -333,11 +355,7 @@ module Rails
|
|
333
355
|
end
|
334
356
|
return value.inspect unless value.is_a? String
|
335
357
|
|
336
|
-
|
337
|
-
value.inspect
|
338
|
-
else
|
339
|
-
"'#{value}'"
|
340
|
-
end
|
358
|
+
"\"#{value.tr("'", '"')}\""
|
341
359
|
end
|
342
360
|
|
343
361
|
# Returns optimized string with indentation
|
@@ -365,6 +383,10 @@ module Rails
|
|
365
383
|
match.end_with?("\n") ? "" : "\n#{str}\n"
|
366
384
|
end
|
367
385
|
end
|
386
|
+
|
387
|
+
def match_file(path, pattern)
|
388
|
+
File.read(path).match(pattern) if File.exist?(path)
|
389
|
+
end
|
368
390
|
end
|
369
391
|
end
|
370
392
|
end
|