Class: AssetCloud::FileSystemBucket
- Inherits:
-
Bucket
- Object
- Bucket
- AssetCloud::FileSystemBucket
show all
- Defined in:
- lib/asset_cloud/buckets/file_system_bucket.rb
Instance Attribute Summary
Attributes inherited from Bucket
#cloud, #name
Instance Method Summary
collapse
Methods inherited from Bucket
#initialize, #versioned?
Instance Method Details
#delete(key) ⇒ Object
23
24
25
26
27
|
# File 'lib/asset_cloud/buckets/file_system_bucket.rb', line 23
def delete(key)
File.delete(path_for(key))
rescue Errno::ENOENT
nil
end
|
#ls(key = nil) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/asset_cloud/buckets/file_system_bucket.rb', line 5
def ls(key = nil)
objects = []
base_path = File.join(path_for(key), "*")
Dir.glob(base_path).each do |f|
next unless File.file?(f)
objects.push(cloud[relative_path_for(f)])
end
objects
end
|
#read(key) ⇒ Object
17
18
19
20
21
|
# File 'lib/asset_cloud/buckets/file_system_bucket.rb', line 17
def read(key)
File.read(path_for(key))
rescue Errno::ENOENT
raise AssetCloud::AssetNotFoundError, key
end
|
#stat(key) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/asset_cloud/buckets/file_system_bucket.rb', line 36
def stat(key)
stat = File.stat(path_for(key))
Metadata.new(true, stat.size, stat.ctime, stat.mtime)
rescue Errno::ENOENT
Metadata.new(false)
end
|
#write(key, data) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/asset_cloud/buckets/file_system_bucket.rb', line 29
def write(key, data)
execute_in_full_path(key) do |path|
File.open(path, "wb+") { |fp| fp << data }
true
end
end
|