Class: Fog::Local::Files
Instance Method Summary
collapse
Methods inherited from Collection
#_dump, _load, aliases, attribute, attributes, #attributes, #connection, #connection=, #create, #initialize, #inspect, #load, #merge_attributes, #model, model, #reload, #table, #to_json
Instance Method Details
#all ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/fog/local/models/files.rb', line 11
def all
if directory.collection.get(directory.name)
data = Dir.entries(connection.path_to(directory.name)).select do |key|
key[0...1] != '.' && !::File.directory?(connection.path_to(key))
end.map do |key|
path = file_path(key)
{
:content_length => ::File.size(path),
:key => key,
:last_modified => ::File.mtime(path)
}
end
load(data)
else
nil
end
end
|
#directory ⇒ Object
29
30
31
|
# File 'lib/fog/local/models/files.rb', line 29
def directory
@directory
end
|
#get(key, &block) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/fog/local/models/files.rb', line 33
def get(key, &block)
path = file_path(key)
if ::File.exists?(path)
data = {
:content_length => ::File.size(path),
:key => key,
:last_modified => ::File.mtime(path)
}
if block_given?
file = ::File.open(path)
while (chunk = file.read(Excon::CHUNK_SIZE)) && yield(chunk); end
file.close
new(data)
else
body = nil
::File.open(path) do |file|
body = file.read
end
new(data.merge!(:body => body))
end
else
nil
end
end
|
#new(attributes = {}) ⇒ Object
58
59
60
|
# File 'lib/fog/local/models/files.rb', line 58
def new(attributes = {})
super({ :directory => directory }.merge!(attributes))
end
|