Class: Mack::Utils::MimeTypes
- Includes:
- Singleton
- Defined in:
- lib/mack/utils/mime_types.rb
Overview
Houses the MimeTypes used by the system to set the proper ‘Content-Type’ for requests.
Class Method Summary collapse
-
.[](name) ⇒ Object
Maps to Mack::Utils::MimeTypes.instance.get.
-
.register(name, type) ⇒ Object
Maps to Mack::Utils::MimeTypes.instance.register.
Instance Method Summary collapse
-
#get(name) ⇒ Object
Returns the type registered for the key, if there is no type for the key, then “text/html” is returned.
-
#initialize ⇒ MimeTypes
constructor
:nodoc:.
-
#register(name, type) ⇒ Object
Registers a new mime-type to the system.
Constructor Details
#initialize ⇒ MimeTypes
:nodoc:
7 8 9 |
# File 'lib/mack/utils/mime_types.rb', line 7 def initialize # :nodoc: @types = YAML.load(File.open(File.join(File.dirname(__FILE__), "mime_types.yml"))) end |
Class Method Details
Instance Method Details
#get(name) ⇒ Object
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"
36 37 38 |
# File 'lib/mack/utils/mime_types.rb', line 36 def get(name) @types[name.to_sym] || "text/html" end |
#register(name, type) ⇒ Object
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"
19 20 21 22 23 24 25 26 |
# File 'lib/mack/utils/mime_types.rb', line 19 def register(name, type) name = name.to_sym if @types.has_key?(name) @types[name] << "; " << type else @types[name] = type end end |