Sha256: c28c497dff43af1db85b4e5a51cb1e5483e8127d40b3be12522b7f4b136862b1

Contents?: true

Size: 855 Bytes

Versions: 1

Compression:

Stored size: 855 Bytes

Contents

require 'aws-sdk'
require 'upload'

class UploadManager
  def initialize (bucket, path_prefix)
    abort "error: Second Curtain must supply an S3 bucket".red unless bucket
    abort "error: Second Curtain must supply a path prefix of at least '/'".re unless path_prefix

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

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

  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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
second_curtain-0.1.2 lib/second_curtain/upload_manager.rb