1

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?

David Lazar
  • 10,865
  • 3
  • 25
  • 38

2 Answers2

3

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

ugliest
  • 101
  • 6
0

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.

Xavier Noria
  • 1,640
  • 1
  • 8
  • 10
  • This was not a problem of namespace. It was a problem of inflections! – David Lazar Feb 17 '22 at 22:16
  • With default configuration, if you have `app/stuff`, Zeitwerk **does not** expect a namespace `Stuff`, because `app/stuff` is considered a root directory. – Xavier Noria Feb 17 '22 at 22:19
  • Regardless of that, it was blowing chunks on Graphql when I provided GraphQL. Noted though about the fact I can not use stuff in my code. You are saying my module in /app/stuff/tiger.rb could be module Tiger and it would work as well as module Stuff module Tiger... – David Lazar Feb 18 '22 at 00:52
  • Exactly, the same way `app/models/user.rb` defines `User` rather than `Models::User`. – Xavier Noria Feb 18 '22 at 07:12
  • My problem though, was the Zeitwork Name Error, in even finding the class. So it was a case of /app/models/user,rb and having a fit because of a mistake in user.rb. So I had to attack this from the inflections point. – David Lazar Feb 18 '22 at 13:44