Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Created September 1, 2017 14:09
Show Gist options
  • Save flash-gordon/c64a7ae527355639da90681c9241c52c to your computer and use it in GitHub Desktop.
Save flash-gordon/c64a7ae527355639da90681c9241c52c to your computer and use it in GitHub Desktop.
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', ...]
@stergiom
Copy link

stergiom commented Sep 1, 2017

😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment