mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
work on simplifying s3 collections
This commit is contained in:
parent
26b556975c
commit
d192ee0e79
3 changed files with 11 additions and 26 deletions
|
@ -30,10 +30,7 @@ module Fog
|
|||
|
||||
def get(name, options = {})
|
||||
remap_attributes(options, {
|
||||
:is_truncated => 'IsTruncated',
|
||||
:marker => 'Marker',
|
||||
:max_keys => 'MaxKeys',
|
||||
:prefix => 'Prefix'
|
||||
:max_keys => 'max-keys',
|
||||
})
|
||||
data = connection.get_bucket(name, options).body
|
||||
bucket = Fog::AWS::S3::Bucket.new({
|
||||
|
@ -41,13 +38,13 @@ module Fog
|
|||
:connection => connection,
|
||||
:name => data['Name']
|
||||
})
|
||||
objects_data = {}
|
||||
options = {}
|
||||
for key, value in data
|
||||
if ['IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
|
||||
objects_data[key] = value
|
||||
if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
|
||||
options[key] = value
|
||||
end
|
||||
end
|
||||
bucket.objects.merge_attributes(objects_data)
|
||||
bucket.objects.merge_attributes(:options => options)
|
||||
data['Contents'].each do |object|
|
||||
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
|
||||
bucket.objects << Fog::AWS::S3::Object.new({
|
||||
|
|
|
@ -4,14 +4,11 @@ module Fog
|
|||
|
||||
class Objects < Fog::Collection
|
||||
|
||||
attribute :is_truncated, 'IsTruncated'
|
||||
attribute :marker, 'Marker'
|
||||
attribute :max_keys, 'MaxKeys'
|
||||
attribute :prefix, 'Prefix'
|
||||
attribute :options
|
||||
|
||||
def all(options = {})
|
||||
merge_attributes(options)
|
||||
bucket.buckets.get(bucket.name, attributes).objects
|
||||
merge_attributes(:options => options)
|
||||
bucket.buckets.get(bucket.name, @options).objects
|
||||
end
|
||||
|
||||
def bucket
|
||||
|
@ -74,7 +71,7 @@ module Fog
|
|||
end
|
||||
|
||||
def reload
|
||||
all
|
||||
all(@options)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -9,9 +9,9 @@ describe 'Fog::AWS::S3::Buckets' do
|
|||
end
|
||||
|
||||
it "should include persisted buckets" do
|
||||
@bucket = s3.buckets.create(:name => 'fogbucketname')
|
||||
bucket = s3.buckets.create(:name => 'fogbucketname')
|
||||
s3.buckets.all.map {|bucket| bucket.name}.should include('fogbucketname')
|
||||
@bucket.destroy
|
||||
bucket.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -45,15 +45,6 @@ describe 'Fog::AWS::S3::Buckets' do
|
|||
bucket.destroy
|
||||
end
|
||||
|
||||
it "should return memoized bucket on subsequent gets" do
|
||||
bucket = s3.buckets.create(:name => 'fogbucketname')
|
||||
get1 = s3.buckets.get('fogbucketname')
|
||||
s3.should_not_receive(:get_bucket)
|
||||
get2 = s3.buckets.get('fogbucketname')
|
||||
get1.attributes.should == get2.attributes
|
||||
bucket.destroy
|
||||
end
|
||||
|
||||
it "should return nil if no matching bucket exists" do
|
||||
s3.buckets.get('fogbucketname').should be_nil
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue