I’d like to define a default before_save callback for any model that is a MongoMapper model. For example, with ActiveRecord I could just do this in an initializer:
module ActiveRecord
class Base
before_save :strip_attrs
private
def strip_attrs
# do stuff
end
end
end
Is it possible to do something like this with MongoMapper?
Try building an
ActiveSupport::Concernplugin and then plug it into MongoMapper::Document, just like MongoMapper does for its internal plugins.