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/collection.rb

52 lines
1,011 B
Ruby
Raw Normal View History

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 = {})
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
def update_attributes(attributes = {})
for key, value in attributes
send(:"#{key}=", value)
end
2009-08-17 21:34:44 -04:00
self
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