destroying.rb revision 492757fbefce7e6aee4a7515983a44d19a542ccc
module Repository::Destroying
extend ActiveSupport::Concern
included do
@destroying ||= []
before_destroy :mark_as_destroying, prepend: true
end
def is_destroying?
self.class.instance_variable_get(:@destroying).include?(self.id)
end
def destroy
super
rescue StandardError => e
unmark_as_destroying
raise e.class, "Can't delete repository: It contains #{Settings.OMS.with_indefinite_article} that is imported by another repository."
end
protected
def mark_as_destroying
self.class.instance_variable_get(:@destroying) << self.id if self.id
end
def unmark_as_destroying
self.class.instance_variable_get(:@destroying).delete(self.id) if self.id
end
end