lib/virtualbox/storage_controller.rb in virtualbox-0.4.3 vs lib/virtualbox/storage_controller.rb in virtualbox-0.5.0
- old
+ new
@@ -41,28 +41,25 @@
#
class StorageController < AbstractModel
attribute :parent, :readonly => true
attribute :name
attribute :type
- attribute :max_ports, :populate_key => :maxportcount
attribute :ports, :populate_key => :portcount
relationship :devices, AttachedDevice, :dependent => :destroy
class <<self
# Populates a relationship with another model.
#
# **This method typically won't be used except internally.**
#
# @return [Array<StorageController>]
- def populate_relationship(caller, data)
- relation = []
+ def populate_relationship(caller, doc)
+ relation = Proxies::Collection.new(caller)
counter = 0
- loop do
- break unless data["storagecontrollername#{counter}".to_sym]
- nic = new(counter, caller, data)
- relation.push(nic)
+ doc.css("StorageControllers StorageController").each do |sc|
+ relation << new(counter, caller, sc)
counter += 1
end
relation
end
@@ -94,39 +91,14 @@
@index = index
# Setup the index specific attributes
populate_data = {}
- self.class.attributes.each do |name, options|
- key = options[:populate_key] || name
- value = data["storagecontroller#{key}#{index}".to_sym]
- populate_data[key] = value
+ data.attributes.each do |key,value|
+ populate_data[key.downcase.to_sym] = value.to_s
end
- # Make sure to merge in device data so those relationships will be
- # setup properly
- populate_data.merge!(extract_devices(index, data))
-
- populate_attributes(populate_data.merge({
- :parent => caller
- }))
- end
-
- # Extracts related devices for a storage controller.
- #
- # **This method typically won't be used except internally.**
- #
- # @return [Hash]
- def extract_devices(index, data)
- name = data["storagecontrollername#{index}".downcase.to_sym].downcase
-
- device_data = {}
- data.each do |k,v|
- next unless k.to_s =~ /^#{name}-/
-
- device_data[k] = v
- end
-
- device_data
+ populate_attributes(populate_data.merge({:parent => caller}), :ignore_relationships => true)
+ populate_relationship(:devices, data)
end
end
end
\ No newline at end of file