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

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

Instance Attribute Summary collapse

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Attribute Details

#bytesInteger (readonly)

Returns The number of bytes used by the directory.

Returns:

  • (Integer)

    The number of bytes used by the directory



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

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:



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

attribute :cdn_cname

#countInteger (readonly)

Returns The number of objects in the directory.

Returns:

  • (Integer)

    The number of objects in the directory



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

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

#keyString (readonly)

Returns The name of the directory.

Returns:

  • (String)

    The name of the directory



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

identity  :key, :aliases => 'name'

#public=(value) ⇒ Object (writeonly)

Required for compatibility with other Fog providers. Not Used.



32
33
34
# File 'lib/fog/rackspace/models/storage/directory.rb', line 32

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.



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

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



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

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



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

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.



143
144
145
# File 'lib/fog/rackspace/models/storage/directory.rb', line 143

def ios_url
  urls[:ios_uri]
end

#metadataFog::Storage::Rackspace::Metadata

Retrieve directory metadata

Returns:



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

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:



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

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:



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

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



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

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



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

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



154
155
156
# File 'lib/fog/rackspace/models/storage/directory.rb', line 154

def streaming_url
  urls[:streaming_uri]
end