Class: Fog::Storage::Rackspace::Files
- Inherits:
-
Collection
- Object
- Collection
- Fog::Storage::Rackspace::Files
- Defined in:
- lib/fog/rackspace/models/storage/files.rb
Instance Attribute Summary collapse
-
#directory ⇒ String
The name of the directory.
-
#limit ⇒ Integer
For an integer value n, limits the number of results to at most n values.
-
#marker ⇒ String
Given a string value x, return object names greater in value than the specified marker.
-
#path ⇒ String
Equivalent to setting delimiter to ‘/’ and prefix to the path with a ‘/’ on the end.
-
#prefix ⇒ String
For a string value x, causes the results to be limited to object names beginning with the substring x.
Class Method Summary collapse
-
.file_url(path, key) ⇒ String
Returns an escaped object url.
Instance Method Summary collapse
-
#all(options = {}) ⇒ Fog::Storage::Rackspace::Files
Returns list of files.
- #each ⇒ Object
-
#each_file_this_page {|| ... } ⇒ Fog::Storage::Rackspace::Directory
Calls block for each file in the directory.
-
#get(key) {|data, remaining, content_length| ... } ⇒ Fog::Storage::Rackspace:File
Retrieves file.
-
#get_http_url(key, expires, options = {}) ⇒ String
Get a temporary http url for a file.
-
#get_https_url(key, expires, options = {}) ⇒ String
Get a temporary https url for a file.
-
#get_url(key) ⇒ String
Returns the public_url for the given object key.
-
#head(key, options = {}) ⇒ Fog::Storage::Rackspace::File
View directory detail without loading file contents.
-
#new(attributes = {}) ⇒ Fog::Storage::Rackspace::File
Create a new file object.
Instance Attribute Details
#directory ⇒ String
Methods in this class require this attribute to be set
Returns The name of the directory.
11 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 11 attribute :directory |
#limit ⇒ Integer
Returns For an integer value n, limits the number of results to at most n values.
16 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 16 attribute :limit |
#marker ⇒ String
Returns Given a string value x, return object names greater in value than the specified marker.
21 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 21 attribute :marker |
#path ⇒ String
Equivalent to setting delimiter to ‘/’ and prefix to the path with a ‘/’ on the end.
26 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 26 attribute :path |
#prefix ⇒ String
Returns For a string value x, causes the results to be limited to object names beginning with the substring x.
30 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 30 attribute :prefix |
Class Method Details
Instance Method Details
#all(options = {}) ⇒ Fog::Storage::Rackspace::Files
Returns list of files
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 41 def all( = {}) requires :directory = { 'limit' => limit, 'marker' => marker, 'path' => path, 'prefix' => prefix }.merge!() merge_attributes() parent = directory.collection.get( directory.key, ) if parent load(parent.files.map {|file| file.attributes}) else nil end end |
#each ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 70 def each if !block_given? self else subset = dup.all subset.each_file_this_page {|f| yield f} while subset.length == (subset.limit || 10000) subset = subset.all(:marker => subset.last.key) subset.each_file_this_page {|f| yield f} end self end end |
#each_file_this_page {|| ... } ⇒ Fog::Storage::Rackspace::Directory
This method retrieves files in pages. Page size is defined by the limit attribute
Calls block for each file in the directory
69 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 69 alias_method :each_file_this_page, :each |
#get(key) {|data, remaining, content_length| ... } ⇒ Fog::Storage::Rackspace:File
If a block is provided, the body attribute will be empty. By default chunk size is 1 MB. This value can be changed by passing the parameter :chunk_size into the :connection_options hash in the service constructor.
Retrieves file
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 108 def get(key, &block) requires :directory data = service.get_object(directory.key, key, &block) = Metadata.from_headers(self, data.headers) file_data = data.headers.merge({ :body => data.body, :key => key, :metadata => }) new(file_data) rescue Fog::Storage::Rackspace::NotFound nil end |
#get_http_url(key, expires, options = {}) ⇒ String
This URL does not use the Rackspace CDN
Get a temporary http url for a file.
required attributes: key
146 147 148 149 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 146 def get_http_url(key, expires, = {}) requires :directory service.get_object_http_url(directory.key, key, expires, ) end |
#get_https_url(key, expires, options = {}) ⇒ String
This URL does not use the Rackspace CDN
Get a temporary https url for a file.
required attributes: key
159 160 161 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 159 def get_https_url(key, expires, = {}) service.get_object_https_url(directory.key, key, expires, ) end |
#get_url(key) ⇒ String
Returns the public_url for the given object key
131 132 133 134 135 136 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 131 def get_url(key) requires :directory if self.directory.public_url Files::file_url directory.public_url, key end end |
#head(key, options = {}) ⇒ Fog::Storage::Rackspace::File
View directory detail without loading file contents
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 171 def head(key, = {}) requires :directory data = service.head_object(directory.key, key) file_data = data.headers.merge({ :key => key }) new(file_data) rescue Fog::Storage::Rackspace::NotFound nil end |
#new(attributes = {}) ⇒ Fog::Storage::Rackspace::File
Create a new file object
185 186 187 188 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 185 def new(attributes = {}) requires :directory super({ :directory => directory }.merge!(attributes)) end |