Class Mack::Utils::MimeTypes
In: lib/mack/utils/mime_types.rb
Parent: Object

Houses the MimeTypes used by the system to set the proper ‘Content-Type’ for requests.

Methods

[]   get   register   register  

Included Modules

Singleton

Public Class methods

Maps to Mack::Utils::MimeTypes.instance.get

[Source]

    # File lib/mack/utils/mime_types.rb, line 43
43:         def [](name)
44:           Mack::Utils::MimeTypes.instance.get(name.to_sym)
45:         end

Maps to Mack::Utils::MimeTypes.instance.register

[Source]

    # File lib/mack/utils/mime_types.rb, line 48
48:         def register(name, type)
49:           Mack::Utils::MimeTypes.instance.register(name, type)
50:         end

Public Instance methods

Returns the type registered for the key, if there is no type for the key, then "text/html" is returned

Examples: Mack::Utils::MimeTypes.get(:iphone)

  # => "app/iphone"

Mack::Utils::MimeTypes.get(:i_dont_exist)

  # => "text/html"

[Source]

    # File lib/mack/utils/mime_types.rb, line 36
36:       def get(name)
37:         @types[name.to_sym] || "text/html"
38:       end

Registers a new mime-type to the system. If the key already exists, it will be appended to the existing type.

Examples: Mack::Utils::MimeTypes.register(:iphone, "app/iphone")

  "/users.iphone" # => will have a 'Content-Type' header of "app/iphone"

Mack::Utils::MimeTypes.register(:iphone, "application/mac-iphone")

  "/users.iphone" # => will have a 'Content-Type' header of "app/iphone; application/mac-iphone"

[Source]

    # File lib/mack/utils/mime_types.rb, line 19
19:       def register(name, type)
20:         name = name.to_sym
21:         if @types.has_key?(name)
22:           @types[name] << "; " << type
23:         else
24:           @types[name] = type
25:         end
26:       end

[Validate]