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
end
private
def buckets
@buckets
end
def buckets=(new_buckets)
@buckets = new_buckets
end
end
end

View file

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

View file

@ -5,14 +5,14 @@ module Fog
class Object < Fog::Model
attr_accessor :body,
:content_length,
:content_type,
:etag,
:key,
:last_modified,
:owner,
:size,
:storage_class
:content_length,
:content_type,
:etag,
:key,
:last_modified,
:owner,
:size,
:storage_class
def initialize(attributes = {})
remap_attributes(attributes, {
@ -61,6 +61,14 @@ module Fog
@bucket = new_bucket
end
def objects
@objects
end
def objects=(new_objects)
@objects = new_objects
end
end
end

View file

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