class ActiveStorage::VariantWithRecord

Overview

A processed variant tracked in active_storage_variant_records.

This is the layout a Rails app writes with config.active_storage.track_variants on, which is the default from load_defaults 6.1. Unlike ActiveStorage::Variant, there is no key to derive: the processed image is a blob of its own, linked through a variant record, so the key is simply that blob's key. The record is found by the variation fingerprint, see Variation#digest. https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant_with_record.rb

Included Modules

Defined in:

active_storage/variant_with_record.cr

Constructors

Instance Method Summary

Instance methods inherited from module ActiveStorage::Blob::Servable

content_type_for_serving : String | Nil content_type_for_serving, forced_disposition_for_serving : String | Nil forced_disposition_for_serving

Constructor Detail

def self.new(blob : Blob, variation : Variation) #

Instance Method Detail

def blob : Blob #

def byte_size : Int64 | Nil #

Returns the size of the processed image, or nil when it has not been processed.

The processed image is a blob of its own, so unlike ActiveStorage::Variant its size is known and a handler can stream it in chunks. https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant_with_record.rb


def content_type : String #

Returns the content type the variant is served with.


def filename : Filename #

Returns the filename the variant is served with.

Rails names the variant blob itself, so the stored filename is used as is, unlike ActiveStorage::Variant which rebuilds it from the original blob.


def image : Blob | Nil #

Returns the blob holding the processed image, or nil when there is none.


def key : String #

Returns the storage key of the processed image.

Raises when the variation has not been processed, so guard with #processed?.


def processed : VariantWithRecord #

Processes this variant unless its image is already tracked, and returns itself.

https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant_with_record.rb


def processed? : Bool #

Returns true when this variation has been processed and its image is still attached.

Rails reads the record alone. The image is read here too, so a record whose image was purged is processed again rather than serving a key nothing is stored under.


def record : VariantRecord | Nil #

Returns the variant record for this variation, or nil when nothing has processed it yet.

A record is stored under the digest its writer computed: Rails' controllers from a decoded URL key, or the app's own passes from the spec as written, where symbol values digest differently. Both candidates are tried, serve path first, so the bridge resolves the same record Rails' redirect controller serves. See Variation#digest_candidates.

A miss is memoized too: it costs one query per candidate, and #processed?, #key, #filename and #content_type all ask again.


def url(expires_in : Time::Span = ActiveStorage.service_urls_expire_in, disposition : String | Nil = "inline") #

Returns a URL serving this variant.

As with ActiveStorage::Variant, the binary serving rules are not applied: the variant was re-encoded by the variant processor, so it is served with its own content type.


def variation : Variation #