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")
Methods
Public Instance methods
content_type()

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

    # File lib/data_base/attachment/upfile.rb, line 9
 9:       def content_type
10:         type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
11:         case type
12:         when %r"jpe?g"                 then "image/jpeg"
13:         when %r"tiff?"                 then "image/tiff"
14:         when %r"png", "gif", "bmp"     then "image/#{type}"
15:         when "txt"                     then "text/plain"
16:         when %r"html?"                 then "text/html"
17:         when "csv", "xml", "css", "js" then "text/#{type}"
18:         else "application/x-#{type}"
19:         end
20:       end
original_filename()

Returns the file‘s normal name.

    # File lib/data_base/attachment/upfile.rb, line 23
23:       def original_filename
24:         File.basename(self.path)
25:       end
size()

Returns the size of the file.

    # File lib/data_base/attachment/upfile.rb, line 28
28:       def size
29:         File.size(self)
30:       end