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

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

Instance Method Summary collapse

Instance Method Details

#all(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/atmos/models/storage/files.rb', line 16

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(", ").map{|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



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

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



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

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

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



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

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



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

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