1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

let models know about their collections

This commit is contained in:
Wesley Beary 2009-08-28 09:03:19 -07:00
parent 846d6279f7
commit e32c247720
4 changed files with 48 additions and 14 deletions

View file

@ -53,6 +53,16 @@ module Fog
true true
end end
private
def buckets
@buckets
end
def buckets=(new_buckets)
@buckets = new_buckets
end
end end
end end

View file

@ -14,6 +14,7 @@ module Fog
buckets = Fog::AWS::S3::Buckets.new buckets = Fog::AWS::S3::Buckets.new
data['Buckets'].each do |bucket| data['Buckets'].each do |bucket|
buckets << Fog::AWS::S3::Bucket.new({ buckets << Fog::AWS::S3::Bucket.new({
:buckets => self
:connection => connection, :connection => connection,
:owner => owner :owner => owner
}.merge!(bucket)) }.merge!(bucket))
@ -28,7 +29,12 @@ module Fog
end end
def new(attributes = {}) def new(attributes = {})
Fog::AWS::S3::Bucket.new(attributes.merge!(:connection => connection)) Fog::AWS::S3::Bucket.new(
attributes.merge!(
:connection => connection,
:buckets => self
)
)
end end
end end

View file

@ -61,6 +61,14 @@ module Fog
@bucket = new_bucket @bucket = new_bucket
end end
def objects
@objects
end
def objects=(new_objects)
@objects = new_objects
end
end end
end end

View file

@ -20,6 +20,12 @@ module Fog
end end
def all(options = {}) def all(options = {})
remap_attributes(options, {
:is_truncated => 'IsTruncated',
:marker => 'Marker',
:max_keys => 'MaxKeys',
:prefix => 'Prefix'
})
data = connection.get_bucket(bucket.name, options).body data = connection.get_bucket(bucket.name, options).body
objects_data = {} objects_data = {}
for key, value in data for key, value in data
@ -36,6 +42,7 @@ module Fog
objects << Fog::AWS::S3::Object.new({ objects << Fog::AWS::S3::Object.new({
:bucket => bucket, :bucket => bucket,
:connection => connection, :connection => connection,
:objects => self,
:owner => owner :owner => owner
}.merge!(object)) }.merge!(object))
end end
@ -62,7 +69,8 @@ module Fog
end end
Fog::AWS::S3::Object.new({ Fog::AWS::S3::Object.new({
:bucket => bucket, :bucket => bucket,
:connection => connection :connection => connection,
:objects => self
}.merge!(object_data)) }.merge!(object_data))
end end
@ -76,14 +84,16 @@ module Fog
end end
Fog::AWS::S3::Object.new({ Fog::AWS::S3::Object.new({
:bucket => bucket, :bucket => bucket,
:connection => connection :connection => connection,
:objects => self
}.merge!(object_data)) }.merge!(object_data))
end end
def new(attributes = {}) def new(attributes = {})
Fog::AWS::S3::Object.new({ Fog::AWS::S3::Object.new({
:bucket => bucket, :bucket => bucket,
:connection => connection :connection => connection,
:objects => self
}.merge!(attributes)) }.merge!(attributes))
end end