Created
August 29, 2015 17:42
-
-
Save solnic/cc5cc4cff71db708cae9 to your computer and use it in GitHub Desktop.
This file contains 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
# 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