Skip to content

Commit

Permalink
Added second form for #copy_from and #copy_to
Browse files Browse the repository at this point in the history
Fixes #963
  • Loading branch information
trevorrowe committed Oct 16, 2015
1 parent 467e350 commit 693197a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
Unreleased Changes
------------------

* Feature - Aws::S3 - The `#copy_from` and `#copy_to` methods of `Aws::S3::Object`
now accept the source or target bucket and key as a hash with mixed
options.

```ruby
# old format
obj.copy_from({ bucket: 'source-bucket', key: 'source-key' }, { multipart_copy: true })

# new format
obj.copy_from(bucket: 'source-bucket', key: 'source-key', multipart_copy: true)
```

Passing two hashes is still valid.

See [related GitHub issue #963](https://github.com/aws/aws-sdk-ruby/issues/963).

* Feature - Aws::S3 - `Aws::S3::Client#put_object` now accepts closed files.

See [related GitHub issue #939](https://github.com/aws/aws-sdk-ruby/pull/939).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ def initialize(object, options = {})
end

def copy_from(source, options = {})
apply_options(source, options)
copy_object(source, @object, options)
end


def copy_to(target, options = {})
apply_options(target, options)
copy_object(@object, target, options)
end

Expand Down Expand Up @@ -57,6 +59,16 @@ def copy_target(target)
end
end

def apply_options(source_or_target, options)
if Hash === source_or_target
source_or_target.each do |key, value|
next if key == :bucket
next if key == :key
options[key] = value
end
end
end

end
end
end
28 changes: 28 additions & 0 deletions aws-sdk-resources/spec/services/s3/object/multipart_copy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ module S3
object.copy_from(bucket:'source-bucket', key:'source-key')
end

it 'accept a hash with options merged' do
expect(client).to receive(:copy_object).with({
bucket: 'bucket',
key: 'key',
copy_source: 'source-bucket/source-key',
content_type: 'text/plain',
})
object.copy_from(
bucket: 'source-bucket',
key: 'source-key',
content_type: 'text/plain'
)
end

it 'accepts an S3::Object source' do
expect(client).to receive(:copy_object).with({
bucket: 'bucket',
Expand Down Expand Up @@ -86,6 +100,20 @@ module S3
object.copy_to(bucket:'target-bucket', key:'target-key')
end

it 'accept a hash with options merged' do
expect(client).to receive(:copy_object).with({
bucket: 'target-bucket',
key: 'target-key',
copy_source: 'bucket/key',
content_type: 'text/plain',
})
object.copy_to(
bucket: 'target-bucket',
key: 'target-key',
content_type: 'text/plain'
)
end

it 'accepts an S3::Object source' do
expect(client).to receive(:copy_object).with({
bucket: 'target-bucket',
Expand Down

0 comments on commit 693197a

Please sign in to comment.