Module: ActiveStorage::HotCell::Client::Previewers::Previewing

Included in:
ActiveStorage::HotCell::Client::Previewers::Pdf::Mutool, ActiveStorage::HotCell::Client::Previewers::Pdf::Poppler, Video::Ffmpeg
Defined in:
lib/active_storage/hot_cell/client/previewers/previewing.rb

Overview

The preview flow every previewer here shares. A previewer names the client that renders for it and differs in nothing else.

accept? must not probe for a binary, and that is the reason these previewers exist as much as the sandboxing is. MuPDFPreviewer.accept? calls mutool_exists? and VideoPreviewer.accept? calls ffmpeg_exists?, both shelling out with system from inside a web request. The moment those binaries leave the application image — which is the point of moving the work into a cell — both answer false, previewable? goes false with them, and previews stop existing. No exception, no alert, nothing in a log.

The sequencing matters as much as the override: these ship and are verified before the binary leaves the application image, because the window between those two events fails silently.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(previewer) ⇒ Object



26
27
28
# File 'lib/active_storage/hot_cell/client/previewers/previewing.rb', line 26

def self.included(previewer)
  previewer.class_attribute :client, instance_accessor: false
end

Instance Method Details

#preview(**options) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/active_storage/hot_cell/client/previewers/previewing.rb', line 30

def preview(**options)
  download_blob_to_tempfile do |input|
    render_through(input) do |attachable|
      yield(**attachable, **options)
    end
  end
end