Class: ActiveStorage::Previewer

Inherits:
Object
  • Object
show all
Defined in:
activestorage/lib/active_storage/previewer.rb

Overview

Active Storage Previewer

This is an abstract base class for previewers, which generate images from blobs. See ActiveStorage::Previewer::MuPDFPreviewer and ActiveStorage::Previewer::VideoPreviewer for examples of concrete subclasses.

Defined Under Namespace

Classes: MuPDFPreviewer, PopplerPDFPreviewer, VideoPreviewer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blob) ⇒ Previewer

Returns a new instance of Previewer.



18
19
20
# File 'activestorage/lib/active_storage/previewer.rb', line 18

def initialize(blob)
  @blob = blob
end

Instance Attribute Details

#blobObject (readonly)

Returns the value of attribute blob.



10
11
12
# File 'activestorage/lib/active_storage/previewer.rb', line 10

def blob
  @blob
end

Class Method Details

.accept?(blob) ⇒ Boolean

Implement this method in a concrete subclass. Have it return true when given a blob from which the previewer can generate an image.

Returns:

  • (Boolean)


14
15
16
# File 'activestorage/lib/active_storage/previewer.rb', line 14

def self.accept?(blob)
  false
end

Instance Method Details

#preview(**options) ⇒ Object

Override this method in a concrete subclass. Have it yield an attachable preview image (i.e. anything accepted by ActiveStorage::Attached::One#attach). Pass the additional options to the underlying blob that is created.

Raises:

  • (NotImplementedError)


25
26
27
# File 'activestorage/lib/active_storage/previewer.rb', line 25

def preview(**options)
  raise NotImplementedError
end