Nov
25th
Tue
25th
Convention for ActiveRecord extensions
There’s not one but many ways of extending ActiveRecord. Some people do:
ActiveRecord::Base.send :include SomeModule
Which in turns includes or extends other modules.
Others extend first, and include internally. Others class_eval the hell out of everything.
There are a few gotchas to avoid, such as accidentally reloading the same modules (ie. in background tasks), which can cause havoc if your extensions uses method aliasing.
Looking at different approaches, I’ve come up with this draft of a convention.