mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
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
This commit is contained in:
parent
72c9e6e888
commit
e424864bd2
3 changed files with 26 additions and 29 deletions
|
@ -4,7 +4,7 @@ module Fog
|
||||||
|
|
||||||
class Bucket < Fog::Model
|
class Bucket < Fog::Model
|
||||||
|
|
||||||
attr_accessor :creation_date, :location, :name, :objects, :owner
|
attr_accessor :creation_date, :location, :name, :owner
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
remap_attributes(attributes, {
|
remap_attributes(attributes, {
|
||||||
|
@ -29,6 +29,29 @@ module Fog
|
||||||
end
|
end
|
||||||
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
|
def payer
|
||||||
@payer ||= begin
|
@payer ||= begin
|
||||||
data = connection.get_request_payment(name)
|
data = connection.get_request_payment(name)
|
||||||
|
|
|
@ -27,32 +27,6 @@ module Fog
|
||||||
bucket
|
bucket
|
||||||
end
|
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 = {})
|
def new(attributes = {})
|
||||||
Fog::AWS::S3::Bucket.new(attributes.merge!(:connection => connection))
|
Fog::AWS::S3::Bucket.new(attributes.merge!(:connection => connection))
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(key, options = {})
|
def get(key, options = {})
|
||||||
data = connection.get_object(bucket, key, options)
|
data = connection.get_object(bucket.name, key, options)
|
||||||
object_data = {}
|
object_data = {}
|
||||||
for key, value in data.headers
|
for key, value in data.headers
|
||||||
if ['Content-Length', 'ETag', 'Last-Modified'].include?(key)
|
if ['Content-Length', 'ETag', 'Last-Modified'].include?(key)
|
||||||
|
@ -38,7 +38,7 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def head(key, options = {})
|
def head(key, options = {})
|
||||||
data = connection.head_object(bucket, key, options)
|
data = connection.head_object(bucket.name, key, options)
|
||||||
object_data = {}
|
object_data = {}
|
||||||
for key, value in data.headers
|
for key, value in data.headers
|
||||||
if ['Content-Length', 'ETag', 'Last-Modified'].include?(key)
|
if ['Content-Length', 'ETag', 'Last-Modified'].include?(key)
|
||||||
|
|
Loading…
Reference in a new issue