2009-08-02 23:37:54 +00:00
|
|
|
module Fog
|
|
|
|
class Model
|
|
|
|
|
2010-06-08 01:22:31 +00:00
|
|
|
extend Fog::Attributes::ClassMethods
|
|
|
|
include Fog::Attributes::InstanceMethods
|
2009-11-21 21:46:46 +00:00
|
|
|
|
2009-12-05 22:53:42 +00:00
|
|
|
attr_accessor :connection
|
|
|
|
|
2009-10-30 06:35:28 +00:00
|
|
|
def collection
|
|
|
|
@collection
|
|
|
|
end
|
|
|
|
|
2009-08-30 21:14:11 +00:00
|
|
|
def initialize(new_attributes = {})
|
|
|
|
merge_attributes(new_attributes)
|
2009-08-02 23:37:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
2010-02-14 22:34:33 +00:00
|
|
|
Thread.current[:formatador] ||= Formatador.new
|
|
|
|
data = "#{Thread.current[:formatador].indentation}<#{self.class.name}"
|
|
|
|
Thread.current[:formatador].indent do
|
|
|
|
unless self.class.attributes.empty?
|
|
|
|
data << "\n#{Thread.current[:formatador].indentation}"
|
|
|
|
data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
|
|
|
|
end
|
2009-08-02 23:37:54 +00:00
|
|
|
end
|
2010-02-16 04:18:52 +00:00
|
|
|
data << "\n#{Thread.current[:formatador].indentation}>"
|
2010-02-14 22:34:33 +00:00
|
|
|
data
|
2009-08-02 23:37:54 +00:00
|
|
|
end
|
|
|
|
|
2009-10-23 17:27:23 +00:00
|
|
|
def reload
|
2010-10-27 23:09:00 +00:00
|
|
|
requires :identity
|
2010-04-27 23:34:04 +00:00
|
|
|
if data = collection.get(identity)
|
|
|
|
new_attributes = data.attributes
|
|
|
|
merge_attributes(new_attributes)
|
2010-05-06 23:41:02 +00:00
|
|
|
self
|
2010-04-27 23:34:04 +00:00
|
|
|
end
|
2009-10-23 17:27:23 +00:00
|
|
|
end
|
|
|
|
|
2010-03-28 01:06:32 +00:00
|
|
|
def to_json
|
|
|
|
attributes.to_json
|
|
|
|
end
|
|
|
|
|
2010-07-22 02:18:34 +00:00
|
|
|
def wait_for(timeout=600, interval=1, &block)
|
2010-05-01 22:08:44 +00:00
|
|
|
reload
|
2010-07-22 02:18:34 +00:00
|
|
|
Fog.wait_for(timeout, interval) do
|
2010-09-16 22:41:19 +00:00
|
|
|
reload or raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} went away.")
|
2010-05-07 16:51:58 +00:00
|
|
|
instance_eval(&block)
|
|
|
|
end
|
2009-12-08 06:23:55 +00:00
|
|
|
end
|
|
|
|
|
2009-08-02 23:37:54 +00:00
|
|
|
private
|
|
|
|
|
2009-10-23 16:42:51 +00:00
|
|
|
def collection=(new_collection)
|
|
|
|
@collection = new_collection
|
|
|
|
end
|
|
|
|
|
2009-08-02 23:37:54 +00:00
|
|
|
end
|
|
|
|
end
|