Class: XenApi::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/xenapi/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

Constructor Details

#initialize(client, prefix, sender) ⇒ Dispatcher

Returns a new instance of Dispatcher.

Parameters:

  • client (Client)

    XenApi::Client instance

  • prefix (String)

    Method prefix name

  • sender (Symbol)

    XenApi::Client method to call when prefix method is invoked



28
29
30
31
32
# File 'lib/xenapi/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

Parameters:

  • meth (String, Symbol)

    Method name to be combined with the receivers prefix

  • args (...)

    Method arguments

Returns:

  • (Object)

    XMLRPC response value



44
45
46
# File 'lib/xenapi/xenapi/dispatcher.rb', line 44

def method_missing(meth, *args)
  @client.send(@sender, "#{@prefix}.#{meth}", *args)
end

Instance Method Details

#inspectObject

See Also:

  • Object#inspect


35
36
37
# File 'lib/xenapi/xenapi/dispatcher.rb', line 35

def inspect
  "#<#{self.class} #{@prefix}>"
end