Class: XenApi::AsyncDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/xenapi/xenapi/async_dispatcher.rb

Overview

This class helps to provide the ability for the XenApi::Client to accept async method calls. Calls are similar to synchronous method calls except that the names are prefixed with ‘Async’.

client = XenApi::Client.new('http://xenapi.test/')
client.async            #=> AsyncDispatcher instance
client.async.VM         #=> Dispatcher instance for 'Async.VM'
client.async.VM.start() #=> Performs XMLRPC 'Async.VM.start' call

further calls on instances of this object will create a Dispatcher instance which then handle actual method calls.

Instance Method Summary collapse

Constructor Details

#initialize(client, sender) ⇒ AsyncDispatcher

Returns a new instance of AsyncDispatcher.

Parameters:

  • client (Client)

    XenApi::Client instance

  • sender (Symbol)

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



17
18
19
20
# File 'lib/xenapi/xenapi/async_dispatcher.rb', line 17

def initialize(client, sender)
  @client = client
  @sender = sender
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *_args) ⇒ Dispatcher

Create a new Dispatcher instance to handle the Async.meth prefix.

Parameters:

  • meth (String, Symbol)

    Method prefix name

  • args (...)

    Method arguments

Returns:

  • (Dispatcher)

    dispatcher instance to handle the Async.meth prefix



32
33
34
# File 'lib/xenapi/xenapi/async_dispatcher.rb', line 32

def method_missing(meth, *_args)
  Dispatcher.new(@client, "Async.#{meth}", @sender)
end

Instance Method Details

#inspectObject

See Also:

  • Object#inspect


23
24
25
# File 'lib/xenapi/xenapi/async_dispatcher.rb', line 23

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