From cffe6a7b6877ede4a9026a6fa69bb8bc2eba8d35 Mon Sep 17 00:00:00 2001 From: Nao Minami Date: Wed, 5 Jul 2017 12:11:40 +0900 Subject: [PATCH] Check all library for mime type lookup --- lib/asset_sync/multi_mime.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/asset_sync/multi_mime.rb b/lib/asset_sync/multi_mime.rb index eb73d392..c8085c7f 100644 --- a/lib/asset_sync/multi_mime.rb +++ b/lib/asset_sync/multi_mime.rb @@ -5,17 +5,28 @@ class MultiMime def self.lookup(ext) + mime = nil + library_found = false if defined?(::MIME::Types) - ::MIME::Types.type_for(ext).first - elsif defined?(::Mime::Type) - ::Mime::Type.lookup_by_extension(ext) - elsif defined?(::Rack::Mime) + mime = ::MIME::Types.type_for(ext).first + library_found = true + end + if !mime && defined?(::Mime::Type) + mime = ::Mime::Type.lookup_by_extension(ext) + library_found = true + end + if !mime && defined?(::Rack::Mime) ext_with_dot = ".#{ext}" - ::Rack::Mime.mime_type(ext_with_dot) - else + mime = ::Rack::Mime.mime_type(ext_with_dot) + library_found = true + end + + if !library_found raise "No library found for mime type lookup" end + mime + end end