Class: XenAPI::Dispatcher
- Inherits:
-
Object
- Object
- XenAPI::Dispatcher
- Defined in:
- lib/xenapi/dispatcher.rb
Instance Method Summary collapse
-
#initialize(proxy, &error_callback) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(proxy, &error_callback) ⇒ Dispatcher
Returns a new instance of Dispatcher.
5 6 7 8 |
# File 'lib/xenapi/dispatcher.rb', line 5 def initialize(proxy, &error_callback) @proxy = adjust_proxy_methods!(proxy) @error_callback = error_callback end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/xenapi/dispatcher.rb', line 10 def method_missing(name, *args) begin response = @proxy.send(name, *args) raise XenAPI::ErrorFactory.create(*response['ErrorDescription']) unless response['Status'] == 'Success' response['Value'] rescue Exception => exc error = XenAPI::ErrorFactory.wrap(exc) if @error_callback @error_callback.call(error) do |new_session| prefix = @proxy.prefix.delete(".").to_sym dispatcher = new_session.send(prefix) dispatcher.send(name, *args) end else raise error end end end |