Sha256: 48ad110e16cab8299b3c5d355617568cef56d872fefc5baca2a3e198f4fcfe52

Contents?: true

Size: 882 Bytes

Versions: 2

Compression:

Stored size: 882 Bytes

Contents

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

    attr_writer :content_type

    private

    def cache_current_values
      @original_filename = @target.original_filename if @target.respond_to?(:original_filename)
      @original_filename ||= "stringio.txt"
      self.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

2 entries across 2 versions & 1 rubygems

Version Path
paperclip-3.4.2 lib/paperclip/io_adapters/stringio_adapter.rb
paperclip-3.4.1 lib/paperclip/io_adapters/stringio_adapter.rb