From e424864bd2110c9135eb5153ef00c6180a7ebdcd Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Wed, 5 Aug 2009 21:11:56 -0700 Subject: [PATCH] remove confusing get path, load a buckets objects when asked for and leave it to the user to keep them around if they want that --- lib/fog/aws/models/s3/bucket.rb | 25 ++++++++++++++++++++++++- lib/fog/aws/models/s3/buckets.rb | 26 -------------------------- lib/fog/aws/models/s3/objects.rb | 4 ++-- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/lib/fog/aws/models/s3/bucket.rb b/lib/fog/aws/models/s3/bucket.rb index 0850e6d25..0fda3460d 100644 --- a/lib/fog/aws/models/s3/bucket.rb +++ b/lib/fog/aws/models/s3/bucket.rb @@ -4,7 +4,7 @@ module Fog class Bucket < Fog::Model - attr_accessor :creation_date, :location, :name, :objects, :owner + attr_accessor :creation_date, :location, :name, :owner def initialize(attributes = {}) remap_attributes(attributes, { @@ -29,6 +29,29 @@ module Fog end end + def objects + data = connection.get_bucket(name, options).body + objects_data = {} + for key, value in data + if ['IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key) + objects_data[key] = value + end + end + objects = Fog::AWS::S3::Objects.new({ + :bucket => bucket, + :connection => connection + }.merge!(objects_data)) + data['Contents'].each do |object| + owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection)) + bucket.objects << Fog::AWS::S3::Object.new({ + :bucket => bucket, + :connection => connection, + :owner => owner + }.merge!(object)) + end + objects + end + def payer @payer ||= begin data = connection.get_request_payment(name) diff --git a/lib/fog/aws/models/s3/buckets.rb b/lib/fog/aws/models/s3/buckets.rb index 92491edd8..bdf5b1226 100644 --- a/lib/fog/aws/models/s3/buckets.rb +++ b/lib/fog/aws/models/s3/buckets.rb @@ -27,32 +27,6 @@ module Fog bucket end - def get(name, options = {}) - data = connection.get_bucket(name, options).body - bucket = Fog::AWS::S3::Bucket.new({ - :connection => connection - }) - objects_data = {} - for key, value in data - if ['IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key) - objects_data[key] = value - end - end - bucket.objects = Fog::AWS::S3::Objects.new({ - :bucket => bucket, - :connection => connection - }.merge!(objects_data)) - data['Contents'].each do |object| - owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection)) - bucket.objects << Fog::AWS::S3::Object.new({ - :bucket => bucket, - :connection => connection, - :owner => owner - }.merge!(object)) - end - bucket - end - def new(attributes = {}) Fog::AWS::S3::Bucket.new(attributes.merge!(:connection => connection)) end diff --git a/lib/fog/aws/models/s3/objects.rb b/lib/fog/aws/models/s3/objects.rb index bbb46b4bb..c0428eb0c 100644 --- a/lib/fog/aws/models/s3/objects.rb +++ b/lib/fog/aws/models/s3/objects.rb @@ -23,7 +23,7 @@ module Fog end def get(key, options = {}) - data = connection.get_object(bucket, key, options) + data = connection.get_object(bucket.name, key, options) object_data = {} for key, value in data.headers if ['Content-Length', 'ETag', 'Last-Modified'].include?(key) @@ -38,7 +38,7 @@ module Fog end def head(key, options = {}) - data = connection.head_object(bucket, key, options) + data = connection.head_object(bucket.name, key, options) object_data = {} for key, value in data.headers if ['Content-Length', 'ETag', 'Last-Modified'].include?(key)