2012-08-12 19:35:35 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Storage
|
|
|
|
class Atmos
|
|
|
|
|
|
|
|
class Directory < Fog::Model
|
|
|
|
|
|
|
|
identity :key, :aliases => :Filename
|
|
|
|
attribute :objectid, :aliases => :ObjectID
|
|
|
|
|
|
|
|
def files
|
|
|
|
@files ||= begin
|
|
|
|
Fog::Storage::Atmos::Files.new(
|
2012-12-19 17:28:04 -05:00
|
|
|
:directory => self,
|
|
|
|
:service => service
|
|
|
|
)
|
|
|
|
end
|
2012-08-12 19:35:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def directories
|
|
|
|
@directories ||= begin
|
2012-12-19 17:28:04 -05:00
|
|
|
Fog::Storage::Atmos::Directories.new(
|
|
|
|
:directory => self,
|
|
|
|
:service => service
|
|
|
|
)
|
|
|
|
end
|
2012-08-12 19:35:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
self.key = attributes[:directory].key + key if attributes[:directory]
|
|
|
|
self.key = key + '/' unless key =~ /\/$/
|
2012-12-19 17:28:04 -05:00
|
|
|
res = service.post_namespace key
|
2012-08-12 19:35:35 -04:00
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy(opts={})
|
|
|
|
if opts[:recursive]
|
|
|
|
files.each {|f| f.destroy }
|
|
|
|
directories.each do |d|
|
|
|
|
d.files.each {|f| f.destroy }
|
|
|
|
d.destroy(opts)
|
|
|
|
end
|
|
|
|
end
|
2012-12-19 17:28:04 -05:00
|
|
|
service.delete_namespace key
|
2012-08-12 19:35:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|