Skip to content

Commit

Permalink
Accept an options hash to Bucket#save
Browse files Browse the repository at this point in the history
You can now pass an options hash to Bucket#save and it will pass the
options through to Connection#request. This is useful for setting
headers (like :x_amz_acl) on the bucket. Backwards compatibility is
maintained from the previous version that just accepted a location
parameter.
  • Loading branch information
bbrowning committed Sep 24, 2010
1 parent eaaa5dd commit b8dd1d2
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/s3/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ def destroy(force = false)
end
end

# Saves the newly built bucket. Optionally you can pass location
# of the bucket (<tt>:eu</tt> or <tt>:us</tt>)
def save(location = nil)
create_bucket_configuration(location)
# Saves the newly built bucket.
#
# ==== Options
# * <tt>:location</tt> - location of the bucket
# (<tt>:eu</tt> or <tt>us</tt>)
# * Any other options are passed through to
# Connection#request
def save(options = {})
unless options.is_a?(Hash)
options = {:location => options}
end
create_bucket_configuration(options)
true
end

Expand Down Expand Up @@ -117,9 +125,9 @@ def bucket_headers(options = {})
end
end

def create_bucket_configuration(location = nil)
location = location.to_s.upcase if location
options = { :headers => {} }
def create_bucket_configuration(options = {})
location = options[:location].to_s.upcase if options[:location]
options[:headers] ||= {}
if location and location != "US"
options[:body] = "<CreateBucketConfiguration><LocationConstraint>#{location}</LocationConstraint></CreateBucketConfiguration>"
options[:headers][:content_type] = "application/xml"
Expand Down

0 comments on commit b8dd1d2

Please sign in to comment.