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 extension.
- #mime_type_fuee ⇒ Object
-
#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 extension.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/paperclip/upfile.rb', line 8 def content_type type = (self.path.match(/\.(\w+)$/)[1] rescue mime_type_fuee).downcase case type when %r"jp(e|g|eg)" then "image/jpeg" when %r"tiff?" then "image/tiff" when %r"png", "gif", "bmp" then "image/#{type}" when "txt" then "text/plain" when %r"html?" then "text/html" when "js" then "application/js" when "csv", "xml", "css" then "text/#{type}" else Paperclip.run("file", "--mime-type #{self.path}").split(':').last.strip rescue "application/x-#{type}" end end |
#mime_type_fuee ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/paperclip/upfile.rb', line 33 def mime_type_fuee if File.respond_to?(:mime_type?) File.mime_type?(self) else "octet-stream" end end |
#original_filename ⇒ Object
Returns the file’s normal name.
24 25 26 |
# File 'lib/paperclip/upfile.rb', line 24 def original_filename File.basename(self.path) end |
#size ⇒ Object
Returns the size of the file.
29 30 31 |
# File 'lib/paperclip/upfile.rb', line 29 def size File.size(self) end |