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

Chdir in a block to dry up all method

- also, plays much nicer with FakeFS
This commit is contained in:
Karl Freeman 2013-05-27 16:07:26 +01:00
parent 08de898804
commit 6ddc27f5de

View file

@ -14,19 +14,19 @@ module Fog
def all def all
requires :directory requires :directory
if directory.collection.get(directory.key) if directory.collection.get(directory.key)
pwd = Dir.pwd data = []
Dir.chdir(service.path_to(directory.key)) Dir.chdir(service.path_to(directory.key)) {
data = Dir.glob('**/*').reject do |file| data = Dir.glob('**/*').reject do |file|
::File.directory?(file) ::File.directory?(file)
end.map do |key| end.map do |key|
path = file_path(key) path = file_path(key)
{ {
:content_length => ::File.size(path), :content_length => ::File.size(path),
:key => key, :key => key,
:last_modified => ::File.mtime(path) :last_modified => ::File.mtime(path)
} }
end end
Dir.chdir(pwd) }
load(data) load(data)
else else
nil nil