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

add public methods to file model

This commit is contained in:
geemus 2010-11-18 11:18:46 -08:00
parent 311910deee
commit 3f5b48e812
5 changed files with 33 additions and 6 deletions

View file

@ -67,11 +67,18 @@ module Fog
end
end
def public=(new_public)
if new_public
@acl = 'public-read'
else
@acl = 'private'
end
new_public
end
def public_url
requires :directory, :key
if directory.public_url
"#{directory.public_url}/#{key}"
elsif connection.get_object_acl(directory.key, key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
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'}
if directory.key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
"https://#{directory.key}.s3.amazonaws.com/#{key}"
else

View file

@ -70,11 +70,18 @@ module Fog
end
end
def public=(new_public)
if new_public
@acl = 'public-read'
else
@acl = 'private'
end
new_public
end
def public_url
requires :directory, :key
if directory.public_url
"#{directory.public_url}/#{key}"
elsif connection.get_object_acl(directory.key, key).body['AccessControlList'].detect {|entry| entry['Scope']['type'] == 'AllUsers' && entry['Permission'] == 'READ'}
if connection.get_object_acl(directory.key, key).body['AccessControlList'].detect {|entry| entry['Scope']['type'] == 'AllUsers' && entry['Permission'] == 'READ'}
if directory.key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
"https://#{directory.key}.commondatastorage.googleapis/#{key}"
else

View file

@ -31,6 +31,10 @@ module Fog
true
end
def public=(new_public)
new_public
end
def public_url
nil
end

View file

@ -41,6 +41,10 @@ module Fog
end
end
def public=(new_public)
new_public
end
def public_url
requires :directory, :key
if @directory.public_url

View file

@ -7,6 +7,11 @@ def file_tests(connection, params = {}, mocks_implemented = true)
model_tests(@directory.files, params, mocks_implemented) do
tests("#public=(true)").succeeds do
pending if Fog.mocking? && !mocks_implemented
@instance.public=(true)
end
tests("#respond_to?(:public_url)").succeeds do
@instance.respond_to?(:public_url)
end