class
ActiveStorage::VariantWithRecord
- ActiveStorage::VariantWithRecord
- Reference
- Object
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.crConstructors
Instance Method Summary
- #blob : Blob
-
#byte_size : Int64 | Nil
Returns the size of the processed image, or
nilwhen it has not been processed. -
#content_type : String
Returns the content type the variant is served with.
-
#filename : Filename
Returns the filename the variant is served with.
-
#image : Blob | Nil
Returns the blob holding the processed image, or
nilwhen there is none. -
#key : String
Returns the storage key of the processed image.
-
#processed : VariantWithRecord
Processes this variant unless its image is already tracked, and returns itself.
-
#processed? : Bool
Returns
truewhen this variation has been processed and its image is still attached. -
#record : VariantRecord | Nil
Returns the variant record for this variation, or
nilwhen nothing has processed it yet. -
#url(expires_in : Time::Span = ActiveStorage.service_urls_expire_in, disposition : String | Nil = "inline")
Returns a URL serving this variant.
- #variation : Variation
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
Instance Method Detail
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
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.
Returns the storage key of the processed image.
Raises when the variation has not been processed, so guard with #processed?.
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
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.
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.
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.