Class: SimpleBackup::Backends

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/simple_backup/backends.rb

Constant Summary collapse

@@logger =
Utils::Logger.instance
@@sources =
Sources.instance

Instance Method Summary collapse

Constructor Details

#initializeBackends

Returns a new instance of Backends.



11
12
13
# File 'lib/simple_backup/backends.rb', line 11

def initialize
  @backends = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/simple_backup/backends.rb', line 33

def method_missing(method, *args)
  backend = create_backend(method)

  return nil if backend.nil?

  name = args.shift
  options = args.shift
  options ||= {}

  raise "Name '#{name}' for backend already used" if @backends.has_key?(name.to_sym)

  backend.name = name
  backend.configure(options)

  @@logger.info "Created backend for: #{backend.desc}"
  @backends[name.to_sym] = backend
end

Instance Method Details

#each(&block) ⇒ Object



15
16
17
# File 'lib/simple_backup/backends.rb', line 15

def each(&block)
  @backends.each(&block)
end

#save_and_cleanupObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simple_backup/backends.rb', line 19

def save_and_cleanup
  each do |name, backend|
    @@sources.each do |name, source|
      next unless source.backup_file and source.supports(backend)

      backend.store(source)
      @@logger.info "Source '#{source.desc.strip}' stored in backend '#{backend.desc.strip}'"

      backend.cleanup(source)
      @@logger.info "Source '#{source.desc.strip}' cleaned up in backend '#{backend.desc.strip}'"
    end
  end
end