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

58 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
identity :key, 'Key'
attribute :body
attribute :content_length, 'Content-Length'
attribute :content_type, 'Content-Type'
attribute :etag, ['Etag', 'ETag']
attribute :last_modified, ['Last-Modified', 'LastModified']
attribute :owner
attribute :size, 'Size'
attribute :storage_class, 'StorageClass'
2009-08-02 19:37:54 -04:00
def bucket
@bucket
end
def copy(target_bucket_name, target_object_key)
data = connection.copy_object(bucket.name, @key, target_bucket_name, target_object_key).body
2009-08-30 17:14:11 -04:00
target_bucket = connection.buckets.new(:name => target_bucket_name)
target_object = target_bucket.objects.new(attributes.merge!(:key => target_object_key))
copy_data = {}
for key, value in data
if ['ETag', 'LastModified'].include?(key)
copy_data[key] = value
end
end
2009-08-30 17:14:11 -04:00
target_object.merge_attributes(copy_data)
target_object
end
2009-08-30 17:14:11 -04:00
def destroy
connection.delete_object(bucket.name, @key)
true
end
def save(options = {})
data = connection.put_object(bucket.name, @key, @body, options)
@etag = data.headers['ETag']
true
end
private
def bucket=(new_bucket)
@bucket = new_bucket
end
2009-08-02 19:37:54 -04:00
end
end
end
end