Sha256: 03782576041464a1efb0b6ef7ef8a343a8b2fb549115b3567b844652810c2088

Contents?: true

Size: 845 Bytes

Versions: 1

Compression:

Stored size: 845 Bytes

Contents

require 'cloudfiles'

class RackCloudBackupDriver < CloudBackup::Driver

  def initialize credentials
    @id = credentials[:id]
    @key = credentials[:key]
    @identificator = credentials[:bucket]
    @cf = CloudFiles::Connection.new(@id, @key)
  end

  def initiate
    @bucket = get_or_create_bucket
  end

  # TODO: parse metadata
  def list_by_date
    @bucket.objects
  end

  def remove name
    @bucket.delete_object name
  end

  # TODO: set metadata to objects
  def upload
    list.each do |file|
      object = @bucket.create_object File.basename(file)
      object.write File.read(file)
    end
  end

  def terminate
    @cf, @bucket = nil
  end

  private

  def get_or_create_bucket
    unless @cf.containers.include? @identificator
      @cf.create_container @identificator
    end
    @cf.container @identificator
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cloud-backup-0.0.2 lib/drivers/rack_cloud_backup_driver.rb