1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Eager load supports individual files

Also we want to eager load routes before anything else.
This commit is contained in:
Aaron Patterson 2018-09-26 11:09:35 -07:00
parent 338c3c45fa
commit 6060a1d97b
No known key found for this signature in database
GPG key ID: 953170BCB4FFAFC6
2 changed files with 8 additions and 4 deletions

View file

@ -473,9 +473,13 @@ module Rails
# files inside eager_load paths. # files inside eager_load paths.
def eager_load! def eager_load!
config.eager_load_paths.each do |load_path| config.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/ if File.file?(load_path)
Dir.glob("#{load_path}/**/*.rb").sort.each do |file| require_dependency load_path
require_dependency file.sub(matcher, '\1') else
matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
require_dependency file.sub(matcher, '\1')
end
end end
end end
end end

View file

@ -38,6 +38,7 @@ module Rails
@paths ||= begin @paths ||= begin
paths = Rails::Paths::Root.new(@root) paths = Rails::Paths::Root.new(@root)
paths.add "config/routes.rb", eager_load: true
paths.add "app", eager_load: true, glob: "{*,*/concerns}" paths.add "app", eager_load: true, glob: "{*,*/concerns}"
paths.add "app/assets", glob: "*" paths.add "app/assets", glob: "*"
paths.add "app/controllers", eager_load: true paths.add "app/controllers", eager_load: true
@ -55,7 +56,6 @@ module Rails
paths.add "config/environments", glob: "#{Rails.env}.rb" paths.add "config/environments", glob: "#{Rails.env}.rb"
paths.add "config/initializers", glob: "**/*.rb" paths.add "config/initializers", glob: "**/*.rb"
paths.add "config/locales", glob: "*.{rb,yml}" paths.add "config/locales", glob: "*.{rb,yml}"
paths.add "config/routes.rb"
paths.add "db" paths.add "db"
paths.add "db/migrate" paths.add "db/migrate"