David Lazar
David Lazar

Reputation: 11427

Rails Zeitwerk snakecase

When we have a directory under app/ that we want Zeitwerk to work off of, and say that naming happens to be something like

app/stuff/graphql.rb
app/stuff/graphql_error.rb

then Zeitwerk is looking for some module Stuff that has some module or class Graphql. But in my code, I am always writing my modules and classes as GraphQL to match that convention. So Zeitwerk is now throwing Zeitwerk::NameError as it tries to work with the code. I don't want to use Stuff::GraphqlError, I want to use Stuff::GraphQLError. How do I trick Zeitwerk here?

Upvotes: 1

Views: 413

Answers (2)

Xavier Noria
Xavier Noria

Reputation: 2324

In order for app/stuff to act as a namespace, you have to put app itself as an autoload path. This is a bit tricky, please have a look at https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html#having-app-in-the-autoload-paths.

Upvotes: 0

ugliest
ugliest

Reputation: 101

I believe Zeitwerk has inflectors that can be used for this: https://github.com/fxn/zeitwerk#inflection

Upvotes: 3

Related Questions