You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe there's a way to do this, but if there is, I'm hitting a wall.
Suppose you had this:
class ArticleRepresenter < Roar::Decorator
include Roar::JSON
property :author, exec_context: :decorator, decorator: UserRepresenter
property :last_editor, exec_context: :decorator, decorator: UserRepresenter
def author
represented.author
end
end
class ArticlesRepresenter < Roar::Decorator
include Roar::JSON::Collection
items extend: ArticleRepresenter
end
Now say this is for an API and you only want to render certain fields depending on user permissions. So when rendering the collection of articles, or a single article, you show author all the time, but only last_editor if the user is an editor.
Seems like one way to do this would be pass in some kind of set of options and check them in the decorator methods. I think this can be accomplished on the single representer by passing in the options with initialize, but how would you do this at the collection level and have it pass it down to each single representer?
The text was updated successfully, but these errors were encountered:
Maybe there's a way to do this, but if there is, I'm hitting a wall.
Suppose you had this:
Now say this is for an API and you only want to render certain fields depending on user permissions. So when rendering the collection of articles, or a single article, you show
author
all the time, but onlylast_editor
if the user is an editor.Seems like one way to do this would be pass in some kind of set of options and check them in the decorator methods. I think this can be accomplished on the single representer by passing in the options with
initialize
, but how would you do this at the collection level and have it pass it down to each single representer?The text was updated successfully, but these errors were encountered: