diff --git a/lib/fog/aws/models/s3/bucket.rb b/lib/fog/aws/models/s3/bucket.rb index be0a05537..ad3aa2e2d 100644 --- a/lib/fog/aws/models/s3/bucket.rb +++ b/lib/fog/aws/models/s3/bucket.rb @@ -4,8 +4,9 @@ module Fog class Bucket < Fog::Model + identity :name, 'Name' + attribute :creation_date, 'CreationDate' - attribute :name, 'Name' attribute :owner def destroy @@ -43,11 +44,6 @@ module Fog @payer = new_payer end - def reload - new_attributes = collection.get(@name).attributes - merge_attributes(new_attributes) - end - def save options = {} if @location diff --git a/lib/fog/aws/models/s3/object.rb b/lib/fog/aws/models/s3/object.rb index 7841bcc63..e632c4ee8 100644 --- a/lib/fog/aws/models/s3/object.rb +++ b/lib/fog/aws/models/s3/object.rb @@ -4,11 +4,12 @@ module Fog class Object < Fog::Model + identity :key, 'Key' + attribute :body attribute :content_length, 'Content-Length' attribute :content_type, 'Content-Type' attribute :etag, ['Etag', 'ETag'] - attribute :key, 'Key' attribute :last_modified, ['Last-Modified', 'LastModified'] attribute :owner attribute :size, 'Size' @@ -37,11 +38,6 @@ module Fog true end - def reload - new_attributes = collection.get(@key).attributes - merge_attributes(new_attributes) - end - def save(options = {}) data = connection.put_object(bucket.name, @key, @body, options) @etag = data.headers['ETag'] diff --git a/lib/fog/model.rb b/lib/fog/model.rb index eb67bb28d..c29931b3a 100644 --- a/lib/fog/model.rb +++ b/lib/fog/model.rb @@ -11,6 +11,11 @@ module Fog end end + def self.identity(name, other_names = []) + @identity = name + self.attribute(name, other_names) + end + def self.aliases @aliases ||= {} end @@ -19,6 +24,10 @@ module Fog @attributes ||= [] end + def identity + send(self.class.instance_variable_get('@identity')) + end + def initialize(new_attributes = {}) merge_attributes(new_attributes) end @@ -54,6 +63,11 @@ module Fog self end + def reload + new_attributes = collection.get(identity).attributes + merge_attributes(new_attributes) + end + private def collection=(new_collection)