1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/rackspace/models/storage/directory.rb

63 lines
1.4 KiB
Ruby

require 'fog/core/model'
require 'fog/rackspace/models/storage/files'
module Fog
module Rackspace
class Storage
class Directory < Fog::Model
extend Fog::Deprecation
deprecate(:name, :key)
deprecate(:name=, :key=)
identity :key, :aliases => 'name'
attribute :bytes, :aliases => 'X-Container-Bytes-Used'
attribute :count, :aliases => 'X-Container-Object-Count'
def destroy
requires :key
connection.delete_container(key)
true
rescue Excon::Errors::NotFound
false
end
def files
@files ||= begin
Fog::Rackspace::Storage::Files.new(
:directory => self,
:connection => connection
)
end
end
def public=(new_public)
@public = new_public
end
def public_url
requires :key
@public_url ||= begin
begin response = connection.cdn.head_container(key)
response.headers['X-CDN-URI']
rescue Fog::Service::NotFound
nil
end
end
end
def save
requires :key
connection.put_container(key)
if @public
@public_url = connection.cdn.put_container(key).headers['X-CDN-URI']
end
true
end
end
end
end
end