Image of Lucian Ghinda writing for notes.ghinda.com
December 17th, 2024

How grape-entity works

Someone asked on Reddit a question like:

> Can anyone provide me an informative article on how grape-entity works?

I don't know or not able to find an article that describes how it works.

Whenever I use it, and I have some doubts, I try to read the source code. 

You can start from here:
https://github.com/ruby-grape/grape-entity/blob/master/lib/grape_entity/entity.rb

But all the files in this folder https://github.com/ruby-grape/grape-entity/tree/master/lib/grape_entity are relatively easy to read.

In case you feel like having questions like "How did the entity got that value or what is the source of that value" I would recommend looking into the delegators https://github.com/ruby-grape/grape-entity/tree/master/lib/grape_entity/delegator