lib/mini_mime.rb in mini_mime-1.0.1 vs lib/mini_mime.rb in mini_mime-1.0.2
- old
+ new
@@ -12,10 +12,20 @@
def self.lookup_by_content_type(mime)
Db.lookup_by_content_type(mime)
end
+ module Configuration
+ class << self
+ attr_accessor :ext_db_path
+ attr_accessor :content_type_db_path
+ end
+
+ self.ext_db_path = File.expand_path("../db/ext_mime.db", __FILE__)
+ self.content_type_db_path = File.expand_path("../db/content_type_mime.db", __FILE__)
+ end
+
class Info
BINARY_ENCODINGS = %w(base64 8bit)
attr_accessor :extension, :content_type, :encoding
@@ -81,12 +91,12 @@
end
class RandomAccessDb
MAX_CACHED = 100
- def initialize(name, sort_order)
- @path = File.expand_path("../db/#{name}", __FILE__)
+ def initialize(path, sort_order)
+ @path = path
@file = File.open(@path)
@row_length = @file.readline.length
@file_length = File.size(@path)
@rows = @file_length / @row_length
@@ -139,11 +149,11 @@
Info.new(@file.readline)
end
end
def initialize
- @ext_db = RandomAccessDb.new("ext_mime.db", 0)
- @content_type_db = RandomAccessDb.new("content_type_mime.db", 1)
+ @ext_db = RandomAccessDb.new(Configuration.ext_db_path, 0)
+ @content_type_db = RandomAccessDb.new(Configuration.content_type_db_path, 1)
end
def lookup_by_extension(extension)
@ext_db.lookup(extension)
end