1
0
Fork 0
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:
Wesley Beary 2009-09-21 11:40:16 -07:00
parent 26b556975c
commit d192ee0e79
3 changed files with 11 additions and 26 deletions

View file

@ -30,10 +30,7 @@ module Fog
def get(name, options = {}) def get(name, options = {})
remap_attributes(options, { remap_attributes(options, {
:is_truncated => 'IsTruncated', :max_keys => 'max-keys',
:marker => 'Marker',
:max_keys => 'MaxKeys',
:prefix => 'Prefix'
}) })
data = connection.get_bucket(name, options).body data = connection.get_bucket(name, options).body
bucket = Fog::AWS::S3::Bucket.new({ bucket = Fog::AWS::S3::Bucket.new({
@ -41,13 +38,13 @@ module Fog
:connection => connection, :connection => connection,
:name => data['Name'] :name => data['Name']
}) })
objects_data = {} options = {}
for key, value in data for key, value in data
if ['IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key) if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
objects_data[key] = value options[key] = value
end end
end end
bucket.objects.merge_attributes(objects_data) bucket.objects.merge_attributes(:options => options)
data['Contents'].each do |object| data['Contents'].each do |object|
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection)) owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
bucket.objects << Fog::AWS::S3::Object.new({ bucket.objects << Fog::AWS::S3::Object.new({

View file

@ -4,14 +4,11 @@ module Fog
class Objects < Fog::Collection class Objects < Fog::Collection
attribute :is_truncated, 'IsTruncated' attribute :options
attribute :marker, 'Marker'
attribute :max_keys, 'MaxKeys'
attribute :prefix, 'Prefix'
def all(options = {}) def all(options = {})
merge_attributes(options) merge_attributes(:options => options)
bucket.buckets.get(bucket.name, attributes).objects bucket.buckets.get(bucket.name, @options).objects
end end
def bucket def bucket
@ -74,7 +71,7 @@ module Fog
end end
def reload def reload
all all(@options)
end end
private private

View file

@ -9,9 +9,9 @@ describe 'Fog::AWS::S3::Buckets' do
end end
it "should include persisted buckets" do 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') s3.buckets.all.map {|bucket| bucket.name}.should include('fogbucketname')
@bucket.destroy bucket.destroy
end end
end end
@ -45,15 +45,6 @@ describe 'Fog::AWS::S3::Buckets' do
bucket.destroy bucket.destroy
end 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 it "should return nil if no matching bucket exists" do
s3.buckets.get('fogbucketname').should be_nil s3.buckets.get('fogbucketname').should be_nil
end end