Method: RightAws::S3::Key#copy
- Defined in:
- lib/s3/right_s3.rb
#copy(new_key_or_name) ⇒ Object
Create an object copy. Returns a destination RightAws::S3::Key instance.
# Key instance as destination
key1 = RightAws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<RightAws::S3::Key:0xb7b1e240 ... >
key2 = RightAws::S3::Key.create(bucket, 'logs/today/2.log') #=> #<RightAws::S3::Key:0xb7b5e240 ... >
key1.put('Olala!') #=> true
key1.copy(key2) #=> #<RightAws::S3::Key:0xb7b5e240 ... >
key1.exists? #=> true
key2.exists? #=> true
puts key2.data #=> 'Olala!'
# String as destination
key = RightAws::S3::Key.create(bucket, 'logs/today/777.log') #=> #<RightAws::S3::Key:0xb7b1e240 ... >
key.put('Olala!') #=> true
new_key = key.copy('logs/today/888.log') #=> #<RightAws::S3::Key:0xb7b5e240 ... >
key.exists? #=> true
new_key.exists? #=> true
522 523 524 525 526 |
# File 'lib/s3/right_s3.rb', line 522 def copy(new_key_or_name) new_key_or_name = Key.create(@bucket, new_key_or_name.to_s) unless new_key_or_name.is_a?(Key) @bucket.s3.interface.copy(@bucket.name, @name, new_key_or_name.bucket.name, new_key_or_name.name) new_key_or_name end |