Module: ActiveStorage::AsyncVariants::VariantWithRecordExtension
- Defined in:
- lib/active_storage/async_variants/variant_with_record_extension.rb
Instance Method Summary collapse
- #async_state ⇒ Object
- #enqueue! ⇒ Object
- #error ⇒ Object
- #failed? ⇒ Boolean
- #pending? ⇒ Boolean
-
#processed ⇒ Object
Block vanilla ActiveStorage’s synchronous transform on bucket-backed services; rely on the auto-enqueue (AttachmentExtension) path – and the public #enqueue! – to dispatch ProcessJob.
- #processed? ⇒ Boolean
- #processing? ⇒ Boolean
- #url ⇒ Object
Instance Method Details
#async_state ⇒ Object
68 69 70 71 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 68 def async_state return nil unless blob.bucket_backed? async_record&.state || "pending" end |
#enqueue! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 13 def enqueue! if result = find_named_async_variant , variant_name, _ = result blob.variant_records.create!( variation_digest: variation.digest, state: "pending", ) ActiveStorage::AsyncVariants::ProcessJob.perform_later( .record, .name, variant_name.to_s, ) end rescue ActiveRecord::RecordNotUnique # another caller (or a leftover record) wins; their job handles it end |
#error ⇒ Object
64 65 66 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 64 def error async_record&.error end |
#failed? ⇒ Boolean
60 61 62 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 60 def failed? async_record&.state == "failed" end |
#pending? ⇒ Boolean
56 57 58 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 56 def pending? async_record.nil? || async_record.state == "pending" end |
#processed ⇒ Object
Block vanilla ActiveStorage’s synchronous transform on bucket-backed services; rely on the auto-enqueue (AttachmentExtension) path – and the public #enqueue! – to dispatch ProcessJob.
9 10 11 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 9 def processed blob.bucket_backed? ? self : super end |
#processed? ⇒ Boolean
44 45 46 47 48 49 50 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 44 def processed? if blob.bucket_backed? async_record&.state == "processed" else super end end |
#processing? ⇒ Boolean
52 53 54 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 52 def processing? async_record&.state == "processing" end |
#url ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 29 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 |