Module: Vos::Drivers::S3VfsStorage
- Included in:
- S3
- Defined in:
- lib/vos/drivers/s3_vfs_storage.rb
Defined Under Namespace
Instance Method Summary collapse
-
#attributes(path) ⇒ Object
Attributes.
-
#create_dir(path) ⇒ Object
Dir.
- #delete_dir(path) ⇒ Object
- #delete_file(path) ⇒ Object
- #each_entry(path, query, &block) ⇒ Object
- #local? ⇒ Boolean
-
#read_file(path, &block) ⇒ Object
File.
- #set_attributes(path, attrs) ⇒ Object
-
#tmp(&block) ⇒ Object
Special.
- #write_file(original_path, append, &block) ⇒ Object
Instance Method Details
#attributes(path) ⇒ Object
Attributes
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 21 def attributes path path = normalize_path(path) return {dir: true, file: false} if path.empty? file = bucket.objects[path] if file.exists? attrs = {} attrs[:file] = true attrs[:dir] = false attrs[:size] = file.content_length attrs[:updated_at] = file.last_modified attrs # There's no dirs, always returning false # elsif dir_exists? path # attrs[:dir] = true else return nil end end |
#create_dir(path) ⇒ Object
Dir
81 82 83 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 81 def create_dir path raise Error, ":create_dir not supported!" end |
#delete_dir(path) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 85 def delete_dir path path = normalize_path path bucket.as_tree(prefix: path).children.each do |obj| if obj.branch? delete_dir "/#{obj.prefix}" elsif obj.leaf? bucket.objects[obj.key].delete else raise "unknow node type!" end end end |
#delete_file(path) ⇒ Object
71 72 73 74 75 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 71 def delete_file path path = normalize_path path file = bucket.objects[path] file.delete end |
#each_entry(path, query, &block) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 99 def each_entry path, query, &block path = normalize_path path raise "S3 not support :each_entry with query!" if query bucket.as_tree(prefix: path).children.each do |obj| if obj.branch? block.call obj.prefix.sub("#{path}/", '').sub(/\/$/, ''), :dir elsif obj.leaf? block.call obj.key.sub("#{path}/", ''), :file else raise "unknow node type!" end end end |
#local? ⇒ Boolean
130 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 130 def local?; false end |
#read_file(path, &block) ⇒ Object
File
48 49 50 51 52 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 48 def read_file path, &block path = normalize_path path file = bucket.objects[path] block.call file.read end |
#set_attributes(path, attrs) ⇒ Object
41 42 43 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 41 def set_attributes path, attrs raise 'not supported' end |
#tmp(&block) ⇒ Object
Special
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 117 def tmp &block tmp_dir = "/tmp/#{rand(10**6)}" if block begin block.call tmp_dir ensure delete_dir tmp_dir end else tmp_dir end end |
#write_file(original_path, append, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vos/drivers/s3_vfs_storage.rb', line 54 def write_file original_path, append, &block path = normalize_path original_path file = bucket.objects[path] if append # there's no support for :append in Fog, so we just mimic it writer = Writer.new writer.write file.read if file.exists? block.call writer file.write writer.data, acl: acl else writer = Writer.new block.call writer file.write writer.data, acl: acl end end |