class
ActiveStorage::Variant
- ActiveStorage::Variant
- Reference
- Object
Overview
A processed variant of an image blob, stored under a key derived from the variation.
This is the layout a Rails app writes with config.active_storage.track_variants off: no row of
its own, the processed image simply sits under #key. Rails #download and #destroy are not
ported.
https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant.rb
Included Modules
Defined in:
active_storage/variant.crConstructors
Instance Method Summary
- #blob : Blob
-
#byte_size : Int64 | Nil
Returns the size of the processed file, or
nilwhen it is not known. -
#content_type : String
Returns the content type of this variant, which is the one of its format.
-
#filename : Filename
Returns the filename this variant is served with: the blob filename with the variant extension.
-
#key : String
Returns the combined key of the blob and the variation that identifies this variant in storage.
-
#processed : Variant
Processes this variant unless its image is already stored, and returns itself.
-
#processed? : Bool
Returns
truewhen the processed image is stored under#key. -
#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 file, or nil when it is not known.
Rails keeps no size for a variant stored under a derived key, and asking the service for one
would cost a request per serve. A handler reads the whole file instead of streaming it in
chunks when this is nil.
Returns the content type of this variant, which is the one of its format.
https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant.rb
Returns the filename this variant is served with: the blob filename with the variant extension.
https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant.rb
Returns the combined key of the blob and the variation that identifies this variant in storage.
https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant.rb
Processes this variant unless its image is already stored, and returns itself.
https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant.rb
Returns true when the processed image is stored under #key.
Rails keeps this private. It is public here because ActiveStorage::Blob#variant reads it to
tell a variation an untracked Rails app already wrote from one nothing has written yet.
The answer is memoized because it is a storage call, and serving one variant asks twice: once
in Blob#variant to pick the layout, once in #processed to decide whether to transform.
#process sets it, so a freshly stored variant reports true without another call.
https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant.rb
Returns a URL serving this variant.
Unlike ActiveStorage::Blob#url, Rails does not apply the binary serving rules here: a variant
is re-encoded by the variant processor, so it is served with the content type of its own
format, and the disposition is taken as passed.
https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/variant.rb