Class: VirtualBox::COM::Util
- Inherits:
-
Object
- Object
- VirtualBox::COM::Util
- Defined in:
- lib/virtualbox/com/util.rb
Class Method Summary collapse
-
.load_interface(interface) ⇒ Object
This loads the interface with the given name and returns it.
-
.loaded_interfaces ⇒ Object
This keeps a hash of all the loaded interface classes.
- .set_interface_version(version) ⇒ Object
-
.version ⇒ Object
Returns the current version.
-
.version_const ⇒ Object
Returns a namespace representation for a version.
-
.versioned_interface(interface) ⇒ Object
Gets an interface within the current version namespace.
Class Method Details
.load_interface(interface) ⇒ Object
This loads the interface with the given name and returns it. This is different than ‘versioned_interface` since this will not cache any results.
24 25 26 27 28 29 30 31 |
# File 'lib/virtualbox/com/util.rb', line 24 def load_interface(interface) # This require will only run once. If we repeat it, it is not # loaded again require "virtualbox/com/interface/#{@__version}/#{interface}" # Find the module based on the version and name and return it Object.module_eval("::VirtualBox::COM::Interface::#{version_const}::#{interface}") end |
.loaded_interfaces ⇒ Object
This keeps a hash of all the loaded interface classes. Example:
loaded_interfaces[:VirtualBox]
This will return either nil or the class representing this interface.
12 13 14 |
# File 'lib/virtualbox/com/util.rb', line 12 def loaded_interfaces @loaded_interfaces ||= {} end |
.set_interface_version(version) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/virtualbox/com/util.rb', line 43 def set_interface_version(version) # Set the new version @__version = version # Clear the loaded interface cache to force each interface # to be reloaded loaded_interfaces.clear end |
.version ⇒ Object
Returns the current version
34 35 36 |
# File 'lib/virtualbox/com/util.rb', line 34 def version @__version end |
.version_const ⇒ Object
Returns a namespace representation for a version.
39 40 41 |
# File 'lib/virtualbox/com/util.rb', line 39 def version_const "Version_" + @__version.upcase.gsub(".", "_") end |
.versioned_interface(interface) ⇒ Object
Gets an interface within the current version namespace.
17 18 19 |
# File 'lib/virtualbox/com/util.rb', line 17 def versioned_interface(interface) loaded_interfaces[interface] ||= load_interface(interface) end |