Should Zeitwerk (autoloader) be configurable?

Hey. :wave: I’m seeing strange behavior when teaching Zeitwork how to account for non-standard files/constants. Here’s my setup:

# demo/config/app.rb
module Demo
  class App < Hanami::App
    autoloader.inflector.inflect "subject_url" => "SubjectURL"
    autoloader.logger = method :puts
  end
end
# lib/demo/subject_url.rb
module Demo
  class SubjectURL
  end
end

When jumping into the console or RSpec, I never see this class load and end up with this error instead:

NameError:
  uninitialized constant Demo::SubjectURL

When looking at the Zeitwork logs being printed straight to the terminal, I should see the following:

Zeitwerk@demo: constant Demo::SubjectURL loaded from file demo/lib/demo/subject_url.rb

Instead I get no output because I think by the time I attempt to configure the autoloader, it’s already been setup via Dry System/Hanami so my custom setting is being ignored.

Is this the wrong way to configure Zeitwerk within Hanami? What should I be doing different?

Hey @bkuhlmann, could you please try configuring the Hanami app’s own inflections instead of the Zeitwerk loader’s inflector? The app inflector is provided to Zeitwerk as part of our internal setup of Zeitwek, and that should do the trick.

See this integration spec as a working example of the setup I described above.

Ah, thanks, that worked! Actually, I had tried using Dry Inflector earlier by using inflections.acronym "SubjectURL" but didn’t realize you only need to use "URL" as the acronym because I was thinking in terms of how Zeitwerk is designed to work and had assumed Dry Inflector worked similar so ended up trying work with Zeitwerk directly. Lesson learned. :sweat_smile:

1 Like