Class: Fog::Storage::Atmos::Files
- Inherits:
-
Collection
- Object
- Array
- Collection
- Fog::Storage::Atmos::Files
- Defined in:
- lib/fog/atmos/models/storage/files.rb
Instance Attribute Summary
Attributes inherited from Collection
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
- #get(key, &block) ⇒ Object
- #get_url(key) ⇒ Object
- #head(key, options = {}) ⇒ Object
- #new(attributes = {}) ⇒ 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 Method Details
#all(options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/atmos/models/storage/files.rb', line 18 def all( = {}) requires :directory directory ? ns = directory.key : ns = '' ns = ns + '/' unless ns =~ /\/$/ data = service.get_namespace(ns).body[:DirectoryList] data = {:DirectoryEntry => []} if data.kind_of? String data[:DirectoryEntry] = [data[:DirectoryEntry]] if data[:DirectoryEntry].kind_of? Hash files = data[:DirectoryEntry].select {|de| de[:FileType] == 'regular'} files.each do |s| s[:directory] = directory end # TODO - Load additional file meta? load(files) end |
#get(key, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/atmos/models/storage/files.rb', line 33 def get(key, &block) requires :directory data = service.get_namespace(directory.key + key, :parse => false)#, &block) file_data = data.headers.merge({ :body => data.body, :key => key }) new(file_data) rescue Fog::Storage::Atmos::NotFound nil end |
#get_url(key) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/fog/atmos/models/storage/files.rb', line 45 def get_url(key) requires :directory if self.directory.public_url "#{self.directory.public_url}/#{key}" end end |
#head(key, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fog/atmos/models/storage/files.rb', line 52 def head(key, = {}) requires :directory data = service.head_namespace(directory.key + key, :parse => false) file_data = data.headers.merge({ :body => data.body, :key => key }) new(file_data) rescue Fog::Storage::Atmos::NotFound nil end |
#new(attributes = {}) ⇒ Object
64 65 66 67 |
# File 'lib/fog/atmos/models/storage/files.rb', line 64 def new(attributes = {}) requires :directory super({ :directory => directory }.merge!(attributes)) end |