ActiveRecord is a gem that provides abstractions for representing business objects, business logic, database queries and persistence. It allows the programmer to quickly build the model in the MVC architecture, the accompanying table in the database and the mapping of objects to the database.
Rebuilding ActiveRecord consisted of building the base class, database connection adapters and query generation.
The general pattern in most of the core gems in Rails consist of having a base class for your gem usually base.rb and different modules for each features of the gem.
Another pattern used in rails is the adapter pattern. The adapter, in this case, allows the programmer to safely switch databases and makes sure the common methods can be used safely. For example in ActiveRecord the database connection uses an adapter pattern.
The simplified class structure looks something like …