Skip to content

Commit 98991a9

Browse files
committed
Merge pull request rails#12695 from mikepack/allow_pathnames
Allow Pathnames to be added to eager load paths
2 parents bd004ec + ec31347 commit 98991a9

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

railties/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Support for Pathnames in eager load paths.
2+
3+
*Mike Pack*
4+
15
* Fixed missing line and shadow on service pages(404, 422, 500).
26

37
*Dmitry Korotkov*

railties/lib/rails/engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def load_generators(app=self)
465465
# files inside eager_load paths.
466466
def eager_load!
467467
config.eager_load_paths.each do |load_path|
468-
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
468+
matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
469469
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
470470
require_dependency file.sub(matcher, '\1')
471471
end

railties/test/application/initializers/load_path_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ module Zoo::ReptileHouse ; end
7171
assert Zoo
7272
end
7373

74+
test "eager loading accepts Pathnames" do
75+
app_file "lib/foo.rb", <<-RUBY
76+
module Foo; end
77+
RUBY
78+
79+
add_to_config <<-RUBY
80+
config.eager_load = true
81+
config.eager_load_paths << Pathname.new("#{app_path}/lib")
82+
RUBY
83+
84+
require "#{app_path}/config/environment"
85+
assert Foo
86+
end
87+
7488
test "load environment with global" do
7589
$initialize_test_set_from_env = nil
7690
app_file "config/environments/development.rb", <<-RUBY

0 commit comments

Comments
 (0)