Class: ActiveStorage::VariantWithRecord

Inherits:
Object
  • Object
show all
Defined in:
activestorage/app/models/active_storage/variant_with_record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blob, variation) ⇒ VariantWithRecord

Returns a new instance of VariantWithRecord.


6
7
8
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 6

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

Instance Attribute Details

#blobObject (readonly)

Returns the value of attribute blob


4
5
6
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 4

def blob
  @blob
end

#variationObject (readonly)

Returns the value of attribute variation


4
5
6
# File 'activestorage/app/models/active_storage/variant_with_record.rb', line 4

def variation
  @variation
end

Instance Method Details

#imageObject


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

def image
  record&.image
end

#processObject


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

def process
  transform_blob { |image| create_or_find_record(image: image) } unless processed?
end

#processedObject


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

def processed
  process
  self
end

#processed?Boolean

Returns:

  • (Boolean)

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

def processed?
  record.present?
end

#url(**options) ⇒ Object Also known as: service_url


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

def url(**options)
  image&.url(**options)
end