Sha256: 81b04149a59acbaf6a0a4f5c746698e5986879494d229db77b32174d343cb8ab

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 37 versions & 4 rubygems

Version Path
activestorage-6.1.4.4 lib/active_storage/transformers/transformer.rb
activestorage-6.1.4.3 lib/active_storage/transformers/transformer.rb
activestorage-6.1.4.2 lib/active_storage/transformers/transformer.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/activestorage-6.1.4.1/lib/active_storage/transformers/transformer.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/activestorage-6.1.4.1/lib/active_storage/transformers/transformer.rb
activestorage-6.1.4.1 lib/active_storage/transformers/transformer.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/activestorage-6.1.4/lib/active_storage/transformers/transformer.rb
activestorage-6.1.4 lib/active_storage/transformers/transformer.rb
activestorage-6.1.3.2 lib/active_storage/transformers/transformer.rb
activestorage-6.1.3.1 lib/active_storage/transformers/transformer.rb
activestorage-6.1.3 lib/active_storage/transformers/transformer.rb
activestorage-6.1.2.1 lib/active_storage/transformers/transformer.rb
activestorage-6.1.2 lib/active_storage/transformers/transformer.rb
activestorage-6.1.1 lib/active_storage/transformers/transformer.rb
activestorage-6.1.0 lib/active_storage/transformers/transformer.rb
activestorage-6.1.0.rc2 lib/active_storage/transformers/transformer.rb
activestorage-6.1.0.rc1 lib/active_storage/transformers/transformer.rb