Lets say I have a User
model and I am exposing User
object via Grape::Entity
. So in here I want to define a dynamic key which name and its value will be based on other keys(id
, name
, email
) value.
module API
module Entities
class User < Grape::Entity
expose :id
expose :name
expose :email
expose :dynamic_key # dynamic key name will be generated based on other keys(`id`, `name`, `email`) value
private
def dynamic_key
#dynamic key value here based on other keys(`id`, `name`) value
end
end
end
end
How could I do it? Thanks in advance!