Class: VBox::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/virtualbox/base.rb
Direct Known Subclasses
Appliance, AudioAdapter, BIOSSettings, BandwidthControl, BandwidthGroup, Console, DHCPServer, Directory, Display, EmulatedUSB, Event, EventListener, EventSource, File, Framebuffer, FsObjInfo, Guest, GuestSession, Host, HostNetworkInterface, HostVideoInputDevice, Keyboard, Machine, MachineDebugger, ManagedObjectRef, Medium, MediumFormat, Mouse, NATEngine, NATNetwork, NetworkAdapter, PCIAddress, ParallelPort, PerformanceCollector, PerformanceMetric, Process, Progress, SerialPort, Session, SharedFolder, Snapshot, StorageController, SystemProperties, Token, USBController, USBDevice, USBDeviceFilter, USBDeviceFilters, VFSExplorer, VRDEServer, VRDEServerInfo, VirtualBox, VirtualBoxErrorInfo, VirtualSystemDescription, WebsessionManager
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(obj_ref) ⇒ Base
Returns a new instance of Base.
6
7
8
|
# File 'lib/virtualbox/base.rb', line 6
def initialize(obj_ref)
@ref = obj_ref
end
|
Instance Attribute Details
#ref ⇒ Object
Returns the value of attribute ref.
4
5
6
|
# File 'lib/virtualbox/base.rb', line 4
def ref
@ref
end
|
Class Method Details
.class_name ⇒ Object
30
31
32
|
# File 'lib/virtualbox/base.rb', line 30
def self.class_name
self.name.split('::').last.to_underscore
end
|
.soap_method(method_name, modifier = nil) ⇒ Object
20
21
22
23
24
|
# File 'lib/virtualbox/base.rb', line 20
def self.soap_method(method_name, modifier=nil)
is_acronym_part = self.name.split('::').last.match(/^[A-Z]{2,}/).nil? ? '_' : ''
modifier_part = modifier.nil? ? '' : modifier + '_'
"i#{is_acronym_part}#{class_name}_#{modifier_part}#{method_name}".to_sym
end
|
.vb_attr(name, options = {}) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/virtualbox/base.rb', line 60
def self.vb_attr(name, options={})
force_array = options[:force_array]
force_tag = options[:force_tag]
force_savon_method = options[:force_savon_method]
native_name = force_savon_method || name
define_method(name) do
result = WebService.send_request(soap_method(native_name, 'get'), _this)
process_result(result, force_array)
end
define_method("#{name}=") do |value|
soap_message = {force_tag ? force_tag : native_name => value}
result = WebService.send_request(soap_method(native_name, 'set'), _this.merge(soap_message))
process_result(result)
end if WebService.operations.include?(soap_method(native_name, 'set'))
end
|
.vb_method(name, options = {}) ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/virtualbox/base.rb', line 79
def self.vb_method(name, options={})
force_array = options[:force_array]
define_method(name) do |meth_args = {}|
ensure_hash meth_args
meth_args.referize!
result = WebService.send_request(soap_method(name), _this.merge(meth_args))
process_result(result, force_array)
end
end
|
Instance Method Details
#_this ⇒ Object
10
11
12
13
14
|
# File 'lib/virtualbox/base.rb', line 10
def _this
_this = {}
_this[:_this] = @ref unless @ref.nil?
_this
end
|
#class_name ⇒ Object
34
35
36
|
# File 'lib/virtualbox/base.rb', line 34
def class_name
self.class.class_name
end
|
#ensure_hash(args) ⇒ Object
16
17
18
|
# File 'lib/virtualbox/base.rb', line 16
def ensure_hash(args)
raise ArgumentError, 'Method arguments must be a hash' unless args.is_a?(Hash)
end
|
#process_result(result, force_array = false) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/virtualbox/base.rb', line 38
def process_result(result, force_array=false)
if force_array
return [] if result.nil?
result = result.to_a
vbox_class = result.first.vbox_class
result.map { |item| item.to_vbox_object(vbox_class) }
else
return if result.nil?
if result.is_a?(Array)
result.map { |item| process_result(item) }
elsif result.is_a?(Hash)
result.update(result) { |_, value| process_result(value) }
elsif !!result == result
result
elsif !result.match(/^[0-9a-f]{16}-[0-9a-f]{16}$/).nil?
result.to_vbox_object(result.vbox_class)
else
result.to_num
end
end
end
|
#soap_method(method_name, modifier = nil) ⇒ Object
26
27
28
|
# File 'lib/virtualbox/base.rb', line 26
def soap_method(method_name, modifier=nil)
self.class.soap_method(method_name, modifier)
end
|