Created
October 6, 2016 19:22
-
-
Save anonymous/1b5f050bc03c72d587dd4e5267cd1684 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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