Skip to content

Instantly share code, notes, and snippets.

@solnic
Created August 29, 2015 17:42
Show Gist options
  • Save solnic/cc5cc4cff71db708cae9 to your computer and use it in GitHub Desktop.
Save solnic/cc5cc4cff71db708cae9 to your computer and use it in GitHub Desktop.
# WHAT'S POSSIBLE ALREADY
class User
include Virtus.model
attribute :id
attribute :name
attribute :email
end
class UserMapper
relation :users
register_as :entity
model User
end
class UserRepo < ROM::Repository::Base
def [](id)
select(:id, :name, :email).where(id: id).as(:entity).one!
end
end
user_repo[1] # returns entity instance
# WHAT I WOULD PREFER TO HAVE INSTEAD
class UserRepo < ROM::Repository::Base
base_model User
def [](id)
select(:id, :name, :email).where(id: id).one!
end
end
user_repo[1] # returns entity instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment