1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activemodel/lib/active_model/validations_repair_helper.rb
2009-09-08 10:26:39 -05:00

35 lines
907 B
Ruby

module ActiveModel
module ValidationsRepairHelper
extend ActiveSupport::Concern
module ClassMethods
def repair_validations(*model_classes)
setup do
@_stored_callbacks = {}
model_classes.each do |k|
@_stored_callbacks[k] = k._validate_callbacks.dup
end
end
teardown do
model_classes.each do |k|
k._validate_callbacks = @_stored_callbacks[k]
k.__update_callbacks(:validate)
end
end
end
end
def repair_validations(*model_classes, &block)
@__stored_callbacks = {}
model_classes.each do |k|
@__stored_callbacks[k] = k._validate_callbacks.dup
end
return block.call
ensure
model_classes.each do |k|
k._validate_callbacks = @__stored_callbacks[k]
k.__update_callbacks(:validate)
end
end
end
end