Created
July 1, 2013 12:13
-
-
Save Pilooz/5900307 to your computer and use it in GitHub Desktop.
guess mime type from filename extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Internal: Lookup mime type for extension. | |
# | |
# Returns a MIME::Type | |
def _mime_type | |
if defined? @_mime_type | |
@_mime_type | |
else | |
guesses = ::MIME::Types.type_for(extname.to_s) | |
# Prefer text mime types over binary | |
@_mime_type = guesses.detect { |type| type.ascii? } || | |
# Otherwise use the first guess | |
guesses.first | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment