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/aws/models/s3/object.rb

67 lines
1.5 KiB
Ruby
Raw Normal View History

2009-08-02 19:37:54 -04:00
module Fog
module AWS
class S3
class Object < Fog::Model
2009-08-14 12:19:40 -04:00
attr_accessor :body,
:content_length,
:content_type,
2009-08-14 12:19:40 -04:00
:etag,
:key,
:last_modified,
:owner,
:size,
:storage_class
2009-08-02 19:37:54 -04:00
2009-08-04 13:51:54 -04:00
def initialize(attributes = {})
remap_attributes(attributes, {
'Content-Length' => :content_length,
'ETag' => :etag,
'Key' => :key,
'LastModified' => :last_modified,
'Last-Modified' => :last_modified,
'Size' => :size,
'StorageClass' => :storage_class
2009-08-04 13:51:54 -04:00
})
super
end
def copy(target_bucket_name, target_object_key)
2009-08-17 20:21:43 -04:00
data = connection.copy_object(bucket.name, key, target_bucket_name, target_object_key).body
copy = self.dup
copy_data = {}
for key, value in data
if ['ETag', 'LastModified'].include?(key)
copy_data[key] = value
end
end
copy.update_attributes(copy_data)
copy
end
def delete
connection.delete_object(bucket, key)
end
def save(options = {})
2009-08-17 20:21:43 -04:00
data = connection.put_object(bucket.name, key, body, options)
@etag = data.headers['ETag']
end
private
def bucket=(new_bucket)
@bucket = new_bucket
end
def bucket
@bucket
end
2009-08-02 19:37:54 -04:00
end
end
end
end