Zeitwerk nested module class gives undefined constant error

87 Views Asked by At

I have the class inside lib/snowflake/connection.rb folder.

inside connection.rb file is the following structure

module SnowFlake
   class Connection

   end
end

Zeitwerk:check is throwing me following error.

expected file lib/snow_flake/connection.rb to define constant Connection

1

There are 1 best solutions below

0
Xavier Noria On BEST ANSWER

OK, I am going to optimistically write an answer.

Assuming the error has been copied verbatim, I suspect your application has lib/snow_flake in the autoload paths. Why? Because otherwise the error would look like (small edits)

expected file lib/snow_flake/connection.rb to define SnowFlake::Connection

That is, the SnowFlake namespace would be included in the missing constant name reported in the error message.

Nested root directories represent the top-level namespace. If lib/snow_flake is added to the autoload paths, then lib/snow_flake/connection.rb is expected to define the top-level constant Connection, not SnowFlake::Connection.

You can inspect the autoload paths by running

% bin/rails runner 'pp ActiveSupport::Dependencies.autoload_paths'

If my hypothesis is confirmed, please just remove lib/snow_flake from the autoload paths. It is probably being added by hand somewhere in config/application.rb.