Class: ActiveStorage::Transformers::Transformer
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | activestorage/lib/active_storage/transformers/transformer.rb |
Overview
A Transformer applies a set of transformations to an image.
The following concrete subclasses are included in Active Storage:
-
ImageProcessingTransformer
: backed by ImageProcessing, a common interface for MiniMagick and ruby-vips
Class Method Summary
- .new(transformations) ⇒ Transformer constructor
Instance Attribute Summary
- #transformations readonly
Instance Method Summary
-
#transform(file, format:)
Applies the transformations to the source image in
file
, producing a target image in the specifiedformat
. -
#process(file, format:)
private
Returns an open Tempfile containing a transformed image in the given
format
.
Constructor Details
.new(transformations) ⇒ Transformer
# File 'activestorage/lib/active_storage/transformers/transformer.rb', line 16
def initialize(transformations) @transformations = transformations end
Instance Attribute Details
#transformations (readonly)
[ GitHub ]# File 'activestorage/lib/active_storage/transformers/transformer.rb', line 14
attr_reader :transformations
Instance Method Details
#process(file, format:) (private)
Returns an open Tempfile containing a transformed image in the given format
. All subclasses implement this method.
# File 'activestorage/lib/active_storage/transformers/transformer.rb', line 36
def process(file, format:) # :doc: raise NotImplementedError end
#transform(file, format:)
Applies the transformations to the source image in file
, producing a target image in the specified format
. Yields an open Tempfile containing the target image. Closes and unlinks the output tempfile after yielding to the given block. Returns the result of the block.
# File 'activestorage/lib/active_storage/transformers/transformer.rb', line 23
def transform(file, format:) output = process(file, format: format) begin yield output ensure output.close! end end