Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autoload types and validators #2222

Merged
merged 8 commits into from
Jan 3, 2022

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Jan 1, 2022

Hi,

I've found a solution for the #2218 AND #2221. This PR adds a lazy_find_validator function that loads Grape's validators when needed. That way, we don't have to require all of them since the autoload doesn't trigger the inherited function.

Also, ArrayCoercer and SetCoercer were registering a DryTypeCoercer collection through inheritance. I had to find another way to register the collection. Therefore, I applied the same technique.

Finally, that way, we can remove safely the eager_load! #2216 in the spec_helper. I ran several specs in our stack and I haven't found any issues.

Happy New Year 🍾

@dblock dblock requested a review from dm1try January 1, 2022 15:22
lib/grape/validations.rb Outdated Show resolved Hide resolved
lib/grape/validations.rb Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@dm1try dm1try left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand right that the original PRs #2207 #2209 solve some "consistency problem" where some part of the code is autoloaded and some part is not? without some numbers, it is unclear whether this is a problem at all.

but I like the part with autoloading validators based on :short_name, it echoes to the first part of #2204(though it's not enough for proper integration with Rails for example)

@dblock
Copy link
Member

dblock commented Jan 2, 2022

Do I understand right that the original PRs #2207 #2209 solve some "consistency problem" where some part of the code is autoloaded and some part is not? without some numbers, it is unclear whether this is a problem at all.

i don’t think it’s a problem either way; if my memory serves me correctly there were issues trying to move validators to auto loading and so this was left alone - sounds like we don’t have any issues with going one way or another, I vote to move to auto loading for consistency

@dm1try
Copy link
Member

dm1try commented Jan 2, 2022

I vote to move to auto loading for consistency to auto loading for consistency

that works for me

Copy link
Member

@dm1try dm1try left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, take a look to the comments and rebase the branch(we should not have an intermediate "merge master" commits here). Thanks!

@ericproulx ericproulx force-pushed the fix_autoload_validators_types branch from 38d7e42 to e553a40 Compare January 2, 2022 17:35
CHANGELOG.md Outdated
@@ -6,6 +6,7 @@

#### Fixes

* [#2222](/~https://github.com/ruby-grape/grape/pull/2222): autoload types and validators - [@ericproulx](/~https://github.com/ericproulx).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize Autoload

Copy link
Member

@dm1try dm1try left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes looks good to me.
though, the commits history looks sloppy :) I can help to fix it(later tonight).

@dblock dblock merged commit 37a19e4 into ruby-grape:master Jan 3, 2022
@dblock
Copy link
Member

dblock commented Jan 3, 2022

The changes looks good to me. though, the commits history looks sloppy :) I can help to fix it(later tonight).

I just squash-merged, thanks @ericproulx for the code, and @dm1try for a thorough code review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants