Sha256: 38bfbe722baba5e5bc23aa6a936b31fc82709d00ff7ac74d8514d1fe844e492e

Contents?: true

Size: 897 Bytes

Versions: 4

Compression:

Stored size: 897 Bytes

Contents

module Paperclip
  class StringioAdapter < AbstractAdapter
    def initialize(target)
      @target = target
      cache_current_values
      @tempfile = copy_to_tempfile(@target)
    end

    attr_writer :original_filename, :content_type
    private

    def cache_current_values
      @original_filename = @target.original_filename if @target.respond_to?(:original_filename)
      @original_filename ||= "stringio.txt"
      @original_filename = @original_filename.strip

      @content_type = @target.content_type if @target.respond_to?(:content_type)
      @content_type ||= "text/plain"

      @size = @target.size
    end

    def copy_to_tempfile(src)
      while data = src.read(16*1024)
        destination.write(data)
      end
      destination.rewind
      destination
    end

  end
end

Paperclip.io_adapters.register Paperclip::StringioAdapter do |target|
  StringIO === target
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
paperclip-3.2.1 lib/paperclip/io_adapters/stringio_adapter.rb
paperclip-3.3.0 lib/paperclip/io_adapters/stringio_adapter.rb
paperclip-3.2.0 lib/paperclip/io_adapters/stringio_adapter.rb
paperclip-3.1.4 lib/paperclip/io_adapters/stringio_adapter.rb