summaryrefslogtreecommitdiffstats
path: root/lib/redmine
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-01-05 17:56:21 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-01-05 17:56:21 +0000
commitd2f540358f39b3cb89885f4733e51d8d183b4720 (patch)
treece59a6cb652e3ecaa063f28dd1b6586617453967 /lib/redmine
parente1189c5335b99803a923992016501b08d14864d1 (diff)
downloadredmine-d2f540358f39b3cb89885f4733e51d8d183b4720.tar.gz
redmine-d2f540358f39b3cb89885f4733e51d8d183b4720.zip
Store mime type lookups in a hash.
git-svn-id: http://svn.redmine.org/redmine/trunk@12484 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine')
-rw-r--r--lib/redmine/mime_type.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/redmine/mime_type.rb b/lib/redmine/mime_type.rb
index 7231e9898..caca97106 100644
--- a/lib/redmine/mime_type.rb
+++ b/lib/redmine/mime_type.rb
@@ -55,13 +55,16 @@ module Redmine
# returns mime type for name or nil if unknown
def self.of(name)
- return nil unless name
- m = name.to_s.match(/(^|\.)([^\.]+)$/)
- ext = m[2].downcase
- type = nil
- type = EXTENSIONS[ext] if m
- type ||= MIME::Types.find {|type| type.extensions.include?(ext)}.to_s.presence
- type
+ return nil unless name.present?
+ if m = name.to_s.match(/(^|\.)([^\.]+)$/)
+ extension = m[2].downcase
+ @known_types ||= Hash.new do |h, ext|
+ type = EXTENSIONS[ext]
+ type ||= MIME::Types.find {|type| type.extensions.include?(ext)}.to_s.presence
+ h[ext] = type
+ end
+ @known_types[extension]
+ end
end
# Returns the css class associated to