Class: MiniMime::Db

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_mime.rb

Defined Under Namespace

Classes: Cache, RandomAccessDb

Constant Summary collapse

LOCK =
Mutex.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDb

Returns a new instance of Db.



140
141
142
143
# File 'lib/mini_mime.rb', line 140

def initialize
  @ext_db = RandomAccessDb.new("ext_mime.db", 0)
  @content_type_db = RandomAccessDb.new("content_type_mime.db", 1)
end

Class Method Details

.lookup_by_content_type(content_type) ⇒ Object



56
57
58
59
60
61
# File 'lib/mini_mime.rb', line 56

def self.lookup_by_content_type(content_type)
  LOCK.synchronize do
    @db ||= new
    @db.lookup_by_content_type(content_type)
  end
end

.lookup_by_filename(filename) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mini_mime.rb', line 40

def self.lookup_by_filename(filename)
  extension = File.extname(filename)
  if extension
    extension.sub!(".", "")
    extension.downcase!
    if extension.length > 0
      LOCK.synchronize do
        @db ||= new
        @db.lookup_by_extension(extension)
      end
    else
      nil
    end
  end
end

Instance Method Details

#lookup_by_content_type(content_type) ⇒ Object



149
150
151
# File 'lib/mini_mime.rb', line 149

def lookup_by_content_type(content_type)
  @content_type_db.lookup(content_type)
end

#lookup_by_extension(extension) ⇒ Object



145
146
147
# File 'lib/mini_mime.rb', line 145

def lookup_by_extension(extension)
  @ext_db.lookup(extension)
end