mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
moving s3 models to more abstract collection reference
This commit is contained in:
parent
922d3a4248
commit
e3e826ad69
6 changed files with 31 additions and 37 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue