mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
49 lines
1.2 KiB
Ruby
49 lines
1.2 KiB
Ruby
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
|
|
|
|
def reload
|
|
if data = collection.get_raw(identity)
|
|
merge_get_raw_result(data)
|
|
self
|
|
end
|
|
end
|
|
|
|
def merge_get_raw_result(data)
|
|
data.body.each_pair do |key,value|
|
|
if aliased_key = self.class.aliases[key]
|
|
send("#{aliased_key}=", value)
|
|
else
|
|
send("#{key}=", value)
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|