Module: HTTP::MimeType
- Defined in:
- lib/http/mime_type.rb,
lib/http/mime_type/json.rb,
lib/http/mime_type/adapter.rb
Overview
MIME type encode/decode adapters
Defined Under Namespace
Class Method Summary collapse
-
.[](type) ⇒ Class
Returns adapter associated with MIME type.
-
.normalize(type) ⇒ String
Resolves type by shortcut if possible.
-
.register_adapter(type, adapter) ⇒ void
Associate MIME type with adapter.
-
.register_alias(type, shortcut) ⇒ void
Register a shortcut for MIME type.
Class Method Details
.[](type) ⇒ Class
Returns adapter associated with MIME type
37 38 39 |
# File 'lib/http/mime_type.rb', line 37 def [](type) adapters[normalize type] || raise(Error, "Unknown MIME type: #{type}") end |
.normalize(type) ⇒ String
Resolves type by shortcut if possible
58 59 60 |
# File 'lib/http/mime_type.rb', line 58 def normalize(type) aliases.fetch type, type.to_s end |
.register_adapter(type, adapter) ⇒ void
This method returns an undefined value.
Associate MIME type with adapter
28 29 30 |
# File 'lib/http/mime_type.rb', line 28 def register_adapter(type, adapter) adapters[type.to_s] = adapter end |
.register_alias(type, shortcut) ⇒ void
This method returns an undefined value.
Register a shortcut for MIME type
50 51 52 |
# File 'lib/http/mime_type.rb', line 50 def register_alias(type, shortcut) aliases[shortcut.to_sym] = type.to_s end |