Sha256: 06b8f11550e06e45023a2e6fd6ccdc40ba23275ddde9ccc7c2c06f315950a4ab

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

module Paperclip
  class UploadedFileAdapter < AbstractAdapter
    def self.register
      Paperclip.io_adapters.register self do |target|
        target.class.name.include?("UploadedFile")
      end
    end

    def initialize(target, options = {})
      super
      cache_current_values

      @tempfile = if @target.respond_to?(:tempfile)
                    copy_to_tempfile(@target.tempfile)
                  else
                    copy_to_tempfile(@target)
                  end
    end

    class << self
      attr_accessor :content_type_detector
    end

    private

    def cache_current_values
      self.original_filename = @target.original_filename
      @content_type = determine_content_type
      @size = File.size(@target.path)
    end

    def content_type_detector
      self.class.content_type_detector || Paperclip::ContentTypeDetector
    end

    def determine_content_type
      content_type = @target.content_type.to_s.strip
      content_type = content_type_detector.new(@target.path).detect if content_type_detector
      content_type
    end
  end
end

Paperclip::UploadedFileAdapter.register

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kt-paperclip-7.2.2 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-7.2.1 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-7.2.0 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-6.4.2 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-7.1.1 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-7.1.0 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-7.0.1 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-7.0.0 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-6.4.1 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-6.4.0 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-6.3.0 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-6.2.2 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-6.2.1 lib/paperclip/io_adapters/uploaded_file_adapter.rb
kt-paperclip-6.2.0 lib/paperclip/io_adapters/uploaded_file_adapter.rb