Class: Sinatra::RPC::Serializer::Base
- Inherits:
-
Object
- Object
- Sinatra::RPC::Serializer::Base
- Defined in:
- lib/sinatra/rpc/serializer/base.rb
Overview
The base class for all Serializer instances.
Direct Known Subclasses
Class Attribute Summary collapse
-
.response_content_type ⇒ Object
readonly
Returns the value of attribute response_content_type.
Class Method Summary collapse
-
.content_types(*content_types) ⇒ Object
Set the list of content types supported by this serializer.
Instance Method Summary collapse
-
#content_type ⇒ String
The content type that should be set in responses.
-
#content_type_options ⇒ Object
An hash of options to set with the response content type.
-
#dump(response) ⇒ String
Convert the response object to a string to be used in the body of the HTTP response.
-
#parse(request) ⇒ Array
Parse an incoming RPC request.
Class Attribute Details
.response_content_type ⇒ Object (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_type ⇒ String
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_options ⇒ Object
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 {} 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.
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.
38 39 40 |
# File 'lib/sinatra/rpc/serializer/base.rb', line 38 def parse(request) raise NotImplementedError end |