Skip to content

Populate the env route information when calling the automatically added endpoints #2076

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

Conversation

anakinj
Copy link
Contributor

@anakinj anakinj commented Jun 26, 2020

Noticed that calling the route method in a before hook causes an NoMethodError when the hook is invoked for the automatically generated Method Not Allowed endpoints. The reason seems to be that the route information dictionary is not populated in these cases.

These changes will populate the route information before calling the method not allowed endpoint. Also included some minor refactoring for the methods involved in all this.

@anakinj anakinj force-pushed the support-env-route-information-for-allowed-methods-endpoints branch 2 times, most recently from fb70f81 to 7910a98 Compare June 26, 2020 21:18
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

First, kudos for digging through this. This is a far from trivial part of grape and you've done an outstanding job fixing the problem.

I have some stylistic nitpicks/preferences, see below. Care to address those?

route_settings[:path] = route.origin
route_settings = routes_map[route.pattern.to_regexp] ||= {}

route_settings.merge!(options: {},
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit hard to grok IMO. Feels like we should decide whether we want to use merge! or assign fields. Are you trying to optimize because merge can do things in bulk? I would merge everything or assign fields one by one. I also really dislike the side effect of ||= and then taking a route_settings reference on that.

Copy link
Contributor Author

@anakinj anakinj Jun 29, 2020

Choose a reason for hiding this comment

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

Totally agree. I've initially re-wrote it to try to understand what it does. Also RuboCop had some issues with the length of the method when I added that one :options key into the hash.

So now as a second attempt to understand what it does i re-wrote it again :).

@anakinj anakinj force-pushed the support-env-route-information-for-allowed-methods-endpoints branch from 7910a98 to f1d06b1 Compare June 29, 2020 08:49
@anakinj
Copy link
Contributor Author

anakinj commented Jun 29, 2020

The more I look into this the more I feel that the automatically generated endpoints do not belong into the core (was not even aware of this functionality before the before hook started to give us a hard time). Was thinking that maybe it could be possible to extract the features into a separate GEM or something.

@anakinj anakinj force-pushed the support-env-route-information-for-allowed-methods-endpoints branch from f1d06b1 to c532d64 Compare June 29, 2020 09:05
@dblock dblock merged commit 197d5b4 into ruby-grape:master Jun 29, 2020
@dblock
Copy link
Member

dblock commented Jun 29, 2020

I merged the change, thank you.

The more I look into this the more I feel that the automatically generated endpoints do not belong into the core (was not even aware of this functionality before the before hook started to give us a hard time). Was thinking that maybe it could be possible to extract the features into a separate GEM or something.

Generally unless we feel that nobody wants a feature and we feel that it was a mistake, we try not to introduce backwards incompatible changes. Either way open an issue (or a PR) and describe what you think we should do? We can discuss it there?

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.

2 participants