fog--fog/lib/fog/model.rb

47 lines
884 B
Ruby
Raw Normal View History

2009-08-02 23:37:54 +00:00
module Fog
class Model
def initialize(attributes = {})
update_attributes(attributes)
2009-08-02 23:37:54 +00: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
data << ">"
end
def update_attributes(attributes = {})
for key, value in attributes
send(:"#{key}=", value)
end
self
end
2009-08-02 23:37:54 +00:00
private
def connection=(new_connection)
@connection = new_connection
end
def connection
@connection
end
def new_record?
!defined?(@new_record) || @new_record
end
2009-08-04 17:51:54 +00:00
def remap_attributes(attributes, mapping)
for key, value in mapping
2009-08-18 01:07:46 +00:00
if mapping[key]
2009-08-04 17:51:54 +00:00
attributes[value] = attributes.delete(key)
end
end
end
2009-08-02 23:37:54 +00:00
end
end