Sha256: fe835b2adaf878cd17bbdf0e49e3114fb5106b81c42ad01e401d12ed4420ef16

Contents?: true

Size: 1.58 KB

Versions: 11

Compression:

Stored size: 1.58 KB

Contents

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-Enabled'] == 'True' && 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, 'X-CDN-Enabled' => 'True').headers['X-CDN-URI']
          else
            connection.cdn.put_container(key, 'X-CDN-Enabled' => 'False')
            @public_url = nil
          end
          true
        end

      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fog-0.4.0 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.34 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.33 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.32 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.31 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.30 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.29 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.28 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.27 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.26 lib/fog/rackspace/models/storage/directory.rb
fog-0.3.25 lib/fog/rackspace/models/storage/directory.rb