mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
let models know about their collections
This commit is contained in:
parent
846d6279f7
commit
e32c247720
4 changed files with 48 additions and 14 deletions
|
@ -53,6 +53,16 @@ module Fog
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def buckets
|
||||||
|
@buckets
|
||||||
|
end
|
||||||
|
|
||||||
|
def buckets=(new_buckets)
|
||||||
|
@buckets = new_buckets
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,8 +14,9 @@ module Fog
|
||||||
buckets = Fog::AWS::S3::Buckets.new
|
buckets = Fog::AWS::S3::Buckets.new
|
||||||
data['Buckets'].each do |bucket|
|
data['Buckets'].each do |bucket|
|
||||||
buckets << Fog::AWS::S3::Bucket.new({
|
buckets << Fog::AWS::S3::Bucket.new({
|
||||||
:connection => connection,
|
:buckets => self
|
||||||
:owner => owner
|
:connection => connection,
|
||||||
|
:owner => owner
|
||||||
}.merge!(bucket))
|
}.merge!(bucket))
|
||||||
end
|
end
|
||||||
buckets
|
buckets
|
||||||
|
@ -28,7 +29,12 @@ module Fog
|
||||||
end
|
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,
|
||||||
|
:buckets => self
|
||||||
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,14 +5,14 @@ module Fog
|
||||||
class Object < Fog::Model
|
class Object < Fog::Model
|
||||||
|
|
||||||
attr_accessor :body,
|
attr_accessor :body,
|
||||||
:content_length,
|
:content_length,
|
||||||
:content_type,
|
:content_type,
|
||||||
:etag,
|
:etag,
|
||||||
:key,
|
:key,
|
||||||
:last_modified,
|
:last_modified,
|
||||||
:owner,
|
:owner,
|
||||||
:size,
|
:size,
|
||||||
:storage_class
|
:storage_class
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
remap_attributes(attributes, {
|
remap_attributes(attributes, {
|
||||||
|
@ -61,6 +61,14 @@ module Fog
|
||||||
@bucket = new_bucket
|
@bucket = new_bucket
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def objects
|
||||||
|
@objects
|
||||||
|
end
|
||||||
|
|
||||||
|
def objects=(new_objects)
|
||||||
|
@objects = new_objects
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,6 +20,12 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def all(options = {})
|
def all(options = {})
|
||||||
|
remap_attributes(options, {
|
||||||
|
:is_truncated => 'IsTruncated',
|
||||||
|
:marker => 'Marker',
|
||||||
|
:max_keys => 'MaxKeys',
|
||||||
|
:prefix => 'Prefix'
|
||||||
|
})
|
||||||
data = connection.get_bucket(bucket.name, options).body
|
data = connection.get_bucket(bucket.name, options).body
|
||||||
objects_data = {}
|
objects_data = {}
|
||||||
for key, value in data
|
for key, value in data
|
||||||
|
@ -36,6 +42,7 @@ module Fog
|
||||||
objects << Fog::AWS::S3::Object.new({
|
objects << Fog::AWS::S3::Object.new({
|
||||||
:bucket => bucket,
|
:bucket => bucket,
|
||||||
:connection => connection,
|
:connection => connection,
|
||||||
|
:objects => self,
|
||||||
:owner => owner
|
:owner => owner
|
||||||
}.merge!(object))
|
}.merge!(object))
|
||||||
end
|
end
|
||||||
|
@ -62,7 +69,8 @@ module Fog
|
||||||
end
|
end
|
||||||
Fog::AWS::S3::Object.new({
|
Fog::AWS::S3::Object.new({
|
||||||
:bucket => bucket,
|
:bucket => bucket,
|
||||||
:connection => connection
|
:connection => connection,
|
||||||
|
:objects => self
|
||||||
}.merge!(object_data))
|
}.merge!(object_data))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,14 +84,16 @@ module Fog
|
||||||
end
|
end
|
||||||
Fog::AWS::S3::Object.new({
|
Fog::AWS::S3::Object.new({
|
||||||
:bucket => bucket,
|
:bucket => bucket,
|
||||||
:connection => connection
|
:connection => connection,
|
||||||
|
:objects => self
|
||||||
}.merge!(object_data))
|
}.merge!(object_data))
|
||||||
end
|
end
|
||||||
|
|
||||||
def new(attributes = {})
|
def new(attributes = {})
|
||||||
Fog::AWS::S3::Object.new({
|
Fog::AWS::S3::Object.new({
|
||||||
:bucket => bucket,
|
:bucket => bucket,
|
||||||
:connection => connection
|
:connection => connection,
|
||||||
|
:objects => self
|
||||||
}.merge!(attributes))
|
}.merge!(attributes))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue