Module: ActiveStorage::AsyncVariants

Defined in:
lib/active_storage/async_variants.rb,
lib/active_storage/async_variants/helper.rb,
lib/active_storage/async_variants/version.rb,
lib/active_storage/async_variants/registry.rb,
lib/active_storage/async_variants/process_job.rb,
lib/active_storage/async_variants/transformer.rb,
lib/active_storage/async_variants/blob_extension.rb,
lib/active_storage/async_variants/preview_extension.rb,
lib/active_storage/async_variants/variation_extension.rb,
lib/active_storage/async_variants/attachment_extension.rb,
lib/active_storage/async_variants/reflection_extension.rb,
lib/active_storage/async_variants/heartbeat_watchdog_job.rb,
lib/active_storage/async_variants/variant_record_extension.rb,
lib/active_storage/async_variants/asset_tag_helper_extension.rb,
app/controllers/active_storage/async_variants/states_controller.rb,
lib/active_storage/async_variants/variant_with_record_extension.rb,
app/controllers/active_storage/async_variants/callbacks_controller.rb

Defined Under Namespace

Modules: AssetTagHelperExtension, AttachmentExtension, BlobExtension, Helper, PreviewExtension, ReflectionExtension, VariantRecordExtension, VariantWithRecordExtension, VariationExtension Classes: CallbacksController, Engine, HeartbeatWatchdogJob, ProcessJob, Registry, StatesController, Transformer

Constant Summary collapse

PASS_THROUGH_HTML_OPTIONS =

HTML attributes round-tripped through the state-endpoint URL so the eventual processed-state render can apply them to the inner <img>/<video>.

%i[alt width height controls autoplay preload].freeze
Assets =
IsolateAssets.register(namespace: self, engine: Engine, route_name: :async_variant_asset)
VERSION =
"0.6.0"

Class Method Summary collapse

Class Method Details

.callback_token_for(variant_record) ⇒ Object



110
111
112
# File 'lib/active_storage/async_variants.rb', line 110

def self.callback_token_for(variant_record)
  ActiveStorage.verifier.generate(variant_record.id, purpose: :async_variant_callback)
end

.callback_url_for(variant_record) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/active_storage/async_variants.rb', line 114

def self.callback_url_for(variant_record)
  url_options = ActiveStorage::Current.url_options || Rails.application.default_url_options
  token = callback_token_for(variant_record)
  Rails.application.routes.url_helpers.active_storage_async_variant_callback_url(
    token: token,
    **url_options,
  )
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



53
54
55
# File 'lib/active_storage/async_variants.rb', line 53

def self.configure
  yield self
end

.prepend_model_extensions!Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/active_storage/async_variants.rb', line 83

def self.prepend_model_extensions!
  require "active_storage/reflection"
  ActiveStorage::Reflection::HasAttachedReflection.prepend(
    ActiveStorage::AsyncVariants::ReflectionExtension
  )
  ActiveStorage::Blob.prepend(
    ActiveStorage::AsyncVariants::BlobExtension
  )
  ActiveStorage::Variation.prepend(
    ActiveStorage::AsyncVariants::VariationExtension
  )
  ActiveStorage::VariantWithRecord.prepend(
    ActiveStorage::AsyncVariants::VariantWithRecordExtension
  )
  ActiveStorage::VariantRecord.include(
    ActiveStorage::AsyncVariants::VariantRecordExtension
  )
  ActiveStorage::Attachment.prepend(
    ActiveStorage::AsyncVariants::AttachmentExtension
  )
  ActiveStorage::Preview.prepend(
    ActiveStorage::AsyncVariants::PreviewExtension
  )
end

.retry_visible?(view) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/active_storage/async_variants.rb', line 47

def self.retry_visible?(view)
  !!view.instance_exec(&retry_visible_proc)
rescue StandardError
  false
end

.retry_visible_if(&block) ⇒ Object

Gates the failed-state retry affordance; the block runs in the view context.



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

def self.retry_visible_if(&block)
  self.retry_visible_proc = block
end