I'm having issues with zeitwerk where I can't access another models constant that shares the same name. For example:
in /app/models
I have a worker.rb
file with a constant RETRY_COUNT
class Worker < ApplicationRecord
RETRY_COUNT = 10
end
and in /lib
I have a /critical/worker.rb
file but namespaced under critical
module Critical
class Worker
some_method(::Worker::RETRY_COUNT)
end
end
I'm able to call the worker model class using ::Worker
, but when I call ::RETRY_COUNT
, it results in
NameError: uninitialized constant Worker (call 'Worker.connection' to establish a connection)::RETRY_COUNT
Anyway around this? I could just hardcode the RETRY_COUNT
on the Critical::Worker
class but I'd like to avoid doing that.
Based on your updates, I'm fairly certain you have a circular dependency.
has_many
calls are processed during "ApplicationRecord initialization". During "AR initialization", one of them referencesCritical::Worker.foo
in ahas_many
, which references::Worker
(an AR) forRETRY_COUNT
, which isn't done initializing yet.If you need this value for "AR initialization time", then put it in a file that has no other dependencies.
Then:
Zeitgeist should then be able to figure out it needs to load
Independent
before anything else, like your AR classes.