Harbor Documentation

Harbor::Mime

Copyright © 2007, 2008, 2009 Christian Neukirchen This file originated from the Rack project, which can be found at rack.rubyforge.org

Constants

  • MIME_TYPES

    List of most common mime-types, selected various sources according to their usefulness in a webserving scope for Ruby users.

    To amend this list with your local mime.types list you can use:

        require 'webrick/httputils'
        list = WEBrick::HTTPUtils.load_mime_types('/etc/mime.types')
        Harbor::Mime::MIME_TYPES.merge!(list)
    

    To add the list mongrel provides, use:

        require 'mongrel/handlers'
        Harbor::Mime::MIME_TYPES.merge!(Mongrel::DirHandler::MIME_TYPES)
    

Public Class Methods

mime_type(ext, fallback='application/octet-stream')

Returns String with mime type if found, otherwise use fallback. ext should be filename extension in the ’.ext’ format that

      File.extname(file) returns.

fallback may be any object

Also see the documentation for MIME_TYPES

Usage:

    Harbor::Mime.mime_type('.foo')

This is a shortcut for:

    Harbor::Mime::MIME_TYPES.fetch('.foo', 'application/octet-stream')
      # File lib/harbor/mime.rb, line 18
18:     def mime_type(ext, fallback='application/octet-stream')
19:       MIME_TYPES.fetch(ext, fallback)
20:     end

Private Instance Methods

mime_type(ext, fallback='application/octet-stream')

Returns String with mime type if found, otherwise use fallback. ext should be filename extension in the ’.ext’ format that

      File.extname(file) returns.

fallback may be any object

Also see the documentation for MIME_TYPES

Usage:

    Harbor::Mime.mime_type('.foo')

This is a shortcut for:

    Harbor::Mime::MIME_TYPES.fetch('.foo', 'application/octet-stream')
      # File lib/harbor/mime.rb, line 18
18:     def mime_type(ext, fallback='application/octet-stream')
19:       MIME_TYPES.fetch(ext, fallback)
20:     end