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

cleanup/simplify models

This commit is contained in:
Wesley Beary 2009-08-12 22:48:17 -07:00
parent ce75cef46a
commit c43cd2a91e
7 changed files with 7 additions and 23 deletions

View file

@ -15,16 +15,13 @@ module Fog
end
def delete
return false if new_record?
connection.release_address(@public_ip)
@new_record = true
true
end
def save
data = connection.allocate_address
@public_ip = data.body['publicIp']
@new_record = false
true
end

View file

@ -16,9 +16,7 @@ module Fog
end
def delete
return false if new_record?
connection.delete_key_pair(@name)
@new_record = true
true
end
@ -26,7 +24,6 @@ module Fog
data = connection.create_key_pair(@name)
new_attributes = data['Body'].reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
update_attributes(new_attributes)
@new_record = false
true
end

View file

@ -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, {
@ -12,16 +12,10 @@ module Fog
'Name' => :name
})
super
@objects ||= Fog::AWS::S3::Objects.new({
:bucket => bucket,
:connection => connection
})
end
def delete
return false if new_record?
connection.delete_bucket(name)
@new_record = true
true
end
@ -32,6 +26,10 @@ module Fog
end
end
def objects
Fog::AWS::S3::Objects.new(:connection => connection)
end
def payer
@payer ||= begin
data = connection.get_request_payment(name)
@ -50,7 +48,6 @@ module Fog
options['LocationConstraint'] = @location
end
connection.put_bucket(name, options)
@new_record = false
true
end

View file

@ -41,9 +41,7 @@ module Fog
end
def delete
return false if new_record?
connection.delete_object(bucket, key)
@new_record = true
true
end
@ -58,7 +56,6 @@ module Fog
def save(options = {})
data = connection.put_object(bucket, key, body, options)
@etag = data.headers['ETag']
@new_record = false
true
end

View file

@ -30,7 +30,7 @@ module Fog
}.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({
objects << Fog::AWS::S3::Object.new({
:bucket => bucket,
:connection => connection,
:owner => owner

View file

@ -1,5 +1,5 @@
module Fog
class Collection < Array
class Collection
def initialize(attributes = {})
update_attributes(attributes)

View file

@ -6,10 +6,6 @@ describe 'S3.buckets' do
p s3.buckets.all
end
it "should return bucket from get" do
p s3.buckets.get('monki')
end
it "should create bucket" do
p @bucket = s3.buckets.create(:name => 'fogbucketstest')
p @bucket.delete