class ActiveStorage::Attachment

Defined in:

active_storage/attachment.cr

Constant Summary

FIELDS_ = {"id" => {type: "big_int", kwargs: {primary_key: true, auto: true}}, "name" => {type: "string", kwargs: {max_size: 255}}, "record_type" => {type: "string", kwargs: {max_size: 255}}, "record_id" => {type: "big_int", kwargs: ::NamedTuple.new}, "blob" => {type: "many_to_one", kwargs: {to: ActiveStorage::Blob}}, "created_at" => {type: "date_time", kwargs: {auto_now_add: true}}} of Nil => Nil

Class Method Summary

Instance Method Summary

Class Method Detail

def self.attach(record_type : String, record_id : Int64, name : String, io : IO, filename : String, content_type : String | Nil = nil, service : String = "local") : ActiveStorage::Attachment #

Stores io as a new blob and links it to (record_type, record_id, name).


def self.exists?(record_type : String, record_id : Int64, name : String) #

def self.purge(record_type : String, record_id : Int64, name : String) : Int32 #

Removes every attachment matching (record_type, record_id, name) and purges the blobs they held. Returns how many were removed.


def self.purge(id : Int64) : Bool #

Removes the attachment with the given id and purges its blob. Returns false when no such attachment exists.


def self.purge(attachment : ActiveStorage::Attachment) : Nil #

Removes the given attachment and purges its blob.


Instance Method Detail

def blob : ActiveStorage::Blob | Nil #

def blob! : ActiveStorage::Blob #

def blob=(related_object : ActiveStorage::Blob | Nil) #

def blob? #

def blob_id : Marten::DB::Field::ReferenceDBTypes | Nil #

def blob_id! #

def blob_id=(related_id : Marten::DB::Field::ReferenceDBTypes | Nil) #

def blob_id? #

def created_at : Time | Nil | Nil #

def created_at! #

def created_at=(created_at : Time | Nil | Nil) #

def created_at? #

def id : Int32 | Int64 | Nil | Nil #

def id! #

def id=(id : Int32 | Int64 | Nil | Nil) #

def id? #

def name : String | Nil | Nil #

def name! #

def name=(name : String | Nil | Nil) #

def name? #

def purge #

Synchronously deletes this attachment and purges the blob it holds.

The attachment row goes first, because ActiveStorage::Blob#purge refuses a blob something is still attached to. A blob another record also holds survives, and so does its row.


def purge_later #

Rails enqueues a background job here; this bridge has no job queue, so the purge runs synchronously, the same as #purge.


def record_id : Int32 | Int64 | Nil | Nil #

def record_id! #

def record_id=(record_id : Int32 | Int64 | Nil | Nil) #

def record_id? #

def record_type : String | Nil | Nil #

def record_type! #

def record_type=(record_type : String | Nil | Nil) #

def record_type? #

def redirect_url #

def representation_url(variation : String) #