Class: Fog::Storage::Atmos::Files

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/atmos/models/storage/files.rb

Instance Attribute Summary

Attributes inherited from Collection

#service

Instance Method Summary collapse

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
32
33
34
35
36
# File 'lib/fog/atmos/models/storage/files.rb', line 18

def all(options = {})
  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|
    data = service.head_namespace(directory.key + s[:Filename], :parse => false)
    headers = Hash[data.headers["x-emc-meta"].split(", ").collect{|s|s.split("=")}]
    s[:content_length] = data.headers["Content-Length"]
    s[:content_type] = data.headers["Content-Type"]
    s[:created_at] = headers["ctime"]
    s[:directory] = directory
  end
  # TODO - Load additional file meta?
  load(files)
end

#get(key, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/atmos/models/storage/files.rb', line 38

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



50
51
52
53
54
55
# File 'lib/fog/atmos/models/storage/files.rb', line 50

def get_url(key)
  requires :directory
  if self.directory.public_url
    "#{self.directory.public_url}/#{key}"
  end
end

#head(key, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/atmos/models/storage/files.rb', line 57

def head(key, options = {})
  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



69
70
71
72
# File 'lib/fog/atmos/models/storage/files.rb', line 69

def new(attributes = {})
  requires :directory
  super({ :directory => directory }.merge!(attributes))
end