Class: Sinatra::RPC::Serializer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/rpc/serializer/base.rb

Overview

The base class for all Serializer instances.

Direct Known Subclasses

XMLRPC

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.response_content_typeObject (readonly)

Returns the value of attribute response_content_type


8
9
10
# File 'lib/sinatra/rpc/serializer/base.rb', line 8

def response_content_type
  @response_content_type
end

Class Method Details

.content_types(*content_types) ⇒ Object

Set the list of content types supported by this serializer.


14
15
16
17
# 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

Instance Method Details

#content_typeString

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.


23
24
25
# File 'lib/sinatra/rpc/serializer/base.rb', line 23

def content_type
  self.class.response_content_type
end

#content_type_optionsObject

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


30
31
32
# File 'lib/sinatra/rpc/serializer/base.rb', line 30

def content_type_options
  {}
end

#dump(response) ⇒ String

Convert the response object to a string to be used in the body of the HTTP response. Must be implemented by subclasses.

Raises:

  • (NotImplementedError)

46
47
48
# File 'lib/sinatra/rpc/serializer/base.rb', line 46

def dump(response)
  raise NotImplementedError
end

#parse(request) ⇒ Array

Parse an incoming RPC request. This method must be implemented by subclasses.

Raises:

  • (NotImplementedError)

38
39
40
# File 'lib/sinatra/rpc/serializer/base.rb', line 38

def parse(request)
  raise NotImplementedError
end