destroying.rb revision d48ad500ac13e587c1d0d9b278ac9d86cde873ef
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksamodule Repository::Destroying
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa extend ActiveSupport::Concern
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa
21a34373b314f1976661a3d9f5eae75af558f09aEugen Kuksa included do
bfdc4a2d94284b4138ed5963cdf2ea32cbf4c3d4Eugen Kuksa @destroying ||= []
21a34373b314f1976661a3d9f5eae75af558f09aEugen Kuksa before_destroy :mark_as_destroying, prepend: true
21a34373b314f1976661a3d9f5eae75af558f09aEugen Kuksa end
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
b14a891a1197d90bc37cc54016eb2c411a558238hardik raise e.class, "Can't delete repository: It contains
b14a891a1197d90bc37cc54016eb2c411a558238hardik #{Settings.OMS.with_indefinite_article} that is imported by another repository."
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa end
214b17ce5309c42f31fa6df96778cc9c85ae927dEugen Kuksa
d48ad500ac13e587c1d0d9b278ac9d86cde873efEugen Kuksa def can_be_deleted?
d48ad500ac13e587c1d0d9b278ac9d86cde873efEugen Kuksa ontologies.map(&:can_be_deleted?).all?
d48ad500ac13e587c1d0d9b278ac9d86cde873efEugen Kuksa end
d48ad500ac13e587c1d0d9b278ac9d86cde873efEugen 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