Module: Paperclip::Upfile

Included in:
File
Defined in:
lib/paperclip/upfile.rb

Overview

The Upfile module is a convenience module for adding uploaded-file-type methods to the File class. Useful for testing. user.avatar = File.new("test/test_avatar.jpg")

Instance Method Summary collapse

Instance Method Details

#content_typeObject

Infer the MIME-type of the file from the magic.



11
12
13
# File 'lib/paperclip/upfile.rb', line 11

def content_type
   MimeMagic.by_magic(self).type || "application/octet-stream"
end

#hexdigestObject

Returns the hexdigest of the file.



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

def hexdigest
  Digest::SHA2.new(512).hexdigest(self.read) # FIXME needed actual digest_bitlength from Attachment class instead of "512" constant
end

#original_filenameObject

Returns the file's normal name.



16
17
18
# File 'lib/paperclip/upfile.rb', line 16

def original_filename
  File.basename(self.path)
end

#sizeObject

Returns the size of the file.



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

def size
  File.size(self)
end