Class: ActiveStorage::Previewer

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

Overview

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.


16
17
18
# File 'activestorage/lib/active_storage/previewer.rb', line 16

def initialize(blob)
  @blob = blob
end

Instance Attribute Details

#blobObject (readonly)

Returns the value of attribute blob


8
9
10
# File 'activestorage/lib/active_storage/previewer.rb', line 8

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)

12
13
14
# File 'activestorage/lib/active_storage/previewer.rb', line 12

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)

23
24
25
# File 'activestorage/lib/active_storage/previewer.rb', line 23

def preview(**options)
  raise NotImplementedError
end