Class: Fog::Compute::VcloudDirector::Model
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::VcloudDirector::Model
- Defined in:
- lib/fog/vcloud_director/compute.rb
Direct Known Subclasses
Catalog, CatalogItem, CustomField, Disk, Media, Network, Organization, Tag, TemplateVm, Vapp, VappTemplate, Vdc, Vm, VmCustomization, VmNetwork
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Model
constructor
A new instance of Model.
- #inspect ⇒ Object
- #lazy_load_attrs ⇒ Object
-
#make_attr_loaded_method(attr) ⇒ Object
it adds an attr_loaded? method to know if the value has been loaded yet or not: ie description_loaded?.
- #make_lazy_load_method(attr) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Model
Returns a new instance of Model.
273 274 275 276 277 278 279 280 |
# File 'lib/fog/vcloud_director/compute.rb', line 273 def initialize(attrs={}) super(attrs) lazy_load_attrs.each do |attr| attributes[attr]= NonLoaded if attributes[attr].nil? make_lazy_load_method(attr) end self.class.attributes.each {|attr| make_attr_loaded_method(attr)} end |
Instance Method Details
#inspect ⇒ Object
305 306 307 308 309 310 |
# File 'lib/fog/vcloud_director/compute.rb', line 305 def inspect @inspecting = true out = super @inspecting = false out end |
#lazy_load_attrs ⇒ Object
282 283 284 |
# File 'lib/fog/vcloud_director/compute.rb', line 282 def lazy_load_attrs @lazy_load_attrs ||= self.class.attributes - attributes.keys end |
#make_attr_loaded_method(attr) ⇒ Object
it adds an attr_loaded? method to know if the value has been loaded yet or not: ie description_loaded?
297 298 299 300 301 302 303 |
# File 'lib/fog/vcloud_director/compute.rb', line 297 def make_attr_loaded_method(attr) self.class.instance_eval do define_method("#{attr}_loaded?") do attributes[attr] != NonLoaded end end end |
#make_lazy_load_method(attr) ⇒ Object
286 287 288 289 290 291 292 293 |
# File 'lib/fog/vcloud_director/compute.rb', line 286 def make_lazy_load_method(attr) self.class.instance_eval do define_method(attr) do reload if attributes[attr] == NonLoaded and !@inspecting attributes[attr] end end end |