class Sinatra::RPC::Serializer::Base

The base class for all Serializer instances.

Attributes

response_content_type[R]

Public Class Methods

content_types(*content_types) click to toggle source

Set the list of content types supported by this serializer. @param content_types [*String] the list of supported content types;

if set to `nil`, this serializer is used as a default in case the
content type is not specified in the request.
# File lib/sinatra/rpc/serializer/base.rb, line 14
def content_types(*content_types)
  Sinatra::RPC::Serializer.register self, content_types
  @response_content_type = content_types.compact.first
end

Public Instance Methods

content_type() click to toggle source

The content type that should be set in responses. By default it is the first from the list of content types defined by the class. @return [String] the content type to set in the response header.

# File lib/sinatra/rpc/serializer/base.rb, line 23
def content_type
  self.class.response_content_type
end
content_type_options() click to toggle source

An hash of options to set with the response content type. For example, {charset: ‘utf-8’} is used in XML-RPC. The default implementation returns an empty hash.

# File lib/sinatra/rpc/serializer/base.rb, line 30
def content_type_options
  {}
end
dump(response) click to toggle source

Convert the response object to a string to be used in the body of the HTTP response. Must be implemented by subclasses. @param response [Object] any response object @return [String] a string representation of the response

# File lib/sinatra/rpc/serializer/base.rb, line 46
def dump(response)
  raise NotImplementedError
end
parse(request) click to toggle source

Parse an incoming RPC request. This method must be implemented by subclasses. @param request [String] the body of the HTTP POST request. @return [Array] an array of the form [‘handler.rpcMethod’, [arg1, arg2, …]]

# File lib/sinatra/rpc/serializer/base.rb, line 38
def parse(request)
  raise NotImplementedError
end