Class: Fog::Storage::Ninefold::Files
- Inherits:
-
Collection
- Object
- Array
- Collection
- Fog::Storage::Ninefold::Files
show all
- Defined in:
- lib/rackspace-fog/ninefold/models/storage/files.rb
Instance Attribute Summary
Attributes inherited from Collection
#connection
Instance Method Summary
collapse
Methods inherited from Collection
#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #reload, #table, #to_json
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Instance Method Details
#all(options = {}) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/rackspace-fog/ninefold/models/storage/files.rb', line 18
def all(options = {})
requires :directory
directory ? ns = directory.key : ns = ''
ns = ns + '/' unless ns =~ /\/$/
data = connection.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
load(files)
end
|
#get(key, &block) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/rackspace-fog/ninefold/models/storage/files.rb', line 33
def get(key, &block)
requires :directory
data = connection.get_namespace(directory.key + key, :parse => false) file_data = data..merge({
:body => data.body,
:key => key
})
new(file_data)
rescue Fog::Storage::Ninefold::NotFound
nil
end
|
#get_url(key) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/rackspace-fog/ninefold/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/rackspace-fog/ninefold/models/storage/files.rb', line 52
def head(key, options = {})
requires :directory
data = connection.head_namespace(directory.key + key, :parse => false)
file_data = data..merge({
:body => data.body,
:key => key
})
new(file_data)
rescue Fog::Storage::Ninefold::NotFound
nil
end
|
#new(attributes = {}) ⇒ Object
64
65
66
67
|
# File 'lib/rackspace-fog/ninefold/models/storage/files.rb', line 64
def new(attributes = {})
requires :directory
super({ :directory => directory }.merge!(attributes))
end
|