ruby-grape / ruby-grape/grape-entity
Exposing a List of Entities
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
So I have an Employee entity that looks something like this.
class Employee::Entity < Grape::Entity
expose :id, :name, :company
end
The Employee has tons of clock ins to the timecard system. The entity for a Clockin is something like:
class Clockin::Entity < Grape::Entity
expose :id, :year, :date, :code, :description
end
Displaying all of the clock ins for an employee is easy enough. How would I go about segregating them by year, though?
My first thought was adding something like this to the Employee entity
expose :clockins do |employee, options|
employee.clockins.group_by { |c| c[:year] }
end
That does get the correct data, but it's not presented correctly.
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 Employee::Entity and Clockin::Entity examples in the issue, then inspect how grouped clockins are rendered by Grape::Entity. Determine the expected serialized representation for clockins grouped by year and verify that the output is presented in that structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100