Sha256: b2aac8ad49a2f97dadadc1f3607339f6d3c4491955137ede3aff8a21c21affe8

Contents?: true

Size: 1.28 KB

Versions: 40

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module ActiveStorage
  module Transformers
    # = Active Storage \Transformers \Transformer
    #
    # 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

40 entries across 40 versions & 5 rubygems

Version Path
activestorage-8.0.2 lib/active_storage/transformers/transformer.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activestorage-7.1.3.4/lib/active_storage/transformers/transformer.rb
activestorage-8.0.1 lib/active_storage/transformers/transformer.rb
activestorage-8.0.0.1 lib/active_storage/transformers/transformer.rb
activestorage-7.2.2.1 lib/active_storage/transformers/transformer.rb
activestorage-7.1.5.1 lib/active_storage/transformers/transformer.rb
activestorage-8.0.0 lib/active_storage/transformers/transformer.rb
activestorage-7.2.2 lib/active_storage/transformers/transformer.rb
activestorage-7.1.5 lib/active_storage/transformers/transformer.rb
activestorage-8.0.0.rc2 lib/active_storage/transformers/transformer.rb
activestorage-7.2.1.2 lib/active_storage/transformers/transformer.rb
activestorage-7.1.4.2 lib/active_storage/transformers/transformer.rb
activestorage-8.0.0.rc1 lib/active_storage/transformers/transformer.rb
activestorage-7.2.1.1 lib/active_storage/transformers/transformer.rb
activestorage-7.1.4.1 lib/active_storage/transformers/transformer.rb
activestorage-8.0.0.beta1 lib/active_storage/transformers/transformer.rb
omg-activestorage-8.0.0.alpha9 lib/active_storage/transformers/transformer.rb
omg-activestorage-8.0.0.alpha8 lib/active_storage/transformers/transformer.rb
omg-activestorage-8.0.0.alpha7 lib/active_storage/transformers/transformer.rb
omg-activestorage-8.0.0.alpha4 lib/active_storage/transformers/transformer.rb