ruby-grape / grape-entity

An API focused facade that sits on top of an object model.
MIT License
721 stars 153 forks source link

Responds to the object itself #302

Open yuuu opened 6 years ago

yuuu commented 6 years ago

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?

al commented 6 years ago

If I understand you correctly, I think expose :itself, as: :body would work and is slightly prettier. Does that help?