lib/paperclip/io_adapters/stringio_adapter.rb in paperclip-3.0.4 vs lib/paperclip/io_adapters/stringio_adapter.rb in paperclip-3.1.0
- old
+ new
@@ -1,62 +1,31 @@
module Paperclip
- class StringioAdapter
+ 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 original_filename
- @original_filename ||= @target.original_filename if @target.respond_to?(:original_filename)
+ def cache_current_values
+ @original_filename = @target.original_filename if @target.respond_to?(:original_filename)
@original_filename ||= "stringio.txt"
- @original_filename.strip
- end
+ @original_filename = @original_filename.strip
- def content_type
- @content_type ||= @target.content_type if @target.respond_to?(:content_type)
+ @content_type = @target.content_type if @target.respond_to?(:content_type)
@content_type ||= "text/plain"
- @content_type
- end
- def size
- @target.size
+ @size = @target.size
end
- def fingerprint
- Digest::MD5.hexdigest(read)
- end
-
- def read(length = nil, buffer = nil)
- @tempfile.read(length, buffer)
- end
-
- # We don't use this directly, but aws/sdk does.
- def rewind
- @tempfile.rewind
- end
-
- def eof?
- @tempfile.eof?
- end
-
- def path
- @tempfile.path
- end
-
- private
-
def copy_to_tempfile(src)
- extension = File.extname(original_filename)
- basename = File.basename(original_filename, extension)
- dest = Tempfile.new([basename, extension])
- dest.binmode
while data = src.read(16*1024)
- dest.write(data)
+ destination.write(data)
end
- dest.rewind
- dest
+ destination.rewind
+ destination
end
end
end