ruby-grape / ruby-grape/grape-entity

Responds to the object itself

Open
#302 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
729
Forks
154
PR merge metrics
No merged PRs in 30d

Description

I want to respond to the specified object itself.

If you program as follows, you will get an error with no body method.

class BodyEntity < Grape::ENtity
  expose :body
end

get do
  present 'success', with: Entities::BodyEntity
end

As a workaround, we currently program as follows.

class BodyEntity < Grape::ENtity
  expose :body do |body|
     body
  end
end

get do
  present 'success', with: Entities::BodyEntity
end

Is not there a better way?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the shown Grape::Entity class with expose :body and the present call, then compare it with the workaround that returns body explicitly. The work is done when the specified object itself can be presented without requiring that workaround; the issue does not name a file or test to update.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.