Skip to content

Commit

Permalink
Update autoloader to push with namespace
Browse files Browse the repository at this point in the history
- This prevents a strange bug wherein Zeitwerk would load the target
  gems files, but raise a Zeitwerk::Name error as it expected the file
  to define the constant, but it didn't
- This was fixed by specifying which namespace the pushed lib directory
  is part of during autoloading
  • Loading branch information
apexatoll committed Sep 22, 2023
1 parent 2a90a83 commit d71fa07
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/kangaru/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run!(argv)
def autoloader
@autoloader ||= Zeitwerk::Loader.new.tap do |loader|
loader.inflector = Zeitwerk::GemInflector.new(root_file)
loader.push_dir(app_dir)
loader.push_dir(app_dir, namespace:)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion sig/zeitwerk/loader.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Zeitwerk

def collapse: (Array[String]) -> void

def push_dir: (String dir) -> void
def push_dir: (String dir, ?namespace: Module) -> void

def setup: -> void
end
Expand Down
6 changes: 5 additions & 1 deletion spec/kangaru/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@

it "configures the loader to load the app dir" do
setup
expect(loader).to have_received(:push_dir).with(application.app_dir).once

expect(loader)
.to have_received(:push_dir)
.with(application.app_dir, namespace:)
.once
end

it "enables the instantiated loader" do
Expand Down

0 comments on commit d71fa07

Please sign in to comment.