Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control which properties get shown by options #214

Open
greggilbert opened this issue Aug 26, 2017 · 0 comments
Open

Control which properties get shown by options #214

greggilbert opened this issue Aug 26, 2017 · 0 comments

Comments

@greggilbert
Copy link
Contributor

greggilbert commented Aug 26, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant