mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
collections should be arrays, and should not memoize stuff
This commit is contained in:
parent
e3326e4261
commit
7f57619dd9
7 changed files with 16 additions and 25 deletions
|
@ -19,7 +19,6 @@ module Fog
|
|||
|
||||
def destroy
|
||||
connection.delete_bucket(@name)
|
||||
buckets.delete(name)
|
||||
true
|
||||
rescue Fog::Errors::NotFound
|
||||
false
|
||||
|
@ -60,7 +59,6 @@ module Fog
|
|||
options['LocationConstraint'] = @location
|
||||
end
|
||||
connection.put_bucket(@name, options)
|
||||
buckets[name] = self
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -11,15 +11,15 @@ module Fog
|
|||
def all
|
||||
data = connection.get_service.body
|
||||
owner = Fog::AWS::S3::Owner.new(data.delete('Owner').merge!(:connection => connection))
|
||||
self.delete_if {true}
|
||||
buckets = Fog::AWS::S3::Buckets.new(:connection => connection)
|
||||
data['Buckets'].each do |bucket|
|
||||
self[bucket['Name']] = Fog::AWS::S3::Bucket.new({
|
||||
:buckets => self,
|
||||
buckets << Fog::AWS::S3::Bucket.new({
|
||||
:buckets => buckets,
|
||||
:connection => connection,
|
||||
:owner => owner
|
||||
}.merge!(bucket))
|
||||
end
|
||||
self
|
||||
buckets
|
||||
end
|
||||
|
||||
def create(attributes = {})
|
||||
|
@ -41,7 +41,6 @@ module Fog
|
|||
:connection => connection,
|
||||
:name => data['Name']
|
||||
})
|
||||
self[bucket.name] = bucket
|
||||
objects_data = {}
|
||||
for key, value in data
|
||||
if ['IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
|
||||
|
@ -51,7 +50,7 @@ module Fog
|
|||
bucket.objects.merge_attributes(objects_data)
|
||||
data['Contents'].each do |object|
|
||||
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
|
||||
bucket.objects[object['Key']] = Fog::AWS::S3::Object.new({
|
||||
bucket.objects << Fog::AWS::S3::Object.new({
|
||||
:bucket => bucket,
|
||||
:connection => connection,
|
||||
:objects => self,
|
||||
|
|
|
@ -33,13 +33,11 @@ module Fog
|
|||
end
|
||||
end
|
||||
target_object.merge_attributes(copy_data)
|
||||
target_object.objects[target_object_key] = target_object
|
||||
target_object
|
||||
end
|
||||
|
||||
def destroy
|
||||
connection.delete_object(bucket.name, @key)
|
||||
objects.delete(@key)
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -55,7 +53,6 @@ module Fog
|
|||
def save(options = {})
|
||||
data = connection.put_object(bucket.name, @key, @body, options)
|
||||
@etag = data.headers['ETag']
|
||||
objects[@key] = self
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -15,12 +15,7 @@ module Fog
|
|||
|
||||
def all(options = {})
|
||||
merge_attributes(options)
|
||||
self.delete_if {true}
|
||||
objects = bucket.buckets.get(bucket.name, attributes).objects
|
||||
objects.keys.each do |key|
|
||||
self[key] = objects[key]
|
||||
end
|
||||
self
|
||||
bucket.buckets.get(bucket.name, attributes).objects
|
||||
end
|
||||
|
||||
def bucket
|
||||
|
@ -44,11 +39,12 @@ module Fog
|
|||
object_data[key] = value
|
||||
end
|
||||
end
|
||||
self[object_data['key']] = Fog::AWS::S3::Object.new({
|
||||
object = Fog::AWS::S3::Object.new({
|
||||
:bucket => bucket,
|
||||
:connection => connection,
|
||||
:objects => self
|
||||
}.merge!(object_data))
|
||||
object
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
@ -63,11 +59,12 @@ module Fog
|
|||
object_data[key] = value
|
||||
end
|
||||
end
|
||||
self[object_data['key']] = Fog::AWS::S3::Object.new({
|
||||
object = Fog::AWS::S3::Object.new({
|
||||
:bucket => bucket,
|
||||
:connection => connection,
|
||||
:objects => self
|
||||
}.merge!(object_data))
|
||||
object
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Fog
|
||||
class Collection < Hash
|
||||
class Collection < Array
|
||||
|
||||
def self.attribute(name, other_names = [])
|
||||
class_eval <<-EOS, __FILE__, __LINE__
|
||||
|
|
|
@ -116,12 +116,12 @@ describe 'Fog::AWS::S3::Bucket' do
|
|||
end
|
||||
|
||||
it "should not exist in buckets before save" do
|
||||
@bucket.buckets.key?(@bucket.name).should be_false
|
||||
@bucket.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.key?(@bucket.name).should be_true
|
||||
@bucket.buckets.all.map {|bucket| bucket.name}.include?(@bucket.name).should be_true
|
||||
@bucket.destroy
|
||||
end
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ describe 'Fog::AWS::S3::Buckets' do
|
|||
end
|
||||
|
||||
it "should include persisted buckets" do
|
||||
bucket = s3.buckets.create(:name => 'fogbucketname')
|
||||
s3.buckets.all.keys.should include('fogbucketname')
|
||||
bucket.destroy
|
||||
@bucket = s3.buckets.create(:name => 'fogbucketname')
|
||||
s3.buckets.all.map {|bucket| bucket.name}.should include('fogbucketname')
|
||||
@bucket.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue