Class: AWS::S3::S3Object

Inherits:
Object show all
Defined in:
lib/s3/s3_object_store_folders.rb

Class Method Summary collapse

Class Method Details

.original_storeObject



9
# File 'lib/s3/s3_object_store_folders.rb', line 9

alias :original_store :store

.store(key, data, bucket = nil, options = {}) ⇒ Object



10
11
12
13
# File 'lib/s3/s3_object_store_folders.rb', line 10

def store(key, data, bucket = nil, options = {})
  store_folders(key, bucket, options) if options[:use_virtual_directories]
  original_store(key, data, bucket, options)
end

.store_directory(directory, bucket, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/s3/s3_object_store_folders.rb', line 20

def store_directory(directory, bucket, options = {})
  Dir[File.join(directory, "*")].each do |file|
    streamed_store("#{File.basename(File.dirname(file))}/#{File.basename(file)}", file, bucket, options.update(:use_virtual_directories => true))
  end
end

.store_folder(key, bucket = nil, options = {}) ⇒ Object



38
39
40
# File 'lib/s3/s3_object_store_folders.rb', line 38

def store_folder(key, bucket = nil, options = {})
  original_store(key + "_$folder$", "", bucket, options) # store the magic entry that emulates a folder
end

.store_folders(key, bucket = nil, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/s3/s3_object_store_folders.rb', line 26

def store_folders(key, bucket = nil, options = {})
  folders = key.split("/")
  folders.slice!(0)
  folders.pop
  current_folder = "/"
  folders.each {|folder|
    current_folder += folder
    store_folder(current_folder, bucket, options)
    current_folder += "/"
  }
end

.streamed_store(key, filepath, bucket = nil, options = {}) ⇒ Object



15
16
17
18
# File 'lib/s3/s3_object_store_folders.rb', line 15

def streamed_store(key, filepath, bucket = nil, options = {})
  store_folders(key, bucket, options) if options[:use_virtual_directories]
  store(key,File.open(filepath), bucket)
end