2010-05-01 22:10:11 -07:00
|
|
|
require 'fog/collection'
|
|
|
|
require 'fog/local/models/directory'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Local
|
|
|
|
|
|
|
|
class Real
|
|
|
|
def directories
|
|
|
|
Fog::Local::Directories.new(:connection => self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
def directories
|
|
|
|
Fog::Local::Directories.new(:connection => self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Directories < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Local::Directory
|
|
|
|
|
|
|
|
def all
|
|
|
|
data = Dir.entries(connection.local_root).select do |entry|
|
|
|
|
entry[0...1] != '.' && ::File.directory?(connection.path_to(entry))
|
|
|
|
end.map do |entry|
|
2010-05-04 14:31:42 -07:00
|
|
|
{:key => entry}
|
2010-05-01 22:10:11 -07:00
|
|
|
end
|
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
2010-05-04 14:31:42 -07:00
|
|
|
def get(key)
|
|
|
|
if ::File.directory?(connection.path_to(key))
|
|
|
|
new(:key => key)
|
2010-05-01 22:10:11 -07:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|