Class: ActiveStorage::VariantWithRecord

Inherits:
Object
  • Object
show all
Includes:
Blob::Servable
Defined in:
app/models/active_storage/variant_with_record.rb

Overview

Active Storage Variant With Record

Like an ActiveStorage::Variant, but keeps detail about the variant in the database as an ActiveStorage::VariantRecord. This is only used if ActiveStorage.track_variants is enabled.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Blob::Servable

#content_type_for_serving, #forced_disposition_for_serving

Constructor Details

#initialize(blob, variation) ⇒ VariantWithRecord

Returns a new instance of VariantWithRecord.



14
15
16
# File 'app/models/active_storage/variant_with_record.rb', line 14

def initialize(blob, variation)
  @blob, @variation = blob, ActiveStorage::Variation.wrap(variation)
end

Instance Attribute Details

#blobObject (readonly)

Returns the value of attribute blob.



10
11
12
# File 'app/models/active_storage/variant_with_record.rb', line 10

def blob
  @blob
end

#variationObject (readonly)

Returns the value of attribute variation.



10
11
12
# File 'app/models/active_storage/variant_with_record.rb', line 10

def variation
  @variation
end

Instance Method Details

#destroyObject

Destroys record and deletes file from service.



32
33
34
# File 'app/models/active_storage/variant_with_record.rb', line 32

def destroy
  record&.destroy
end

#filenameObject



27
28
29
# File 'app/models/active_storage/variant_with_record.rb', line 27

def filename
  ActiveStorage::Filename.new "#{blob.filename.base}.#{variation.format.downcase}"
end

#imageObject



23
24
25
# File 'app/models/active_storage/variant_with_record.rb', line 23

def image
  record&.image
end

#processedObject



18
19
20
21
# File 'app/models/active_storage/variant_with_record.rb', line 18

def processed
  process unless processed?
  self
end