Created
September 1, 2017 14:09
-
-
Save flash-gordon/c64a7ae527355639da90681c9241c52c 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
module Entities | |
class User < ROM::Struct | |
def name | |
[first_name, last_name].join(' ') | |
end | |
end | |
end | |
class Users < ROM::Relation[:sql] | |
schema do | |
attribute :id, Types::Serial, | |
attribute :first_name, Types::String | |
attribute :last_name, Types::String | |
end | |
end | |
class UserRepo < ROM::Repository[:users] | |
struct_namespace Entities | |
end | |
UserRepo.new(container).users.to_a # => <# Entites::User ... > | |
UserRepo.new(container).users.to_a.map(&:name) # => ['John Doe', ...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
😎