Sha256: afe1e56d0128c444f0f46322b27cabe152ec9b784d7d05ee6a38a40e9e4f6b88

Contents?: true

Size: 945 Bytes

Versions: 2

Compression:

Stored size: 945 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.8 lib/active_model_cachers/hook/on_model_delete.rb
active_model_cachers-2.1.6 lib/active_model_cachers/hook/on_model_delete.rb