Module: Strelka::App::Negotiation::ClassMethods

Defined in:
lib/strelka/app/negotiation.rb

Overview

Class methods to add to classes with content-negotiation.

Instance Method Summary collapse

Instance Method Details

#add_content_type(name, mimetype, callback = nil) ⇒ Object

Define a new media-type associated with the specified name and mimetype. Responses whose requests accept content of the given mimetype will #call the specified callback with the current response body, and should return the transformed body. If the conversion failed, the callback can either raise an exception or return nil, either of which will continue on to any remaining transforms. If no callback is given, the method's block will be used.



45
46
47
48
49
# File 'lib/strelka/app/negotiation.rb', line 45

def add_content_type( name, mimetype, callback=nil ) # :yield: response.body
	callback ||= Proc.new # Use the block
	Strelka::HTTPResponse::Negotiation.mimetype_map[ name.to_sym ] = mimetype
	Strelka::HTTPResponse::Negotiation.stringifiers[ mimetype ] = callback
end