Module: Lipsiadmin::Attachment::Upfile
- Defined in:
- lib/data_base/attachment/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.
-
#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.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/data_base/attachment/upfile.rb', line 9 def content_type type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase case type when %r"jpe?g" 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 "csv", "xml", "css", "js" then "text/#{type}" else "application/x-#{type}" end end |
#original_filename ⇒ Object
Returns the file’s normal name.
23 24 25 |
# File 'lib/data_base/attachment/upfile.rb', line 23 def original_filename File.basename(self.path) end |
#size ⇒ Object
Returns the size of the file.
28 29 30 |
# File 'lib/data_base/attachment/upfile.rb', line 28 def size File.size(self) end |