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

Grape::Extensions::Hashie::Mash::ParamBuilder can't be set as a default globally in 1 place #1775

Closed
myxoh opened this issue Aug 2, 2018 · 5 comments

Comments

@myxoh
Copy link
Member

myxoh commented Aug 2, 2018

Context: I'm upgrading a massive rails 3.2 API to rails 4. I'm late to the party to realise that Grape changed the default param builder.

Problem: The proposed solution for backwards compatibility:
include Grape::Extensions::Hashie::Mash::ParamBuilder can't be applied globally as far as I could investigate.
The reason for concern is that we have over 200+ API endpoints, and I'd rather not have to modify the 200 files just for the sake of maintaining backwards compatibility.

Is there anyway of setting this builder as the default builder for Grape? Just re-opening Grape::API or building a custom parent class that included Grape::Extensions::Hashie::Mash::ParamBuilder didn't cut it for me.
Using the
def self.inherited(base)
base.include Grape::Extensions::Hashie::Mash::ParamBuilder
end
didn't help either, as in some of our API's the routes hadn't been loaded by then causing some trouble.

Perhaps you've though of an approach, or a new approach must be made?

Thanks in advance for the help

@dblock
Copy link
Member

dblock commented Aug 4, 2018

So technically modifying 200 files works, right? You can introduce a class in the middle and then inherit from it maybe, but you'll still need to modify 200 files. Since it's a bulk search/replace, why is that not an acceptable solution?

Quick and dirty, you can probably monkey-patch Grape::Request, it's called with Grape::Request.new(env, build_params_with: namespace_inheritable(:build_params_with)).

Feel free to PR a better solution to set this globally.

@dblock dblock changed the title Grape::Extensions::Hashie::Mash::ParamBuilder can't be set as a default Grape::Extensions::Hashie::Mash::ParamBuilder can't be set as a default globally in 1 place Aug 4, 2018
@dblock
Copy link
Member

dblock commented Aug 4, 2018

FYI this was introduced in #1610. I renamed this into a feature request to allow one to set the param builder globally, without an include.

@myxoh
Copy link
Member Author

myxoh commented Aug 26, 2018

Thank you @dblock that's awesome!

@myxoh myxoh closed this as completed Aug 26, 2018
@dblock
Copy link
Member

dblock commented Aug 27, 2018

reopening since it's still a valid feature

@myxoh
Copy link
Member Author

myxoh commented Dec 10, 2018

I think this can be closed now. Apologise for the original confusion when creating this issue

@myxoh myxoh closed this as completed Dec 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants