2011-06-28 16:05:18 +10:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Storage
|
|
|
|
class Ninefold
|
|
|
|
|
|
|
|
class Directory < Fog::Model
|
|
|
|
|
2011-07-09 16:55:55 +10:00
|
|
|
identity :key, :aliases => :Filename
|
|
|
|
attribute :objectid, :aliases => :ObjectID
|
|
|
|
|
|
|
|
def files
|
|
|
|
@files ||= begin
|
|
|
|
Fog::Storage::Ninefold::Files.new(
|
|
|
|
:directory => self,
|
|
|
|
:connection => connection
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def directories
|
|
|
|
@directories ||= begin
|
|
|
|
Fog::Storage::Ninefold::Directories.new(
|
|
|
|
:directory => self,
|
|
|
|
:connection => connection
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2011-06-28 16:05:18 +10:00
|
|
|
|
|
|
|
def save
|
2011-07-10 23:44:35 +10:00
|
|
|
self.key = attributes[:directory].key + key if attributes[:directory]
|
|
|
|
self.key = key + '/' unless key =~ /\/$/
|
2011-07-09 16:55:55 +10:00
|
|
|
res = connection.post_namespace key
|
2011-06-28 16:05:18 +10:00
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
2011-07-09 16:55:55 +10:00
|
|
|
def destroy(opts={})
|
|
|
|
if opts[:recursive]
|
2011-07-10 23:44:35 +10:00
|
|
|
files.each {|f| f.destroy }
|
|
|
|
directories.each do |d|
|
|
|
|
d.files.each {|f| f.destroy }
|
|
|
|
d.destroy(opts)
|
|
|
|
end
|
2011-07-09 16:55:55 +10:00
|
|
|
end
|
|
|
|
connection.delete_namespace key
|
2011-06-28 16:05:18 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|