Introducing zeitwerk
In the past, I tried to make some changes regarding autoload #2200, #2207, #2209. Unfortunately, #2207 and #2209 had to be reverted.
After reading this article, I thought it would be great to use zeitwerk instead of autoload.
Benefits
- manages the
autoload -
eager_loadproof - no explicit requires except dependencies
Changes
- Applied the file convention structure
- Replaced the MonkeyPatch - Rack::Accept::Header
- eager_load is done when loading
grapeinstead of at compile! -
eager_load_spechas been removed - Removed the
validatorregistration process (were loaded dynamically throughinherited) - Removed the cache for coercers (@collection_coercers)
What's the downside?
What's the downside?
Follow the file structure convention if we can label that has a "downside".
Rebase? I'll take a look.
I'd like to merge this.
1. Update the language around auto/lazy loading/reloading in README. 2. What externally visible contracts are we breaking? Should we be incrementing the version to 3.0?
There's a breaking change with custom validator. Now, they must follow the convention Grape::Validations::Validators::[CustomName] The registration part was done through inheritance. I'll put it back.
There's a breaking change with custom validator. Now, they must follow the convention
Grape::Validations::Validators::[CustomName]The registration part was done through inheritance. I'll put it back.
Sounds good, I'll wait to merge.
@dblock I've found something else related to gem grape-swagger. Versions below 2.0 are grape ~> 1.3 and ruby >= 2.7. Above 2.0, its ruby >= 3.0 and 'grape', '>= 1.7', '< 3.0'.
Next Grape release is 2.1.0 and Grape is still ruby >= 2.7.0. Should they follow each other related to ruby version ?
Next Grape release is
2.1.0andGrapeis stillruby >= 2.7.0. Should they follow each other related torubyversion ?
I don't think they have to. Generally we remove rubies going EOL or if there's "good reason". If you can spell it out in a PR we can do whatever :)
The code looks good here. I think we still need to say something in UGPRADING/README about auto-loading? WDYT? It feels like a scary change to go "quietly" :)
@ericproulx Want to add some words to those files and let's merge?
@ericproulx Want to add some words to those files and let's merge?
Done. I mentionned something about Monkey Patch that might result in a Zeitwerk Error.
Merged, nice work.