Sha256: 29ad2177803c1f837a304f7d429ad1c8078199f4275d33589980e1819b18b648

Contents?: true

Size: 618 Bytes

Versions: 1

Compression:

Stored size: 618 Bytes

Contents

require "active_storage/blob"
require "global_id"
require "active_support/core_ext/module/delegation"

# Schema: id, record_gid, blob_id, created_at
class ActiveStorage::Attachment < ActiveRecord::Base
  self.table_name = "active_storage_attachments"

  belongs_to :blob, class_name: "ActiveStorage::Blob"

  delegate_missing_to :blob

  def record
    @record ||= GlobalID::Locator.locate(record_gid)
  end

  def record=(record)
    @record = record
    self.record_gid = record&.to_gid
  end

  def purge
    blob.purge
    destroy
  end

  def purge_later
    ActiveStorage::PurgeJob.perform_later(self)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activestorage-0.1 lib/active_storage/attachment.rb