Bambinos RSS

New Bamboo

Bamboo Blog

Archive

Nov
25th
Tue
permalink ismasan

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. 

Here’s the gist of it.