Module: Paperclip::Upfile
- 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
-
#content_type ⇒ Object
Infer the MIME-type of the file from the magic.
-
#hexdigest ⇒ Object
Returns the hexdigest of the file.
-
#original_filename ⇒ Object
Returns the file’s normal name.
-
#size ⇒ Object
Returns the size of the file.
Instance Method Details
#content_type ⇒ Object
Infer the MIME-type of the file from the magic.
11 12 13 14 15 16 17 |
# File 'lib/paperclip/upfile.rb', line 11 def content_type unless MimeMagic.by_magic(self).nil? MimeMagic.by_magic(self).type else "application/octet-stream" end end |
#hexdigest ⇒ Object
Returns the hexdigest of the file.
30 31 32 |
# File 'lib/paperclip/upfile.rb', line 30 def hexdigest Digest::SHA2.new(512).hexdigest(self.read) # FIXME needed actual digest_bitlength from Attachment class instead of "512" constant end |
#original_filename ⇒ Object
Returns the file’s normal name.
20 21 22 |
# File 'lib/paperclip/upfile.rb', line 20 def original_filename File.basename(self.path) end |
#size ⇒ Object
Returns the size of the file.
25 26 27 |
# File 'lib/paperclip/upfile.rb', line 25 def size File.size(self) end |