-
Notifications
You must be signed in to change notification settings - Fork 152
Added 'only' option that selects which attributes should be returned #114
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
expose :user, using: UserEntity | ||
end | ||
|
||
data = Entity.represent(model, only: 'name,user.name,user.email') |
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.
I really think that only
should take an array or a single symbol, not a comma-delimited string.
I really like this, except for the
It's easy to turn a comma-delimited string above into something like this, and if you accept such a string you should be really validating its syntax, which I feel is outside of the scope of this gem. You also don't need to support a comma-delimited version at all, Rack supports passing arrays in, so you could make a query like |
@dblock thanks for your comment. I agree with you, I was blind in the mindset of an API paying attention about how I needed to pass to grape-entity so I can have this feature. You're right, it makes more sense that some middleware takes care of it instead of the gem. I'm gonna work on those changes. Thanks for your insight! |
@dblock When you have a chance, could you take a look on my modifications? Thanks! |
@@ -2,6 +2,7 @@ | |||
============ | |||
|
|||
* Your contribution here. | |||
* [#114](https://github.com/intridea/grape-entity/pull/114): Added 'only' option that selects which attributes should be returned |
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.
Swap this with the line above.
This looks good. Please fix the build and squash the commits. To fix the build just do a |
5e5d01a
to
e9a2590
Compare
@dblock done. 👍 |
Merged via 6375f15. For next time, Rubocop's workflow is like this:
|
This PR intends to add an option named
only
, when representing an object or collection.The motivation for this is that we use both
grape
andgrape-entity
intending to creating a well-structured and performant API.Some great service APIs, like Facebook and Github ones allow the consumer for the API to choose which fields he wants in this request. Also, this article is a very interesting read.
Based on this, I developed this feature into
grape-entity
, and I would love to check some opinion about this.Thanks. 😃