Class: VMware::DataObject
- Inherits:
-
Object
- Object
- VMware::DataObject
- Defined in:
- lib/vmware/objects/data_object.rb
Overview
Wrapper for data object instances used to enumerate their properties.
Class Method Summary collapse
-
.dump(obj) ⇒ Object
Dump a data object to a string.
- .is_base_class(val) ⇒ Object
-
.soap_to_data_object(val) ⇒ Object
Convert a VMware SOAP object to a data_object wrapper or basic ruby object.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Return a specific property.
-
#initialize(values) ⇒ DataObject
constructor
A new instance of DataObject.
-
#properties(prop_list = []) ⇒ Object
Retrieve all of the properties from the object as a hash.
- #soap_type ⇒ Object
Constructor Details
permalink #initialize(values) ⇒ DataObject
Returns a new instance of DataObject.
7 8 9 10 11 12 |
# File 'lib/vmware/objects/data_object.rb', line 7 def initialize(values) @values = values # We cache properties for more efficient access. @cached_properties = nil end |
Class Method Details
permalink .dump(obj) ⇒ Object
Dump a data object to a string.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vmware/objects/data_object.rb', line 56 def self.dump(obj) if self.is_base_class(obj) obj elsif obj.is_a? Array items = obj.collect {|o| self.dump(o) } "[#{items.join(', ')}]" else s = [] obj.properties.each {|k,v| s << "#{k} => #{self.dump(v)}" } "{#{s.join(', ')}}" end end |
permalink .is_base_class(val) ⇒ Object
[View source]
69 70 71 |
# File 'lib/vmware/objects/data_object.rb', line 69 def self.is_base_class(val) val.nil? or val.is_a? String or val.is_a? TrueClass or val.is_a? FalseClass or val.is_a? Numeric or val.is_a? DateTime end |
permalink .soap_to_data_object(val) ⇒ Object
Convert a VMware SOAP object to a data_object wrapper or basic ruby object.
43 44 45 46 47 48 49 50 51 |
# File 'lib/vmware/objects/data_object.rb', line 43 def self.soap_to_data_object(val) if self.is_base_class(val) return val elsif val.is_a? Array return val.collect {|v| self.soap_to_data_object(v) } else return VMware::DataObject.new(val) end end |
Instance Method Details
permalink #[](key) ⇒ Object
Return a specific property.
35 36 37 38 |
# File 'lib/vmware/objects/data_object.rb', line 35 def [](key) p = properties p[key.to_s] end |
permalink #properties(prop_list = []) ⇒ Object
Retrieve all of the properties from the object as a hash.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vmware/objects/data_object.rb', line 17 def properties(prop_list = []) return @cached_properties if @cached_properties prop_hash = {} @values.instance_variables.each do |var| val = @values.instance_eval(var) prop_hash[var.gsub(/^@/, "")] = VMware::DataObject::soap_to_data_object(val) end @cached_properties = prop_hash end |
permalink #soap_type ⇒ Object
[View source]
28 29 30 |
# File 'lib/vmware/objects/data_object.rb', line 28 def soap_type @values.class.to_s end |