Sha256: 0f4800cf01eef8a4c764e5848c77ed3ad50cff81c53e92dd7e68aae13f6947f9

Contents?: true

Size: 875 Bytes

Versions: 2

Compression:

Stored size: 875 Bytes

Contents

module Paperclip
  module Rack
    class FileAdapter < ::Paperclip::AbstractAdapter
      def initialize(target)
        @target = target[:tempfile]
        cache_current_values(target)
      end

      private

        def cache_current_values(target)
          self.original_filename = target[:filename] if target.has_key?(:filename)
          self.original_filename ||= @target.original_filename if @target.respond_to?(:original_filename)
          self.original_filename ||= File.basename(@target.path)
          @tempfile = copy_to_tempfile(@target)
          @content_type = Paperclip::ContentTypeDetector.new(@target.path).detect
          @size = File.size(@target)
        end

    end
  end
end

Paperclip.io_adapters.register Paperclip::Rack::FileAdapter do |target|
  begin
   target.is_a?(Hash) && Tempfile === target[:tempfile]
  rescue => e
    false
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paperclip-rack-0.0.2 lib/paperclip/rack/io_adapters/file_adapter.rb
paperclip-rack-0.0.1 lib/paperclip/rack/io_adapters/file_adapter.rb