2009-08-02 19:37:54 -04:00
|
|
|
module Fog
|
2009-08-17 21:34:44 -04:00
|
|
|
class Collection < Array
|
2009-08-02 19:37:54 -04:00
|
|
|
|
|
|
|
def initialize(attributes = {})
|
2009-08-04 23:09:08 -04:00
|
|
|
update_attributes(attributes)
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
data = "#<#{self.class.name}"
|
|
|
|
for attribute in (self.instance_variables - ['@connection'])
|
|
|
|
data << " #{attribute}=#{send(attribute[1..-1].to_sym).inspect}"
|
|
|
|
end
|
2009-08-17 21:34:44 -04:00
|
|
|
data << " ["
|
|
|
|
for item in self
|
|
|
|
data << "#{item.inspect},"
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
2009-08-17 21:34:44 -04:00
|
|
|
data.chomp!
|
2009-08-02 19:37:54 -04:00
|
|
|
data << "]>"
|
|
|
|
end
|
|
|
|
|
2009-08-04 23:09:08 -04:00
|
|
|
def update_attributes(attributes = {})
|
|
|
|
for key, value in attributes
|
|
|
|
send(:"#{key}=", value)
|
|
|
|
end
|
2009-08-17 21:34:44 -04:00
|
|
|
self
|
2009-08-04 23:09:08 -04:00
|
|
|
end
|
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def connection=(new_connection)
|
|
|
|
@connection = new_connection
|
|
|
|
end
|
|
|
|
|
|
|
|
def connection
|
|
|
|
@connection
|
|
|
|
end
|
|
|
|
|
2009-08-17 21:34:44 -04:00
|
|
|
def new_record?
|
|
|
|
!defined?(@new_record) || @new_record
|
|
|
|
end
|
|
|
|
|
2009-08-04 13:51:54 -04:00
|
|
|
def remap_attributes(attributes, mapping)
|
|
|
|
for key, value in mapping
|
2009-08-17 21:34:44 -04:00
|
|
|
if attributes.key?(key)
|
2009-08-04 13:51:54 -04:00
|
|
|
attributes[value] = attributes.delete(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
end
|