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/files.rb

79 lines
2.1 KiB
Ruby
Raw Normal View History

2010-10-04 17:02:08 -04:00
require 'fog/core/collection'
2010-09-08 17:40:02 -04:00
require 'fog/aws/models/storage/file'
2010-03-13 16:37:24 -05:00
2009-08-02 19:37:54 -04:00
module Fog
module AWS
2010-09-08 17:40:02 -04:00
class Storage
2010-01-14 23:44:39 -05:00
class Files < Fog::Collection
2009-08-02 19:37:54 -04:00
attribute :delimiter, :aliases => 'Delimiter'
attribute :directory
attribute :is_truncated, :aliases => 'IsTruncated'
attribute :marker, :aliases => 'Marker'
attribute :max_keys, :aliases => ['MaxKeys', 'max-keys']
attribute :prefix, :aliases => 'Prefix'
2009-08-04 13:51:54 -04:00
2010-09-08 17:40:02 -04:00
model Fog::AWS::Storage::File
def all(options = {})
requires :directory
options = {
'delimiter' => @delimiter,
'marker' => @marker,
'max-keys' => @max_keys,
'prefix' => @prefix
}.merge!(options)
options = options.reject {|key,value| value.nil? || value.to_s.empty?}
2010-01-05 01:03:24 -05:00
merge_attributes(options)
2010-03-08 19:19:48 -05:00
parent = directory.collection.get(
directory.key,
options
)
2010-03-08 19:19:48 -05:00
if parent
merge_attributes(parent.files.attributes)
2010-03-08 19:19:48 -05:00
load(parent.files.map {|file| file.attributes})
2010-01-05 01:03:24 -05:00
else
nil
end
end
def get(key, options = {}, &block)
requires :directory
data = connection.get_object(directory.key, key, options, &block)
file_data = data.headers.merge({
:body => data.body,
:key => key
})
2010-01-14 23:44:39 -05:00
new(file_data)
rescue Excon::Errors::NotFound
nil
end
def get_url(key, expires)
requires :directory
connection.get_object_url(directory.key, key, expires)
end
def head(key, options = {})
requires :directory
data = connection.head_object(directory.key, key, options)
file_data = data.headers.merge({
:key => key
})
2010-01-14 23:44:39 -05:00
new(file_data)
rescue Excon::Errors::NotFound
nil
end
def new(attributes = {})
requires :directory
2010-01-14 23:44:39 -05:00
super({ :directory => directory }.merge!(attributes))
end
2009-08-02 19:37:54 -04:00
end
end
end
end