Sha256: 9ed9bb5c550b98eb114ad496af55802d31112108011b0549740d04af776f94e7

Contents?: true

Size: 1.23 KB

Versions: 37

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module ActiveStorage
  module Transformers
    # A Transformer applies a set of transformations to an image.
    #
    # The following concrete subclasses are included in Active Storage:
    #
    # * ActiveStorage::Transformers::ImageProcessingTransformer:
    #   backed by ImageProcessing, a common interface for MiniMagick and ruby-vips
    class Transformer
      attr_reader :transformations

      def initialize(transformations)
        @transformations = transformations
      end

      # 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.
      def transform(file, format:)
        output = process(file, format: format)

        begin
          yield output
        ensure
          output.close!
        end
      end

      private
        # Returns an open Tempfile containing a transformed image in the given +format+.
        # All subclasses implement this method.
        def process(file, format:) # :doc:
          raise NotImplementedError
        end
    end
  end
end

Version data entries

37 entries across 35 versions & 4 rubygems

Version Path
activestorage-7.0.8.6 lib/active_storage/transformers/transformer.rb
activestorage-7.0.8.5 lib/active_storage/transformers/transformer.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activestorage-7.0.8.4/lib/active_storage/transformers/transformer.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activestorage-7.0.5.1/lib/active_storage/transformers/transformer.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activestorage-7.0.5.1/lib/active_storage/transformers/transformer.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activestorage-7.0.5.1/lib/active_storage/transformers/transformer.rb
activestorage-7.0.8.4 lib/active_storage/transformers/transformer.rb
activestorage-7.0.8.1 lib/active_storage/transformers/transformer.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-7.0.3.1/lib/active_storage/transformers/transformer.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-7.0.2.3/lib/active_storage/transformers/transformer.rb
activestorage-7.0.8 lib/active_storage/transformers/transformer.rb
activestorage-7.0.7.2 lib/active_storage/transformers/transformer.rb
activestorage-7.0.7.1 lib/active_storage/transformers/transformer.rb
activestorage-7.0.7 lib/active_storage/transformers/transformer.rb
activestorage-7.0.6 lib/active_storage/transformers/transformer.rb
activestorage-7.0.5.1 lib/active_storage/transformers/transformer.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activestorage-7.0.2.3/lib/active_storage/transformers/transformer.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activestorage-7.0.3.1/lib/active_storage/transformers/transformer.rb
activestorage-7.0.5 lib/active_storage/transformers/transformer.rb
activestorage-7.0.4.3 lib/active_storage/transformers/transformer.rb