Class: Sinatra::RPC::Handler::Introspection

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/rpc/handler/introspection.rb

Overview

The instrospection handler can be used to display metadata about the RPC server. It adds the listMethods, methodSignature and methodHelp RPC methods to the system namespace.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Introspection

The initializer requires a reference the current application.

Parameters:

  • app (Sinatra::Base)

    the current Sinatra application



12
13
14
# File 'lib/sinatra/rpc/handler/introspection.rb', line 12

def initialize(app)
  @app = app
end

Instance Method Details

#list_methodsArray

List the available methods.

Returns:

  • (Array)

    the array of methods exposed by this RPC server.



18
19
20
# File 'lib/sinatra/rpc/handler/introspection.rb', line 18

def list_methods
  index.keys.sort
end

#method_help(method_name) ⇒ String

Return a help for the given method.

Parameters:

  • method_name (String)

    the method name in the form handler.methodName.

Returns:

  • (String)

    a description of the method.



32
33
34
# File 'lib/sinatra/rpc/handler/introspection.rb', line 32

def method_help(method_name)
  index[method_name][:help]
end

#method_signature(method_name) ⇒ Array

Return the signature of the given method.

Parameters:

  • method_name (String)

    the method name in the form handler.methodName.

Returns:

  • (Array)

    a list of the form [return, param1, param2, ...].



25
26
27
# File 'lib/sinatra/rpc/handler/introspection.rb', line 25

def method_signature(method_name)
  index[method_name][:signature]
end