Class: Fog::Storage::Rackspace::Directory

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/rackspace/models/storage/directory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bytesInteger (readonly)

Returns The number of bytes used by the directory.

Returns:

  • (Integer)

    The number of bytes used by the directory



15
# File 'lib/fog/rackspace/models/storage/directory.rb', line 15

attribute :bytes, :aliases => 'X-Container-Bytes-Used', :type => :integer

#cdn_nameString

Note:

This value does not persist and will need to be specified each time a directory is created or retrieved

Returns The CDN CNAME to be used instead of the default CDN directory URI. The CDN CNAME will need to be setup setup in DNS and point to the default CDN directory URI.

Returns:

  • (String)

    The CDN CNAME to be used instead of the default CDN directory URI. The CDN CNAME will need to be setup setup in DNS and point to the default CDN directory URI.

See Also:



26
# File 'lib/fog/rackspace/models/storage/directory.rb', line 26

attribute :cdn_cname

#countInteger (readonly)

Returns The number of objects in the directory.

Returns:

  • (Integer)

    The number of objects in the directory



19
# File 'lib/fog/rackspace/models/storage/directory.rb', line 19

attribute :count, :aliases => 'X-Container-Object-Count', :type => :integer

#keyString (readonly)

Returns The name of the directory.

Returns:

  • (String)

    The name of the directory



11
# File 'lib/fog/rackspace/models/storage/directory.rb', line 11

identity  :key, :aliases => 'name'

#public=(value) ⇒ Object (writeonly)

Required for compatibility with other Fog providers. Not Used.



30
31
32
# File 'lib/fog/rackspace/models/storage/directory.rb', line 30

def public=(value)
  @public = value
end

#public_urlString

Returns the public url for the directory. If the directory has not been published to the CDN, this method will return nil as it is not publically accessible. This method will return the approprate url in the following order:

  1. If the service used to access this directory was created with the option :rackspace_cdn_ssl => true, this method will return the SSL-secured URL.

  2. If the cdn_cname attribute is populated this method will return the cname.

  3. return the default CDN url.

Returns:

  • (String)

    public url for directory

Raises:



128
129
130
131
132
# File 'lib/fog/rackspace/models/storage/directory.rb', line 128

def public_url
  return nil if urls.empty?
  return urls[:ssl_uri] if service.ssl?
  cdn_cname || urls[:uri]
end

Instance Method Details

#destroyBoolean

Note:

Directory must be empty before it is destroyed.

Destroy the directory and remove it from CDN

Returns:

  • (Boolean)

    returns true if directory was deleted

Raises:

See Also:



65
66
67
68
69
70
71
72
# File 'lib/fog/rackspace/models/storage/directory.rb', line 65

def destroy
  requires :key
  service.delete_container(key)
  service.cdn.publish_container(self, false) if cdn_enabled?
  true
rescue Excon::Errors::NotFound
  false
end

#filesFog::Storage::Rackspace::Files

Returns collection of files in directory

Returns:

Raises:



80
81
82
83
84
85
86
87
# File 'lib/fog/rackspace/models/storage/directory.rb', line 80

def files
  @files ||= begin
    Fog::Storage::Rackspace::Files.new(
      :directory    => self,
      :service   => service
    )
  end
end

#ios_urlString

URL used to stream video to iOS devices. Cloud Files will auto convert to the approprate format.

Returns:

  • (String)

    iOS URL

Raises:

See Also:



141
142
143
# File 'lib/fog/rackspace/models/storage/directory.rb', line 141

def ios_url
  urls[:ios_uri]
end

#metadataFog::Storage::Rackspace::Metadata

Retrieve directory metadata

Returns:



49
50
51
52
53
54
55
# File 'lib/fog/rackspace/models/storage/directory.rb', line 49

def 
  unless attributes[:metadata]
     response = service.head_container(key)
     attributes[:metadata] = Fog::Storage::Rackspace::Metadata.from_headers(self, response.headers)
  end
  attributes[:metadata]
end

#metadata=(hash) ⇒ Object

Set directory metadata

Parameters:



38
39
40
41
42
43
44
45
# File 'lib/fog/rackspace/models/storage/directory.rb', line 38

def metadata=(hash)
  if hash.is_a? Fog::Storage::Rackspace::Metadata
    attributes[:metadata] = hash
  else
    attributes[:metadata] = Fog::Storage::Rackspace::Metadata.new(self, hash)
  end
  attributes[:metadata]
end

#public?Boolean

Is directory published to CDN

Returns:

  • (Boolean)

    return true if published to CDN

Raises:



95
96
97
98
99
100
# File 'lib/fog/rackspace/models/storage/directory.rb', line 95

def public?
  if @public.nil?
    @public ||= (key && public_url) ? true : false
  end
  @public
end

#reloadFog::Storage::Rackspace::Directory

Reload directory with latest data from Cloud Files

Returns:

Raises:



108
109
110
111
112
113
# File 'lib/fog/rackspace/models/storage/directory.rb', line 108

def reload
  @public = nil
  @urls = nil
  @files = nil
  super
end

#saveBoolean

Note:

If public attribute is true, directory will be CDN enabled

Create or update directory and associated metadata

Returns:

  • (Boolean)

    returns true if directory was saved

Raises:

See Also:



164
165
166
167
168
169
170
171
172
173
# File 'lib/fog/rackspace/models/storage/directory.rb', line 164

def save
  requires :key
  create_or_update_container
  if cdn_enabled?
    @urls = service.cdn.publish_container(self, public?)
  else
    raise Fog::Storage::Rackspace::Error.new("Directory can not be set as :public without a CDN provided") if public?
  end
  true
end

#streaming_urlString

URL used to stream resources



152
153
154
# File 'lib/fog/rackspace/models/storage/directory.rb', line 152

def streaming_url
  urls[:streaming_uri]
end