Class: Web::Mime::ApacheUnixReader

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

Overview

:nodoc:

Constant Summary collapse

MIME_FILENAME =
"resources/mime.types"
COMMENTED_PATTERN =
/(^\s*#)|(^\s*$)/
VALUE_PATTERN =
/\.*(\S+)\s*=\s*(\S+)/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.applies?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/web/mime.rb', line 27

def self.applies?
  File.exists? mime_file
end

.mime_fileObject



23
24
25
# File 'lib/web/mime.rb', line 23

def self.mime_file
  Web::lib_filename( MIME_FILENAME )
end

Instance Method Details

#mime_typesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/web/mime.rb', line 31

def mime_types
  mime_array = File.open( self.class.mime_file, "r" ) { |f|
    f.read.to_a
  }
  mime_array.uniq!
  mime_array.delete_if { |line|
    line =~ COMMENTED_PATTERN
  }
  mime_hash = {}
  mime_hash.default = DEFAULT_MIMETYPE
  mime_array.each { |line|
    pieces = line.split( /\s+/ )
    mime_type = pieces.shift
    pieces.each { |extension|
      mime_hash[extension] = mime_type
    }
  }
  mime_hash
end