-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Removes dependency on Hashie::Mash #1279
Conversation
This would break a massive amount of users of Grape, I don't think removing a dependency justifies the amount of pain and suffering that we're going to introduce by this change. Furthermore, nothing says that this change actually improves anything (eg. performance), and that's something that we would want to demonstrate with some basic benchmarks. I would like to be able to tell Grape to make |
While removing a dependency is nice, removing Hashie isn't really about doing that just for the sake of it. If there's similar performance, why use an external library instead of the native Hash? When I was making the change to remove it, we aren't even using any features of Hashie native Hashes cannot do. We just package the data in it and give it back. Why should an API DSL force the use of an external Hash library when Ruby standard Hashes would work the exact same? |
Also, I'm assuming most people using Grape only use Hashie because of it, and there are some issues mixing Hashie with the standard hash: hashie/hashie#341 I end up creating a helper in my Grape projects as a work around |
Ruby standard hash doesn't work the same way. It doesn't expose properties as methods and such. There're probably significant amounts of people relying on the fact that |
Been trying to come up with an idea to ease the transition for people using Hashie but can't seem to come up with something very elegant. Do you have any ideas @dblock? |
Maybe we can add a configuration to transform params with a block? And the default return value would just be a plain Hash?
Idk just spitballing.... |
Maybe just write a middleware someone can use? |
@arempe93 I'm totally with you on this, I hate my code being polluted with Hashie and now we have #dig the case is even stronger. How about you set a params_hash_class somewhere and specify Hashie as default. Then reference that throughout instead of referencing Hashie.new or idiomatic Hash[] use params_hash_class.new? |
Not a fresh article about why is not a good idea depending on it: I spent a few hours debugging an issue migrating from Rails 4.1 to 4.2. You can see the problem in the commit in which they reverted the behaviour for Rails 5. I am behind removing hashie as a dependency. Instead of thinking about what it breaks (which we can handle with semantic versioning and the changelog), think about what it really provides for grape and if that's worth keeping for. |
@vbalazs see above. I am looking for a PR that is green and that gives people a backwards-compatible way forward (even if they have to do a bit of work) |
So I decided to give this another look because of the discussion around it. Basically the hurdle was getting it to work on Rails 3.x because of the missing I tried using |
@@ -261,6 +261,7 @@ def initialize(value) | |||
requires :b | |||
end | |||
end | |||
subject.before_validation { p params } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug code leftover ...
This passes the build, so it's on the right track. I think we could kill the Rails 3 support in this PR if it makes things a lot easier, it's about time, no? :) We still need a path for everyone forward, and I mean a way to get a |
What about using a |
@msroot I am open to it, we already depend on AS. |
@vbalazs what was your solution on rails 4.2 to get around that PR only being available on rails 4.1/rails 5? monkey patching? |
@jcope2013 i was in a situation where i could just do |
@vbalazs thanks for the suggestion |
Closing in favor of #1610. Please add your comments! |
Inspired by #1274
I have always found the use of
Hashie::Mash
as a replacement to hashes in Grape to be cumbersome. In my opinion it's kind of awkward to haveparams
be aHash
anddeclared(params)
be aHashie::Mash
. Especially when trying to pass declared params toActiveRecord
or any gem that expects a trueHash
, not a hash-like object.I think it should be up to the user to decide whether to use Hashie