Module: ActiveStorage::AsyncVariants::VariantWithRecordExtension

Defined in:
lib/active_storage/async_variants/variant_with_record_extension.rb

Instance Method Summary collapse

Instance Method Details

#async_stateObject



54
55
56
57
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 54

def async_state
  return nil unless blob.bucket_backed?
  async_record&.state || "pending"
end

#errorObject



50
51
52
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 50

def error
  async_record&.error
end

#failed?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 46

def failed?
  async_record&.state == "failed"
end

#pending?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 42

def pending?
  async_record.nil? || async_record.state == "pending"
end

#processedObject



6
7
8
9
10
11
12
13
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 6

def processed
  if blob.bucket_backed?
    enqueue_processing unless processed? || processing?
    self
  else
    super
  end
end

#processed?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 30

def processed?
  if blob.bucket_backed?
    async_record&.state == "processed"
  else
    super
  end
end

#processing?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 38

def processing?
  async_record&.state == "processing"
end

#urlObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 15

def url(...)
  if blob.bucket_backed? && !processed?
    fallback = active_fallback
    case fallback
    when :original then blob.url(...)
    when :blank then nil
    when Proc then fallback.call(blob)
    when String then fallback
    else super
    end
  else
    super
  end
end