W3cubDocs

/Ruby on Rails 7.0

class ActiveStorage::VariantWithRecord

Parent:
Object

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.

Attributes

blob[R]
variation[R]

Public Class Methods

new(blob, variation) Show source
# File activestorage/app/models/active_storage/variant_with_record.rb, line 9
def initialize(blob, variation)
  @blob, @variation = blob, ActiveStorage::Variation.wrap(variation)
end

Public Instance Methods

image() Show source
# File activestorage/app/models/active_storage/variant_with_record.rb, line 26
def image
  record&.image
end
process() Show source
# File activestorage/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() Show source
# File activestorage/app/models/active_storage/variant_with_record.rb, line 13
def processed
  process
  self
end
processed?() Show source
# File activestorage/app/models/active_storage/variant_with_record.rb, line 22
def processed?
  record.present?
end

© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.