Class: Fog::Storage::Rackspace::Files
- Inherits:
-
Collection
- Object
- Array
- 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.
Attributes inherited from Collection
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_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.
Methods inherited from Collection
#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #reload, #table, #to_json
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::Collection
Instance Attribute Details
#directory ⇒ String
Methods in this class require this attribute to be set
Returns The name of the directory.
13 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 13 attribute :directory |
#limit ⇒ Integer
Returns For an integer value n, limits the number of results to at most n values.
18 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 18 attribute :limit |
#marker ⇒ String
Returns Given a string value x, return object names greater in value than the specified marker.
23 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 23 attribute :marker |
#path ⇒ String
Equivalent to setting delimiter to ‘/’ and prefix to the path with a ‘/’ on the end.
28 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 28 attribute :path |
#prefix ⇒ String
Returns For a string value x, causes the results to be limited to object names beginning with the substring x.
32 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 32 attribute :prefix |
Class Method Details
Instance Method Details
#all(options = {}) ⇒ Fog::Storage::Rackspace::Files
Returns list of files
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 43 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
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 72 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
71 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 71 alias :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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 110 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_url(key) ⇒ String
Returns the public_url for the given object key
133 134 135 136 137 138 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 133 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
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 148 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
162 163 164 165 |
# File 'lib/fog/rackspace/models/storage/files.rb', line 162 def new(attributes = {}) requires :directory super({ :directory => directory }.merge!(attributes)) end |