Module: ActiveStorageBlobExtension

Defined in:
lib/active_storage/service/image_kit_io_service.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_storage/service/image_kit_io_service.rb', line 16

def self.included(base)
  base.class_eval do
    before_update :check_metadata
    before_destroy :remove_imagekit_file
    # ActiveRecord::Blob class first destroy the record data and then calls the service.delete method with key
    # as an argument. But the imagekit.io needs fileId to destroy the file which can be get from the metadata.
    # So first destroy the remote file and then destroy the local blob record.
    def remove_imagekit_file
      service.class.delete_ik_file(self)
    end

    def remote_file_exist?
      service.exist?(self.key)
    end

    def remote_file
      return false unless remote_file_exist?

      service.class.remote_file(self)
    end

    # Needs to reload the record to reflect updated remote meta data.
    def 
      self.reload
    end
  end
end