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
-
#content_type ⇒ Object
Infer the MIME-type of the file from the magic.
-
#hash ⇒ Object
Returns the hash 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 |
# File 'lib/paperclip/upfile.rb', line 11 def content_type MimeMagic.by_magic(File.open(self.path)) end |
#hash ⇒ Object
Returns the hash of the file.
26 27 28 |
# File 'lib/paperclip/upfile.rb', line 26 def hash Digest::SHA2.new(512).file(self.path).hexdigest # FIXME needed actual hash_length from Attachment class instead of "512" constant end |
#original_filename ⇒ Object
Returns the file's normal name.
16 17 18 |
# File 'lib/paperclip/upfile.rb', line 16 def original_filename File.basename(self.path) end |
#size ⇒ Object
Returns the size of the file.
21 22 23 |
# File 'lib/paperclip/upfile.rb', line 21 def size File.size(self) end |