Class: ActiveStorage::Previewer
- Inherits:
-
Object
- Object
- ActiveStorage::Previewer
- Defined in:
- 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.
Direct Known Subclasses
Defined Under Namespace
Classes: MuPDFPreviewer, PopplerPDFPreviewer, VideoPreviewer
Instance Attribute Summary collapse
-
#blob ⇒ Object
readonly
Returns the value of attribute blob.
Class Method Summary collapse
-
.accept?(blob) ⇒ Boolean
Implement this method in a concrete subclass.
Instance Method Summary collapse
-
#initialize(blob) ⇒ Previewer
constructor
A new instance of Previewer.
-
#preview(**options) ⇒ Object
Override this method in a concrete subclass.
Constructor Details
#initialize(blob) ⇒ Previewer
Returns a new instance of Previewer.
16 17 18 |
# File 'lib/active_storage/previewer.rb', line 16 def initialize(blob) @blob = blob end |
Instance Attribute Details
#blob ⇒ Object (readonly)
Returns the value of attribute blob.
8 9 10 |
# File '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.
12 13 14 |
# File '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.
23 24 25 |
# File 'lib/active_storage/previewer.rb', line 23 def preview(**) raise NotImplementedError end |