Class: ActiveStorage::VariantWithRecord
- Inherits:
-
Object
- Object
- ActiveStorage::VariantWithRecord
- Defined in:
- app/models/active_storage/variant_with_record.rb
Overview
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
- #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.
9 10 11 |
# File 'app/models/active_storage/variant_with_record.rb', line 9 def initialize(blob, variation) @blob, @variation = blob, ActiveStorage::Variation.wrap(variation) end |
Instance Attribute Details
#blob ⇒ Object (readonly)
Returns the value of attribute blob.
6 7 8 |
# File 'app/models/active_storage/variant_with_record.rb', line 6 def blob @blob end |
#variation ⇒ Object (readonly)
Returns the value of attribute variation.
6 7 8 |
# File 'app/models/active_storage/variant_with_record.rb', line 6 def variation @variation end |
Instance Method Details
#image ⇒ Object
26 27 28 |
# File 'app/models/active_storage/variant_with_record.rb', line 26 def image record&.image end |
#process ⇒ Object
18 19 20 |
# File 'app/models/active_storage/variant_with_record.rb', line 18 def process transform_blob { |image| create_or_find_record(image: image) } unless processed? end |
#processed ⇒ Object
13 14 15 16 |
# File 'app/models/active_storage/variant_with_record.rb', line 13 def processed process self end |
#processed? ⇒ Boolean
22 23 24 |
# File 'app/models/active_storage/variant_with_record.rb', line 22 def processed? record.present? end |