Sha256: 02d91bbbadf8f1f3fde32fc52d5b8e43541e3c4846b54653ac0e4bfbbf1cdf40

Contents?: true

Size: 626 Bytes

Versions: 1

Compression:

Stored size: 626 Bytes

Contents

class ActiveStorage::Attached::One < ActiveStorage::Attached
  delegate_missing_to :attachment

  def attachment
    @attachment ||= ActiveStorage::Attachment.find_by(record_gid: record.to_gid.to_s, name: name)
  end

  def attach(attachable)
    @attachment = ActiveStorage::Attachment.create!(record_gid: record.to_gid.to_s, name: name, blob: create_blob_from(attachable))
  end

  def attached?
    attachment.present?
  end

  def purge
    if attached?
      attachment.purge
      @attachment = nil
    end
  end

  def purge_later
    if attached?
      attachment.purge_later
      @attachment = nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activestorage-0.1 lib/active_storage/attached/one.rb