diff --git a/lib/fog/aws/models/s3/bucket.rb b/lib/fog/aws/models/s3/bucket.rb index 90821dba2..be0a05537 100644 --- a/lib/fog/aws/models/s3/bucket.rb +++ b/lib/fog/aws/models/s3/bucket.rb @@ -8,10 +8,6 @@ module Fog attribute :name, 'Name' attribute :owner - def buckets - @buckets - end - def destroy connection.delete_bucket(@name) true @@ -24,6 +20,10 @@ module Fog data.body['LocationConstraint'] end + def location=(new_location) + @location = new_location + end + def objects @objects ||= begin Fog::AWS::S3::Objects.new( @@ -44,7 +44,7 @@ module Fog end def reload - new_attributes = buckets.get(@name).attributes + new_attributes = collection.get(@name).attributes merge_attributes(new_attributes) end @@ -57,12 +57,6 @@ module Fog true end - private - - def buckets=(new_buckets) - @buckets = new_buckets - end - end end diff --git a/lib/fog/aws/models/s3/buckets.rb b/lib/fog/aws/models/s3/buckets.rb index f86c78e13..a262a59ae 100644 --- a/lib/fog/aws/models/s3/buckets.rb +++ b/lib/fog/aws/models/s3/buckets.rb @@ -14,7 +14,7 @@ module Fog buckets = Fog::AWS::S3::Buckets.new(:connection => connection) data['Buckets'].each do |bucket| buckets << Fog::AWS::S3::Bucket.new({ - :buckets => buckets, + :collection => buckets, :connection => connection, :owner => owner }.merge!(bucket)) @@ -34,7 +34,7 @@ module Fog }) data = connection.get_bucket(name, options).body bucket = Fog::AWS::S3::Bucket.new({ - :buckets => self, + :collection => self, :connection => connection, :name => data['Name'] }) @@ -50,7 +50,7 @@ module Fog bucket.objects << Fog::AWS::S3::Object.new({ :bucket => bucket, :connection => connection, - :objects => self, + :collection => bucket.objects, :owner => owner }.merge!(object)) end @@ -62,8 +62,8 @@ module Fog def new(attributes = {}) Fog::AWS::S3::Bucket.new( attributes.merge!( - :connection => connection, - :buckets => self + :collection => self, + :connection => connection ) ) end diff --git a/lib/fog/aws/models/s3/object.rb b/lib/fog/aws/models/s3/object.rb index dd640687b..7841bcc63 100644 --- a/lib/fog/aws/models/s3/object.rb +++ b/lib/fog/aws/models/s3/object.rb @@ -37,12 +37,8 @@ module Fog true end - def objects - @objects - end - def reload - new_attributes = objects.get(@key).attributes + new_attributes = collection.get(@key).attributes merge_attributes(new_attributes) end @@ -58,10 +54,6 @@ module Fog @bucket = new_bucket end - def objects=(new_objects) - @objects = new_objects - end - end end diff --git a/lib/fog/aws/models/s3/objects.rb b/lib/fog/aws/models/s3/objects.rb index 17842485f..5cf69756b 100644 --- a/lib/fog/aws/models/s3/objects.rb +++ b/lib/fog/aws/models/s3/objects.rb @@ -11,7 +11,7 @@ module Fog attribute :prefix, 'Prefix' def all(options = {}) - bucket.buckets.get( + bucket.collection.get( bucket.name, options.reject {|key, value| !['delimiter', 'marker', 'max-keys', 'prefix'].include?(key)} ).objects @@ -40,8 +40,8 @@ module Fog end object = Fog::AWS::S3::Object.new({ :bucket => bucket, - :connection => connection, - :objects => self + :collection => self, + :connection => connection }.merge!(object_data)) object rescue Fog::Errors::NotFound @@ -64,8 +64,8 @@ module Fog end object = Fog::AWS::S3::Object.new({ :bucket => bucket, - :connection => connection, - :objects => self + :collection => self, + :connection => connection }.merge!(object_data)) object rescue Fog::Errors::NotFound @@ -75,8 +75,8 @@ module Fog def new(attributes = {}) Fog::AWS::S3::Object.new({ :bucket => bucket, - :connection => connection, - :objects => self + :collection => self, + :connection => connection }.merge!(attributes)) end diff --git a/lib/fog/model.rb b/lib/fog/model.rb index f95c0feee..eb67bb28d 100644 --- a/lib/fog/model.rb +++ b/lib/fog/model.rb @@ -39,6 +39,10 @@ module Fog attributes end + def collection + @collection + end + def merge_attributes(new_attributes = {}) for key, value in new_attributes if aliased_key = self.class.aliases[key] @@ -52,6 +56,10 @@ module Fog private + def collection=(new_collection) + @collection = new_collection + end + def connection=(new_connection) @connection = new_connection end diff --git a/spec/aws/models/s3/bucket_spec.rb b/spec/aws/models/s3/bucket_spec.rb index 1e0ed5123..69b161cc7 100644 --- a/spec/aws/models/s3/bucket_spec.rb +++ b/spec/aws/models/s3/bucket_spec.rb @@ -16,15 +16,15 @@ describe 'Fog::AWS::S3::Bucket' do end - describe "#buckets" do + describe "#collection" do it "should return a Fog::AWS::S3::Buckets" do - s3.buckets.new.buckets.should be_a(Fog::AWS::S3::Buckets) + s3.buckets.new.collection.should be_a(Fog::AWS::S3::Buckets) end it "should be the buckets the bucket is related to" do buckets = s3.buckets - buckets.new.buckets.should == buckets + buckets.new.collection.should == buckets end end @@ -115,12 +115,12 @@ describe 'Fog::AWS::S3::Bucket' do end it "should not exist in buckets before save" do - @bucket.buckets.all.map {|bucket| bucket.name}.include?(@bucket.name).should be_false + s3.buckets.all.map {|bucket| bucket.name}.include?(@bucket.name).should be_false end it "should exist in buckets after save" do @bucket.save - @bucket.buckets.all.map {|bucket| bucket.name}.include?(@bucket.name).should be_true + s3.buckets.all.map {|bucket| bucket.name}.include?(@bucket.name).should be_true @bucket.destroy end