Speaking as someone who actually did monkeypatch ActiveRecord, I also agree with Esparta’s advice here: don’t. I don’t regret doing it, because I knew what I was getting myself into; but if you look at the sourcecode you will see the lengths I had to go to.
My approach to ActiveRecord actually veers far to the opposite direction: you should treat ActiveRecord as an entirely private API. I make the model constants private and make my own public APIs to query data.
Here’s a quick example of what I mean
class Record < ApplicationRecord
self.table_name = "certificates"
Why go to this trouble? Have you ever looked at the public interface of an ActiveRecord model? The API is huge. Most people give up and just integration-test everything with factories or fixtures. But the downside to that is that your test suite becomes intolerably slow.
I wrote a greenfield API service with this method, and was able to hit 100% test coverage with miniscule amounts of factory tests; the vast majority simply stubs out the interfaces under test. Only the stuff that literally talks to the DB needs to be integration tested this way.
Perhaps it’s a little scorched-earth, but AR is such a complex interface that I feel like it will become the center of gravity if you allow it. A data mapper pattern is better, but if you must use AR this is what I recommend.