mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge branch 'master' of git@github.com:geemus/fog
This commit is contained in:
commit
37c8ce7bd7
3 changed files with 39 additions and 52 deletions
|
@ -5,9 +5,9 @@ module Fog
|
||||||
class Bucket < Fog::Model
|
class Bucket < Fog::Model
|
||||||
|
|
||||||
attr_accessor :creation_date,
|
attr_accessor :creation_date,
|
||||||
:location,
|
:location,
|
||||||
:name,
|
:name,
|
||||||
:owner
|
:owner
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
remap_attributes(attributes, {
|
remap_attributes(attributes, {
|
||||||
|
@ -22,10 +22,8 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def location
|
def location
|
||||||
@location ||= begin
|
data = s3.get_bucket_location(name)
|
||||||
data = s3.get_bucket_location(name)
|
data.body['LocationConstraint']
|
||||||
data.body['LocationConstraint']
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def objects
|
def objects
|
||||||
|
@ -36,10 +34,8 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def payer
|
def payer
|
||||||
@payer ||= begin
|
data = connection.get_request_payment(name)
|
||||||
data = connection.get_request_payment(name)
|
data.body['Payer']
|
||||||
data.body['Payer']
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def payer=(new_payer)
|
def payer=(new_payer)
|
||||||
|
|
|
@ -6,6 +6,7 @@ module Fog
|
||||||
|
|
||||||
attr_accessor :body,
|
attr_accessor :body,
|
||||||
:content_length,
|
:content_length,
|
||||||
|
:content_type,
|
||||||
:etag,
|
:etag,
|
||||||
:key,
|
:key,
|
||||||
:last_modified,
|
:last_modified,
|
||||||
|
@ -26,14 +27,6 @@ module Fog
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def body
|
|
||||||
@body ||= get.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def content_length
|
|
||||||
@content_length ||= head.content_length
|
|
||||||
end
|
|
||||||
|
|
||||||
def copy(target_bucket_name, target_object_key)
|
def copy(target_bucket_name, target_object_key)
|
||||||
data = connection.copy_object(bucket.name, key, target_bucket_name, target_object_key).body
|
data = connection.copy_object(bucket.name, key, target_bucket_name, target_object_key).body
|
||||||
copy = self.dup
|
copy = self.dup
|
||||||
|
@ -51,14 +44,6 @@ module Fog
|
||||||
connection.delete_object(bucket, key)
|
connection.delete_object(bucket, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def etag
|
|
||||||
@etag ||= head.etag
|
|
||||||
end
|
|
||||||
|
|
||||||
def last_modified
|
|
||||||
@last_modified ||= head.last_modified
|
|
||||||
end
|
|
||||||
|
|
||||||
def save(options = {})
|
def save(options = {})
|
||||||
data = connection.put_object(bucket.name, key, body, options)
|
data = connection.put_object(bucket.name, key, body, options)
|
||||||
@etag = data.headers['ETag']
|
@etag = data.headers['ETag']
|
||||||
|
@ -66,28 +51,6 @@ module Fog
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get
|
|
||||||
data = connection.get_object(bucket.name, key, options)
|
|
||||||
object_data = { :body => data.body}
|
|
||||||
for key, value in data.headers
|
|
||||||
if ['Content-Length', 'ETag', 'Last-Modified'].include?(key)
|
|
||||||
object_data[key] = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
update_attributes(object_data)
|
|
||||||
end
|
|
||||||
|
|
||||||
def head
|
|
||||||
data = connection.head_object(bucket.name, key, options)
|
|
||||||
object_data = {}
|
|
||||||
for key, value in data.headers
|
|
||||||
if ['Content-Length', 'ETag', 'Last-Modified'].include?(key)
|
|
||||||
object_data[key] = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
update_attributes(object_data)
|
|
||||||
end
|
|
||||||
|
|
||||||
def bucket=(new_bucket)
|
def bucket=(new_bucket)
|
||||||
@bucket = new_bucket
|
@bucket = new_bucket
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,9 +34,9 @@ module Fog
|
||||||
data['Contents'].each do |object|
|
data['Contents'].each do |object|
|
||||||
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
|
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
|
||||||
objects << Fog::AWS::S3::Object.new({
|
objects << Fog::AWS::S3::Object.new({
|
||||||
:bucket => bucket,
|
:bucket => bucket,
|
||||||
:connection => connection,
|
:connection => connection,
|
||||||
:owner => owner
|
:owner => owner
|
||||||
}.merge!(object))
|
}.merge!(object))
|
||||||
end
|
end
|
||||||
objects
|
objects
|
||||||
|
@ -48,6 +48,34 @@ module Fog
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get
|
||||||
|
data = connection.get_object(bucket.name, key, options)
|
||||||
|
object_data = { :body => data.body}
|
||||||
|
for key, value in data.headers
|
||||||
|
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
|
||||||
|
object_data[key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Fog::AWS::S3::Object.new({
|
||||||
|
:bucket => bucket,
|
||||||
|
:connection => connection
|
||||||
|
}.merge!(object_data))
|
||||||
|
end
|
||||||
|
|
||||||
|
def head
|
||||||
|
data = connection.head_object(bucket.name, key, options)
|
||||||
|
object_data = {}
|
||||||
|
for key, value in data.headers
|
||||||
|
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
|
||||||
|
object_data[key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Fog::AWS::S3::Object.new({
|
||||||
|
:bucket => bucket,
|
||||||
|
:connection => connection
|
||||||
|
}.merge!(object_data))
|
||||||
|
end
|
||||||
|
|
||||||
def new(attributes = {})
|
def new(attributes = {})
|
||||||
Fog::AWS::S3::Object.new({
|
Fog::AWS::S3::Object.new({
|
||||||
:bucket => bucket,
|
:bucket => bucket,
|
||||||
|
|
Loading…
Reference in a new issue