r/rails • u/Tristan_Kruse • 15d ago
Open source Autoloading can remove a require without removing the architectural dependency
I created and maintain ArchUnitRuby. Writing assisted by AI.
One thing I wanted to avoid in an architecture test was confusing “no explicit require” with
“no dependency.” These are different spellings of a relationship:
require_relative '../retrieval/store'
Retrieval::Store.new
In an autoloaded application, the second spelling is ordinary Ruby. If your team has decided
that a controller or API component shouldn't know about that implementation, an import-only
rule isn't the complete policy you meant to write.
ArchUnitRuby 1.0 can combine file-load edges and known project constant references through
`dependency_analysis: :imports_and_constants`. That mode is opt-in. The resulting graph can
be checked from the normal Ruby test suite.
This isn't a claim to understand every Rails association, callback, reflection path or
metaprogrammed reference. Packwerk's package workflow and ArchSpec's component/convention
rules also serve useful needs; this approach is about a test-native graph policy.
For a Rails boundary you actually maintain, would file-load edges and constant references
express enough of the policy, or is the important coupling somewhere else?
2
u/CaptainKabob 15d ago
What's the problem you're trying to solve?