16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/transactify.rb', line 16
def ctransactify(*cmethods)
interceptor = const_get("#{name.demodulize}Interceptor")
klass = const_get(name)
helper = const_set("Transactify#{SecureRandom.hex}Helper", Module.new)
cmethods.each do |method_name|
interceptor.module_eval do
helper.send :define_singleton_method, :prepended do |base|
define_method(method_name) do |*args, &block|
ActiveRecord::Base.transaction do
super(*args, &block)
end
end
end
(class << klass; self; end).module_eval do
prepend(helper)
end
end
end
end
|