1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[docs::was::storage] added docs for other public methods

This commit is contained in:
Weston Platter 2012-12-26 22:31:35 -06:00
parent 1db9ea947c
commit 8ab67ba3e7

View file

@ -29,6 +29,14 @@ module Fog
# Use small chunk sizes to minimize memory. E.g. 5242880 = 5mb
attr_accessor :multipart_chunk_size
# Set file's access control list (ACL).
#
# valid acls: private, public-read, public-read-write, authenticated-read
#
# @param [String] new_acl one of valid options
# @return [String] @acl
#
def acl=(new_acl)
valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read']
unless valid_acls.include?(new_acl)
@ -37,6 +45,11 @@ module Fog
@acl = new_acl
end
# Get file's body if exists, else ' '.
#
# @return [File]
#
def body
attributes[:body] ||= if last_modified && (file = collection.get(identity))
file.body
@ -45,14 +58,35 @@ module Fog
end
end
# Set body attribute.
#
# @param [File] new_body
# @return [File] attributes[:body]
#
def body=(new_body)
attributes[:body] = new_body
end
# Get the file instance's directory.
#
# @return [Fog::AWS::Storage::Directory]
#
def directory
@directory
end
# Copy object from one bucket to other bucket.
#
# required attributes: directory, key
#
# @param target_directory_key [String]
# @param target_file_key [String]
# @param options [Hash] options for copy_object method
# @return [String] Fog::AWS::Files#head status of directory contents
#
def copy(target_directory_key, target_file_key, options = {})
requires :directory, :key
connection.copy_object(directory.key, key, target_directory_key, target_file_key, options)
@ -60,6 +94,15 @@ module Fog
target_directory.files.head(target_file_key)
end
# Destroy file via http DELETE.
#
# required attributes: directory, key
#
# @param options [Hash]
# @options versionId []
# @return [Boolean] true if successful
#
def destroy(options = {})
requires :directory, :key
attributes[:body] = nil if options['versionId'] == version
@ -87,6 +130,14 @@ module Fog
end
end
# Set Access-Control-List permissions.
#
# valid new_publics: public_read, private
#
# @param [String] new_public
# @return [String] new_puplic
#
def public=(new_public)
if new_public
@acl = 'public-read'
@ -96,6 +147,15 @@ module Fog
new_public
end
# Get pubically acessible url via http GET.
# Checks persmissions before creating.
# Defaults to s3 subdomain or compliant bucket name
#
# required attributes: directory, key
#
# @return [String] public url
#
def public_url
requires :directory, :key
if connection.get_object_acl(directory.key, key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
@ -155,11 +215,24 @@ module Fog
true
end
# Get a url for file.
#
# required attributes: key
#
# @param expires [String] number of seconds before url expires
# @param options [Hash]
# @return [String] url
#
def url(expires, options = {})
requires :key
collection.get_url(key, expires, options)
end
# File version if exists or creates new version.
# @return [Fog::Storage::AWS::Version]
#
def versions
@versions ||= begin
Fog::Storage::AWS::Versions.new(