grape icon indicating copy to clipboard operation
grape copied to clipboard

Introducing zeitwerk

Open ericproulx opened this issue 2 years ago • 2 comments

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

  1. manages the autoload
  2. eager_load proof
  3. no explicit requires except dependencies

Changes

  • Applied the file convention structure
  • Replaced the MonkeyPatch - Rack::Accept::Header
  • eager_load is done when loading grape instead of at compile!
  • eager_load_spec has been removed
  • Removed the validator registration process (were loaded dynamically through inherited)
  • Removed the cache for coercers (@collection_coercers)

ericproulx avatar Oct 28 '23 20:10 ericproulx

What's the downside?

dblock avatar Nov 01 '23 21:11 dblock

What's the downside?

Follow the file structure convention if we can label that has a "downside".

ericproulx avatar Nov 13 '23 18:11 ericproulx

Rebase? I'll take a look.

dblock avatar Mar 24 '24 01:03 dblock

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.

ericproulx avatar Apr 01 '24 13:04 ericproulx

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 avatar Apr 01 '24 13:04 dblock

@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 ?

ericproulx avatar Apr 01 '24 14:04 ericproulx

Next Grape release is 2.1.0 and Grape is still ruby >= 2.7.0. Should they follow each other related to ruby version ?

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 :)

dblock avatar Apr 01 '24 22:04 dblock

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" :)

dblock avatar Apr 01 '24 22:04 dblock

@ericproulx Want to add some words to those files and let's merge?

dblock avatar Apr 10 '24 07:04 dblock

@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.

ericproulx avatar Apr 10 '24 20:04 ericproulx

Merged, nice work.

dblock avatar Apr 11 '24 12:04 dblock