Class: ActiveStorage::VariantWithRecord
- Defined in:
- activestorage/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
-
#blob ⇒ Object
readonly
Returns the value of attribute blob.
-
#variation ⇒ Object
readonly
Returns the value of attribute variation.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroys record and deletes file from service.
- #image ⇒ Object
-
#initialize(blob, variation) ⇒ VariantWithRecord
constructor
A new instance of VariantWithRecord.
- #process ⇒ Object
- #processed ⇒ Object
- #processed? ⇒ Boolean
Constructor Details
#initialize(blob, variation) ⇒ VariantWithRecord
Returns a new instance of VariantWithRecord.
11 12 13 |
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 11 def initialize(blob, variation) @blob, @variation = blob, ActiveStorage::Variation.wrap(variation) end |
Instance Attribute Details
#blob ⇒ Object (readonly)
Returns the value of attribute blob
8 9 10 |
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 8 def blob @blob end |
#variation ⇒ Object (readonly)
Returns the value of attribute variation
8 9 10 |
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 8 def variation @variation end |
Instance Method Details
#destroy ⇒ Object
Destroys record and deletes file from service.
33 34 35 |
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 33 def destroy record&.destroy end |
#image ⇒ Object
28 29 30 |
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 28 def image record&.image end |
#process ⇒ Object
20 21 22 |
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 20 def process transform_blob { |image| create_or_find_record(image: image) } unless processed? end |
#processed ⇒ Object
15 16 17 18 |
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 15 def processed process self end |
#processed? ⇒ Boolean
24 25 26 |
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 24 def processed? record.present? end |