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
34
35
36
|
# File 'lib/virtualbox/base.rb', line 34
def self.class_name
self.name.split('::').last.to_underscore
end
|
.soap_method(method_name, modifier = nil) ⇒ Object
24
25
26
27
28
|
# File 'lib/virtualbox/base.rb', line 24
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
|
.starts_with_acronym ⇒ Object
20
21
22
|
# File 'lib/virtualbox/base.rb', line 20
def self.starts_with_acronym
define_method(:acronym) {}
end
|
.vb_attr(name, options = {}) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/virtualbox/base.rb', line 64
def self.vb_attr(name, options={})
force_array = options[:force_array]
force_tag = options[:force_tag]
if name.to_s.start_with?('ipv6') || name.to_s.include?('advertise_default_ipv6_route_enabled')
native_name = name.to_s.gsub('ipv6', 'i_pv6').to_sym
elsif name.to_s.include?('_3d_')
native_name = name.to_s.gsub('_3d_', '3_d_').to_sym
elsif name.to_s.include?('_2d_')
native_name = name.to_s.gsub('_2d_', '2_d_').to_sym
else
native_name = name
end
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
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/virtualbox/base.rb', line 90
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
38
39
40
|
# File 'lib/virtualbox/base.rb', line 38
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/virtualbox/base.rb', line 42
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
30
31
32
|
# File 'lib/virtualbox/base.rb', line 30
def soap_method(method_name, modifier=nil)
self.class.soap_method(method_name, modifier)
end
|