Sha256: c8d130bdc99048801f5baff4b62484b97584139c4e5c9190cce50497820baff4
Contents?: true
Size: 1.29 KB
Versions: 42
Compression:
Stored size: 1.29 KB
Contents
module Lipsiadmin module Attachment # 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") module Upfile # Infer the MIME-type of the file from the extension. 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 # Returns the file's normal name. def original_filename File.basename(self.path) end # Returns the size of the file. def size File.size(self) end end end if defined? StringIO class StringIO#:nodoc: attr_accessor :original_filename, :content_type def original_filename @original_filename ||= "stringio.txt" end def content_type @content_type ||= "text/plain" end end end end
Version data entries
42 entries across 42 versions & 1 rubygems