DataMapper hooks differ from those used in Merb controllers. This is because controller filter chains require a decently specific form of logic. DataMapper models, on the other hand, have the benefit of using the more generic Hook class of Extlib.
From the application developer’s perspective, the two methods used to create hooks are before and after. DataMapper registers specific hooks for the methods save, create, update, and destroy. Each of these can be used with before and after.
module DataMapper module Hook def self.included(model) model.class_eval <<-EOS, _ _FILE_ _, _ _LINE_ _ include Extlib::Hook register_instance_hooks :save, :create, :update, :destroy EOS end end DataMapper::Resource.append_inclusions Hook end # module DataMapper