Skip to content

Instantly share code, notes, and snippets.

@vovayartsev
Last active January 25, 2017 17:04
Show Gist options
  • Save vovayartsev/b39741cba70609514ee709b05afe32ae to your computer and use it in GitHub Desktop.
Save vovayartsev/b39741cba70609514ee709b05afe32ae to your computer and use it in GitHub Desktop.
# 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