ruby-grape / ruby-grape/grape-entity
Always expose with the default entity
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
I'm using grape and grape-entity in a Rails 4.2.1 project, and I'm running into a weird error with presenting using the right model.
According to the documentation, organizing my entities within each model results in this:
Grape will automatically detect the Entity class and use it to present your models.
In addition, the documentation also says:
By default every object of a collection is wrapped into an instance of your Entity class.
Here's the code I have now.
class User < ActiveRecord::Base
class Entity < Grape::Entity
expose :id, :name
expose :addresses
end
end
class Address < ActiveRecord::Base
class Entity < Grape::Entity
expose :id, :street1
end
end
If I don't do expose :addresses, with: Address:Entity, it doesn't work, and still exposes all the fields of the address. Any reason it's not automatically detecting the correct entity?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the entity-organization documentation and the nested User::Entity and Address::Entity example in the issue. Reproduce the collection presentation with and without expose :addresses, with: Address::Entity, then trace how the default entity is selected. Done means the behavior is explained and the nested address uses the intended entity, with a regression test if the repository has coverage for this path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100