Skip to content

Commit

Permalink
Fix eager loading some namespaces with collapsed directories
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Nov 8, 2022
1 parent 99a61ad commit a7abe7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/zeitwerk/loader/eager_load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def load_file(path)
next unless dir?(abspath)

if collapse?(abspath)
current_dirs << abspath
dirs << abspath
elsif segment == inflector.camelize(basename, abspath)
next_dirs << abspath
end
Expand Down
19 changes: 19 additions & 0 deletions test/lib/zeitwerk/test_eager_load_namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ def loader.actual_eager_load_dir(*)
end
end

test "supports collapsed directories" do
files = [
["a/collapsed/m/x.rb", "M::X = 1"],
["b/y.rb", "Y = 1"],
["b/m/y.rb", "M::Y = 1"]
]
with_files(files) do
loader.push_dir("a")
loader.push_dir("b")
loader.collapse("a/collapsed")
loader.setup
loader.eager_load_namespace(M)

assert required?(files[0])
assert !required?(files[1])
assert required?(files[2])
end
end

test "eader loads everything (nested root directories)" do
files = [
["x.rb", "X = 1"],
Expand Down

0 comments on commit a7abe7f

Please sign in to comment.