Module: Wrest::Components::Translators

Defined in:
lib/wrest/components/translators.rb,
lib/wrest/components/translators/xml.rb,
lib/wrest/components/translators/content_types.rb

Overview

Contains strategies/lambdas which know how to deserialise different content types.

Defined Under Namespace

Modules: Json, Xml

Constant Summary

CONTENT_TYPES =

Maps content types to deserialisers

{
  'application/xml' => Wrest::Components::Translators::Xml,
  'text/xml' => Wrest::Components::Translators::Xml,
  'application/json' => Wrest::Components::Translators::Json,
  'text/javascript' => Wrest::Components::Translators::Json
}

Class Method Summary (collapse)

Class Method Details

+ (Object) lookup(content_type)

Loads the appropriate desirialisation strategy based on the content type



18
19
20
21
# File 'lib/wrest/components/translators.rb', line 18

def self.lookup(content_type)
  translator = CONTENT_TYPES[content_type]
  translator || (raise Wrest::Exceptions::UnsupportedContentType.new("Unsupported content type #{content_type}"))
end