Class: UploadManager

Inherits:
Object
  • Object
show all
Defined in:
lib/upload_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(bucket, path_prefix) ⇒ UploadManager

Returns a new instance of UploadManager.



5
6
7
8
9
10
11
12
# File 'lib/upload_manager.rb', line 5

def initialize (bucket, path_prefix)
	abort "error: must supply an S3 bucket" unless bucket
	abort "error: must supply a path prefix of at least '/'" unless path_prefix

	@uploads = []
	@path_prefix = path_prefix
	@bucket = bucket
end

Instance Method Details

#enqueue_upload(expected_path, actual_path) ⇒ Object



14
15
16
# File 'lib/upload_manager.rb', line 14

def enqueue_upload(expected_path, actual_path)
	@uploads.push(Upload.new(expected_path, actual_path))
end

#to_htmlObject



30
31
32
# File 'lib/upload_manager.rb', line 30

def to_html
	"<html><body>#{@uploads.map(&:to_html).join}</body></html>"
end

#upload(folder_name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/upload_manager.rb', line 18

def upload(folder_name)
	return nil unless @uploads.count > 0

	@uploads.each do |upload|
		upload.upload(@bucket, @path_prefix)
	end

	index_object = @bucket.objects[@path_prefix + folder_name + "/index.html"]
	index_object.write(to_html)
	index_object.url_for(:read).to_s
end