class M2Config::MimeType
Constants
- MONGREL2_PREFS
- RECESSIVE
- SQL_FIND_DUPLICATES
Public Class Methods
new(fields)
click to toggle source
Calls superclass method
# File lib/m2config/mimetype.rb, line 67 def initialize(fields) raise ArgumentError, "Extension must start with a ." unless fields[:extension] =~ /^\./ type = M2Config::MimeType[extension:fields[:extension]] raise ArgumentError, "extension #{fields[:extension]} is already covered by #{type.mimetype} type" if type super(fields, false) save end
not_dominant?(mtype)
click to toggle source
Is it reasonable to ignore this type ?
# File lib/m2config/mimetype.rb, line 38 def self.not_dominant?(mtype) mtype.obsolete? || superceded?(mtype) || !simplest?(mtype) end
populate_table(types=nil, ignoreDoubles=false)
click to toggle source
# File lib/m2config/mimetype.rb, line 16 def self.populate_table(types=nil, ignoreDoubles=false) raise RuntimeError, "Table must be empty" if db[:mimetype].count > 0 types ||= MIME::Types rows = [] # Will collect ext<->type rows types.each { |type| next if not_dominant?(type) type.extensions.each { |ext| ext = "."+ext clashingType = M2Config::MimeType[extension:ext] raise ArgumentError, "extension #{ext} is already covered by #{clashingType.mimetype} type" if clashingType rows << [type.content_type, ext] } } db.transaction { db[:mimetype].import([:mimetype, :extension], rows) } remove_duplicates unless ignoreDoubles end
remove_duplicates()
click to toggle source
# File lib/m2config/mimetype.rb, line 50 def self.remove_duplicates randomChoices = [] db[SQL_FIND_DUPLICATES].all.each { |r| ext = r[:extension] preferred = MONGREL2_PREFS[ext] if preferred db[:mimetype].where(extension:ext).delete db[:mimetype].insert(extension:ext, mimetype:preferred) else raise ArgumentError, "#{ext} (#{r[:mimetype]}) has multiple content types but no Mongrel2 preference" end } raise RuntimeError, "Still duplicates after removing duplicates!" if db[SQL_FIND_DUPLICATES].all.size > 0 end
simplest?(mtype)
click to toggle source
# File lib/m2config/mimetype.rb, line 46 def self.simplest?(mtype) mtype.content_type == mtype.simplified end
superceded?(mtype)
click to toggle source
# File lib/m2config/mimetype.rb, line 42 def self.superceded?(mtype) mtype.docs =~ /instead/ end