destroying.rb revision 214b17ce5309c42f31fa6df96778cc9c85ae927d
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksamodule Repository::Destroying
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa extend ActiveSupport::Concern
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa before_destroy :mark_as_destroying, prepend: true
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa def is_destroying?
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa self.class.instance_variable_get(:@destroying).include?(self.id)
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa end
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa def destroy
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa super
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa rescue StandardError => e
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa unmark_as_destroying
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa raise e.class, "Can't delete repository: It contains an ontology that is imported by another repository."
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa end
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa protected
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa def mark_as_destroying
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa self.class.instance_variable_get(:@destroying) << self.id if self.id
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa end
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa def unmark_as_destroying
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa self.class.instance_variable_get(:@destroying).delete(self.id) if self.id
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa end
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksaend