Class: Fog::Compute::VcloudDirector::Model

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/vcloud_director/compute.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

#initialize(attrs = {}) ⇒ Model

Returns a new instance of Model.



255
256
257
258
259
260
261
262
# File 'lib/fog/vcloud_director/compute.rb', line 255

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

#inspectObject



287
288
289
290
291
292
# File 'lib/fog/vcloud_director/compute.rb', line 287

def inspect
  @inspecting = true
  out = super
  @inspecting = false
  out
end

#lazy_load_attrsObject



264
265
266
# File 'lib/fog/vcloud_director/compute.rb', line 264

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?



279
280
281
282
283
284
285
# File 'lib/fog/vcloud_director/compute.rb', line 279

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



268
269
270
271
272
273
274
275
# File 'lib/fog/vcloud_director/compute.rb', line 268

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