Last active
January 25, 2017 17:04
-
-
Save vovayartsev/b39741cba70609514ee709b05afe32ae 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
# DbAdapter provides access to the underlaying DB layer: | |
# DbAdapter.new.fetch_records(User, name: "Ivan", active: true) # => [ <#User>, <#User>, .... ] | |
# | |
class DbAdapter | |
def fetch_records(klass, conditions) | |
# .... returns an array of records | |
end | |
end | |
# This is our "ActiveRecord" class | |
class User | |
def self.table_name | |
"users" | |
end | |
# TODO: implement "where" method | |
end | |
class Relation | |
# TODO: implement this class | |
end | |
# TODO: the code below should work just like ActiveRecord in Rails | |
relation = User.where(name: "Ivan").where(active: true) | |
relation.to_a # => [ <#User>, <#User>, .... ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment