Class: Paperclip::FileAdapter

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

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ FileAdapter

Returns a new instance of FileAdapter.



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

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

Instance Method Details

#content_typeObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 16

def content_type
  types = MIME::Types.type_for(original_filename)
  if types.length == 0
    type_from_file_command
  elsif types.length == 1
    types.first.content_type
  else
    best_content_type_option(types)
  end
end

#eof?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 48

def eof?
  @tempfile.eof?
end

#fingerprintObject



27
28
29
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 27

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

#nil?Boolean

Returns:

  • (Boolean)


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

def nil?
  @target.nil?
end

#original_filenameObject



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

def original_filename
  if @target.respond_to?(:original_filename)
    @target.original_filename
  else
    File.basename(@target.path)
  end
end

#pathObject



52
53
54
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 52

def path
  @tempfile.path
end

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



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

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

#rewindObject

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



44
45
46
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 44

def rewind
  @tempfile.rewind
end

#sizeObject



31
32
33
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 31

def size
  File.size(@tempfile)
end