-
Notifications
You must be signed in to change notification settings - Fork 152
Add option :merge to expose. Allow to merge fields into nested hashes and into the root #204
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
d98042f
to
4a47b95
Compare
@@ -1,7 +1,7 @@ | |||
0.5.1 (Next) | |||
============ | |||
|
|||
* Your contribution here. |
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.
Put this back please.
I like it, just amend the CHANGELOG please, and I'll keep this open for a bit, lets see what others say. |
95af47d
to
d0a1b72
Compare
Very timely for me! I was just poking around for solutions to this. Specifically, the ability to merge into the root hash. The one question I have, is what's the behavior on key collision, and can I control it. One idea is to support specifying a lambda to merge, and have it work like Hash#merge's block params: expose :custom_attrs, merge: -> (k, v1, v2) { v1 } I think this would do the trick -- in the OutputBuilder class: if exposure.for_merge
if exposure.for_merge.respond_to? :call
@output_hash.merge! result, &exposure.for_merge
else
@output_hash.merge! result
end
else
@output_hash[exposure.key] = result
end |
… or into the root. This also closes ruby-grape#138
Hi @uberjay . |
d0a1b72
to
ae279de
Compare
I am going to merge this. See what I did there? Merge ... 👍 |
Add option :merge to expose. Allow to merge fields into nested hashes and into the root
@dblock ok I'll check it a bit later 👍 |
Any update on this? Just spent a lot of time chasing my tail due to this. I recommend pulling 0.5.1 or reverting this until it is resolved. This is a breaking change for more than just testing. It breaks the wrapping of error messages in error! calls when using an entity model because the result returned to the present algorithm is no longer a Hash. |
@wleeper I working on this. Tomorrow I let you know if it's really better to revert that commit 🎱 |
I don't think yanking 0.5.1 now is a good option, there're lots of people using it in production and it doesn't break "everything". Looking forward to a fix. |
Any news? |
@lucaskanashiro Looking forward to your PR! |
This also closes #138
Hi guys. Long time ago I dreamed about merging fields into nested hashes. And that's it. I found it useful and decided to make a PR.
We can do this:
this:
And even this:
It would be awesome if you take a look at this. Thanks!