Class: XenApi::Dispatcher
- Inherits:
-
Object
- Object
- XenApi::Dispatcher
- Defined in:
- lib/xenapi/dispatcher.rb
Overview
This class helps to provide XMLRPC method dispatching.
Calls made to the top level XenApi::Client
instance will generate instances of this class to provide scoping of methods by their prefix. All Xen API method calls are two level, the first level specifies a namespace or prefix for the second level method call. Taking VM.start
as an example, VM
is the namespace prefix and start
is the method name.
Calling Xen API XMLRPC methods therefore consists of first creating a Dispatcher
instance with the prefix name and then calling a method on the Dispatcher
instance to create the XMLRPC method name to be called by the XenApi::Client
instance.
client = XenApi::Client.new('http://xenapi.test/')
client.VM #=> Dispatcher instance for 'VM'
client.VM.start() #=> Performs XMLRPC 'VM.start' call
Instance Method Summary collapse
-
#initialize(client, prefix, sender) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #inspect ⇒ Object
-
#method_missing(meth, *args) ⇒ Object
Calls a method on
XenApi::Client
to perform the XMLRPC method.
Constructor Details
#initialize(client, prefix, sender) ⇒ Dispatcher
Returns a new instance of Dispatcher.
28 29 30 31 32 |
# File 'lib/xenapi/dispatcher.rb', line 28 def initialize(client, prefix, sender) @client = client @prefix = prefix @sender = sender end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
Calls a method on XenApi::Client
to perform the XMLRPC method
44 45 46 |
# File 'lib/xenapi/dispatcher.rb', line 44 def method_missing(meth, *args) @client.send(@sender, "#{@prefix}.#{meth}", *args) end |
Instance Method Details
#inspect ⇒ Object
35 36 37 |
# File 'lib/xenapi/dispatcher.rb', line 35 def inspect "#<#{self.class} #{@prefix}>" end |