Class: Paperclip::UploadedFileAdapter

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

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ UploadedFileAdapter

Returns a new instance of UploadedFileAdapter.



3
4
5
6
7
8
9
10
11
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 3

def initialize(target)
  @target = target

  if @target.respond_to?(:tempfile)
    @tempfile = copy_to_tempfile(@target.tempfile)
  else
    @tempfile = copy_to_tempfile(@target)
  end
end

Instance Method Details

#content_typeObject



17
18
19
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 17

def content_type
  @target.content_type
end

#eof?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 42

def eof?
  @tempfile.eof?
end

#fingerprintObject



21
22
23
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 21

def fingerprint
  @fingerprint ||= Digest::MD5.file(path).to_s
end

#nil?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 29

def nil?
  false
end

#original_filenameObject



13
14
15
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 13

def original_filename
  @target.original_filename
end

#pathObject



46
47
48
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 46

def path
  @tempfile.path
end

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



33
34
35
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 33

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

#rewindObject

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



38
39
40
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 38

def rewind
  @tempfile.rewind
end

#sizeObject



25
26
27
# File 'lib/paperclip/io_adapters/uploaded_file_adapter.rb', line 25

def size
  File.size(path)
end