Sha256: a0c6c25f546eb859d6cdd979e7db7906683f818d8faf95e14f6a6b0697185d5e

Contents?: true

Size: 916 Bytes

Versions: 2

Compression:

Stored size: 916 Bytes

Contents

# frozen_string_literal: true
require 'active_record'

module ActiveModelCachers::Hook
  module OnModelDelete
    module InstanceMethods
      def delete
        self.class.delete(id, self) if persisted?
        @destroyed = true
        freeze
      end
    end

    module ClassMethods
      def delete(id, model = nil)
        ActiveModelCachers::ActiveRecord::Extension.global_callbacks.before_delete1.exec(self, self, id, model)
        ActiveModelCachers::ActiveRecord::Extension.global_callbacks.before_delete2.exec(self, self, id, model)

        result = super(id)

        ActiveModelCachers::ActiveRecord::Extension.global_callbacks.after_delete.exec(self, self, id, model)
        return result
      end
    end
  end
end

ActiveRecord::Base.send(:include, ActiveModelCachers::Hook::OnModelDelete::InstanceMethods)
ActiveRecord::Base.send(:extend, ActiveModelCachers::Hook::OnModelDelete::ClassMethods)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_model_cachers-2.1.7 lib/active_model_cachers/hook/on_model_delete.rb
active_model_cachers-2.1.5 lib/active_model_cachers/hook/on_model_delete.rb