Skip to content

Instantly share code, notes, and snippets.

@PavelPenkov
Forked from anonymous/repr.rb
Created October 6, 2016 19:22
Show Gist options
  • Save PavelPenkov/f8c4fa6b089ad61f79ec35b844a89396 to your computer and use it in GitHub Desktop.
Save PavelPenkov/f8c4fa6b089ad61f79ec35b844a89396 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
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