Class: Backup::Storages

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Singleton
Defined in:
lib/backup-agent/storages/base.rb,
lib/backup-agent/storages.rb,
lib/backup-agent/storages/local.rb,
lib/backup-agent/storages/amazon-s3.rb

Overview

Storage based on Amazon S3

Defined Under Namespace

Classes: AmazonS3, Base, Local

Instance Method Summary collapse

Constructor Details

#initializeStorages

Returns a new instance of Storages.



9
10
11
# File 'lib/backup-agent/storages.rb', line 9

def initialize
  @groups = {}
end

Instance Method Details

#[](pair) ⇒ Object



13
14
15
# File 'lib/backup-agent/storages.rb', line 13

def [](pair)
  @groups.fetch(pair.keys[0]).fetch(pair.values[0])
end

#amazon_s3(definitions) ⇒ Object



36
37
38
39
40
# File 'lib/backup-agent/storages.rb', line 36

def amazon_s3(definitions)
  definitions.map do |name, options|
    register Backup::Storages::AmazonS3 => [:amazon_s3, name, options.merge(credentials: credentials[amazon_s3: name])]
  end.flatten(1)
end

#eachObject



17
18
19
20
21
# File 'lib/backup-agent/storages.rb', line 17

def each
  @groups.each do |type, storages|
    storages.each { |name, storage| yield storage, type, name }
  end
end

#local(definitions) ⇒ Object



30
31
32
33
34
# File 'lib/backup-agent/storages.rb', line 30

def local(definitions)
  definitions.map do |name, args|
    register Backup::Storages::Local => [:local, name, *[args].flatten(1)]
  end.flatten(1)
end

#register(arg) ⇒ Object

register AmazonS3 => [:amazon_s3, :default, storage constructor arguments…]



24
25
26
27
28
# File 'lib/backup-agent/storages.rb', line 24

def register(arg)
  arg.map do |klass, rest|
    (@groups[rest[0]] ||= {})[rest[1]] = klass.new(*rest.drop(2))
  end
end