Class: Paperclip::StringioAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip/io_adapters/stringio_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ StringioAdapter

Returns a new instance of StringioAdapter.



3
4
5
6
# File 'lib/paperclip/io_adapters/stringio_adapter.rb', line 3

def initialize(target)
  @target = target
  @tempfile = copy_to_tempfile(@target)
end

Instance Attribute Details

#content_typeObject



16
17
18
19
20
# File 'lib/paperclip/io_adapters/stringio_adapter.rb', line 16

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

#original_filenameObject



10
11
12
13
14
# File 'lib/paperclip/io_adapters/stringio_adapter.rb', line 10

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

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/paperclip/io_adapters/stringio_adapter.rb', line 39

def eof?
  @tempfile.eof?
end

#fingerprintObject



26
27
28
# File 'lib/paperclip/io_adapters/stringio_adapter.rb', line 26

def fingerprint
  Digest::MD5.hexdigest(read)
end

#pathObject



43
44
45
# File 'lib/paperclip/io_adapters/stringio_adapter.rb', line 43

def path
  @tempfile.path
end

#read(length = nil, buffer = nil) ⇒ Object



30
31
32
# File 'lib/paperclip/io_adapters/stringio_adapter.rb', line 30

def read(length = nil, buffer = nil)
  @tempfile.read(length, buffer)
end

#rewindObject

We don’t use this directly, but aws/sdk does.



35
36
37
# File 'lib/paperclip/io_adapters/stringio_adapter.rb', line 35

def rewind
  @tempfile.rewind
end

#sizeObject



22
23
24
# File 'lib/paperclip/io_adapters/stringio_adapter.rb', line 22

def size
  @target.size
end