Inline mime type lookup into blob helper

This commit is contained in:
Joshua Peek
2012-08-20 11:33:16 -05:00
parent 64f3509222
commit b85aeaad3e
3 changed files with 4 additions and 67 deletions

View File

@@ -32,7 +32,10 @@ module Linguist
#
# Returns a mime type String.
def mime_type
@mime_type ||= Mime.mime_for(extname.to_s)
@mime_type ||= begin
mime_type = Mime.lookup_mime_type_for(extname.to_s)
mime_type ? mime_type.to_s : 'text/plain'
end
end
# Public: Get the Content-Type header value

View File

@@ -3,24 +3,6 @@ require 'yaml'
module Linguist
module Mime
# Internal: Look up mime type for extension.
#
# ext - The extension String. May include leading "."
#
# Examples
#
# Mime.mime_for('.html')
# # => 'text/html'
#
# Mime.mime_for('txt')
# # => 'text/plain'
#
# Return mime type String otherwise falls back to 'text/plain'.
def self.mime_for(ext)
mime_type = lookup_mime_type_for(ext)
mime_type ? mime_type.to_s : 'text/plain'
end
# Internal: Lookup mime type for extension or mime type
#
# ext_or_mime_type - A file extension ".txt" or mime type "text/plain".