Skip to content

Instantly share code, notes, and snippets.

Created October 6, 2016 19:22
Show Gist options
  • Save anonymous/1b5f050bc03c72d587dd4e5267cd1684 to your computer and use it in GitHub Desktop.
Save anonymous/1b5f050bc03c72d587dd4e5267cd1684 to your computer and use it in GitHub Desktop.
User = Struct.new(:email)
Post = Struct.new(:user, :text)
class PostRepresenter < Representable::Decorator
include Representable::JSON
property :text
property :user, populator: lambda { |input, options| options[:represented].user = User.new }
end
alice = User.new("[email protected]")
p = Post.new
PostRepresenter.new(p).from_hash({ "text" => "my text"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment