Class: Fog::Vcloud::Model

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/vcloud/model.rb

Instance Attribute Summary

Attributes inherited from Model

#connection

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#collection, #initialize, #inspect, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires

Constructor Details

This class inherits a constructor from Fog::Model

Class Method Details

.delete_attribute(name) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/fog/vcloud/model.rb', line 20

def self.delete_attribute(name)
  if @attributes.reject! { |item| item == name }
    class_eval <<-EOS,__FILE__,__LINE__
      undef_method :#{name}
      undef_method :#{name}=
    EOS
    aliases.reject! { |key, value| value == name || key == name }
  end
end

.inherited(klass) ⇒ Object

def self.attribute(name, other_names = [])

super
class_eval <<-EOS, __FILE__, __LINE__
  def #{name}=(new_#{name})
    @#{name} = new_#{name}
  end
EOS

end



14
15
16
17
18
# File 'lib/fog/vcloud/model.rb', line 14

def self.inherited(klass)
  attributes.each { |attribute| klass.attribute attribute }
  klass.instance_variable_set(:@identity, @identity)
  klass.instance_variable_set(:@aliases, @aliases)
end

Instance Method Details

#merge_get_raw_result(data) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/vcloud/model.rb', line 37

def merge_get_raw_result(data)
  #data.body.each_pair do |key,value|
  (data.respond_to?(:body) ? data.body : data).each_pair do |key,value|
    if aliased_key = self.class.aliases[key]
      send("#{aliased_key}=", value)
    else
      send("#{key}=", value)
    end
  end
end

#reloadObject



30
31
32
33
34
35
# File 'lib/fog/vcloud/model.rb', line 30

def reload
  if data = collection.get_raw(identity)
    merge_get_raw_result(data)
    self
  end
end