When using Grape Entity, sometimes we want to expose a few fields from an inner/related object. We can simply do this by:
expose(:bar) { |entity| entity.foo.bar }
However if many fields needs this treatment, this can get very repetitive. Is there a way to define delegation / forward so a bunch of expose
all are associated with another object?
create a separate entity for
foo
class, let's call itAPI::Entities::Foo
. then you canyou have to follow REST guidelines to serialize like this. you are dealing with resources. don't break it to flat, cumbersome data structures.