1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/vcloud/model.rb

55 lines
1.4 KiB
Ruby
Raw Normal View History

2010-05-16 12:09:25 -04:00
module Fog
module Vcloud
class Model < Fog::Model
#def self.attribute(name, other_names = [])
# super
# class_eval <<-EOS, __FILE__, __LINE__
# def #{name}=(new_#{name})
# @#{name} = new_#{name}
# end
# EOS
#end
def self.inherited(klass)
attributes.each { |attribute| klass.attribute attribute }
klass.instance_variable_set(:@identity, @identity)
klass.instance_variable_set(:@aliases, @aliases)
end
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
attr_accessor :loaded
alias_method :loaded?, :loaded
2010-05-16 12:09:25 -04:00
def reload
if data = collection.get_raw(identity)
merge_get_raw_result(data)
@loaded = true
2010-05-16 12:09:25 -04:00
self
end
end
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|
2010-05-16 12:09:25 -04:00
if aliased_key = self.class.aliases[key]
send("#{aliased_key}=", value)
else
send("#{key}=", value)
end
end
end
end
end
end