Module: Sinatra::RPC
- Defined in:
- lib/sinatra/rpc.rb,
lib/sinatra/rpc/fault.rb,
lib/sinatra/rpc/utils.rb,
lib/sinatra/rpc/helpers.rb,
lib/sinatra/rpc/version.rb,
lib/sinatra/rpc/serializer.rb,
lib/sinatra/rpc/handler/echo.rb,
lib/sinatra/rpc/serializer/base.rb,
lib/sinatra/rpc/serializer/xmlrpc.rb,
lib/sinatra/rpc/handler/introspection.rb
Overview
This extension provides the functionality of an RPC server. The resulting server will handle all POST requests to /RPC2 and dispatch methods to the underlying handler objects. For example, calling the 'myHandler.myMethod' method will actually execute
my_handler.my_method
on the target handler. RPC methods are usually camelcased, so an automatic conversion to and from standard method names with underscores is performed at registration.
Defined Under Namespace
Modules: Fault, Handler, Helpers, Serializer, Utils Classes: NotFound
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.registered(app) ⇒ Object
Callback executed when the app registers this extension module.
Instance Method Summary collapse
-
#add_rpc_handler(namespace = nil, handler) ⇒ Object
Add a new RPC handler object.
-
#register_rpc_fault(fault_name, error_code) ⇒ Object
Generate a new fault class.
Class Method Details
.registered(app) ⇒ Object
Callback executed when the app registers this extension module. Here we set the default property values and register standard error codes and handlers.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/sinatra/rpc.rb', line 86 def self.registered(app) app.helpers Helpers # Initialize the method index app.set(:rpc_method_index, {}) # Register the echo handler class app.add_rpc_handler 'test', Handler::Echo # Register the introspection handler class app.add_rpc_handler 'system', Handler::Introspection.new(app) end |
Instance Method Details
#add_rpc_handler(namespace = nil, handler) ⇒ Object
Add a new RPC handler object. If specified, the namespace is used as a prefix for all the RPC method calls. All the public methods exposed by the handler object will be made available as RPC methods (with a camelcase name).
75 76 77 78 |
# File 'lib/sinatra/rpc.rb', line 75 def add_rpc_handler(namespace = nil, handler) handler = handler.new if Class === handler settings.rpc_method_index.merge! Utils.rpc_methods namespace, handler end |