1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/storage/directories.rb

40 lines
1.1 KiB
Ruby
Raw Normal View History

2010-10-04 17:02:08 -04:00
require 'fog/core/collection'
require 'fog/aws/models/storage/directory'
2010-03-13 16:37:24 -05:00
2009-08-02 19:37:54 -04:00
module Fog
module Storage
class AWS
2010-01-14 23:44:39 -05:00
class Directories < Fog::Collection
model Fog::Storage::AWS::Directory
2009-08-02 19:37:54 -04:00
def all
data = service.get_service.body['Buckets']
load(data)
2009-08-02 19:37:54 -04:00
end
def get(key, options = {})
remap_attributes(options, {
:delimiter => 'delimiter',
:marker => 'marker',
:max_keys => 'max-keys',
:prefix => 'prefix'
})
data = service.get_bucket(key, options).body
directory = new(:key => data['Name'], :is_persisted => true)
2009-09-21 14:40:16 -04:00
options = {}
for k, v in data
if ['CommonPrefixes', 'Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(k)
options[k] = v
end
end
2010-01-14 23:44:39 -05:00
directory.files.merge_attributes(options)
directory.files.load(data['Contents'])
2010-01-14 23:44:39 -05:00
directory
rescue Excon::Errors::NotFound
nil
end
2009-08-02 19:37:54 -04:00
end
end
end
end