Commit 10f37a84 by Nikolay Norkin

Dynamic callbacks defining

parent 5058797e
......@@ -47,18 +47,20 @@ module Paranoia
module Callbacks
def self.extended(klazz)
klazz.define_callbacks :restore, :real_destroy
%i(restore real_destroy).each do |callback_name|
klazz.define_callbacks callback_name
klazz.define_singleton_method("before_restore") do |*args, &block|
set_callback(:restore, :before, *args, &block)
klazz.define_singleton_method("before_#{callback_name}") do |*args, &block|
set_callback(callback_name, :before, *args, &block)
end
klazz.define_singleton_method("around_restore") do |*args, &block|
set_callback(:restore, :around, *args, &block)
klazz.define_singleton_method("around_#{callback_name}") do |*args, &block|
set_callback(callback_name, :around, *args, &block)
end
klazz.define_singleton_method("after_restore") do |*args, &block|
set_callback(:restore, :after, *args, &block)
klazz.define_singleton_method("after_#{callback_name}") do |*args, &block|
set_callback(callback_name, :after, *args, &block)
end
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment