module DataMapper::Model::Hook::Methods
Public Instance Methods
after(target_method, method_sym = nil, &block)
click to toggle source
@api public
Calls superclass method
# File lib/dm-core/model/hook.rb, line 25 def after(target_method, method_sym = nil, &block) setup_hook(:after, target_method, method_sym, block) { super } end
before(target_method, method_sym = nil, &block)
click to toggle source
@api public
Calls superclass method
# File lib/dm-core/model/hook.rb, line 20 def before(target_method, method_sym = nil, &block) setup_hook(:before, target_method, method_sym, block) { super } end
hooks()
click to toggle source
@api private
# File lib/dm-core/model/hook.rb, line 30 def hooks @hooks ||= { :save => { :before => [], :after => [] }, :create => { :before => [], :after => [] }, :update => { :before => [], :after => [] }, :destroy => { :before => [], :after => [] }, } end
inherited(model)
click to toggle source
Calls superclass method
# File lib/dm-core/model/hook.rb, line 14 def inherited(model) copy_hooks(model) super end
Private Instance Methods
copy_hooks(model)
click to toggle source
deep copy hooks from the parent model
# File lib/dm-core/model/hook.rb, line 55 def copy_hooks(model) hooks = Hash.new do |hooks, name| hooks[name] = Hash.new do |types, type| if self.hooks[name] types[type] = self.hooks[name][type].map do |command| command.copy(model) end end end end model.instance_variable_set(:@hooks, hooks) end
setup_hook(type, name, method, proc) { || ... }
click to toggle source
# File lib/dm-core/model/hook.rb, line 41 def setup_hook(type, name, method, proc) types = hooks[name] if types && types[type] types[type] << if proc ProcCommand.new(proc) else MethodCommand.new(self, method) end else yield end end