Class: Swagger::MimeType
- Inherits:
-
String
- Object
- String
- Swagger::MimeType
- Extended by:
- Forwardable
- Defined in:
- lib/swagger/mime_type.rb
Overview
Class representing Media Types (commonly known as MIME Types).
Constant Summary collapse
- MIME_TYPE_FORMAT =
/(\w+)\/(\w+\.)?([\w\.]+)(\+\w+)?\s*(;.*)?/
- COMMON_ALIASES =
{ txt: 'text/plain', text: 'text/plain', json: 'application/json', xml: 'application/xml', binary: 'application/octet-stream' }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mime_type_name) ⇒ MimeType
constructor
A new instance of MimeType.
Constructor Details
#initialize(mime_type_name) ⇒ MimeType
Returns a new instance of MimeType.
20 21 22 23 24 25 |
# File 'lib/swagger/mime_type.rb', line 20 def initialize(mime_type_name) @mime_type_name = mime_type_name.to_s @mime_type = MIME::Types[@mime_type_name].first || base_type(@mime_type_name) raise ArgumentError, "Unknown mime type or suffix: #{mime_type_name}" if @mime_type.nil? super @mime_type_name end |
Class Method Details
.parser_for(mime_type) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/swagger/mime_type.rb', line 27 def self.parser_for(mime_type) mime_type = COMMON_ALIASES[mime_type] if COMMON_ALIASES.key? mime_type case mime_type when 'application/json' return JSON else raise NotImplementedError, "Parser support for #{mime_type} is not implemented" end end |