Created
November 5, 2018 02:48
-
-
Save davelooi/959564958d18dce6de9204776b157e0f 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
## somewhere.rb | |
bunch_of_user_entities = UserRepository.new.fetch_all_active_users.map do |user_record| | |
UserEntity.new(user_record.id, user_record.email, user_record.name, user_record.age) | |
end | |
## user_entity.rb | |
class UserEntity < Struct.new(:id, :email, :name, :age) | |
def to_s | |
"#{name}-#{email}" | |
end | |
end | |
## user_repo.rb | |
class UserRepository | |
def fetch_all_active_users | |
Query.active_users | |
end | |
def fetch_all_active_male_users | |
Query.active_users.gender(:male) | |
end | |
def fetch_users_older_than_21 | |
Query.older_than(21) | |
end | |
end | |
## user_query.rb | |
class UserQuery | |
def self.active_users | |
where(status: :active) | |
end | |
def self.gender(g) | |
where(gender: g) | |
end | |
def self.older_than(age) | |
where(dob > age.years.ago) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment