Class: SimpleBackup::Sources
- Inherits:
-
Object
- Object
- SimpleBackup::Sources
show all
- Includes:
- Singleton
- Defined in:
- lib/simple_backup/sources.rb
Constant Summary
collapse
- @@logger =
Utils::Logger.instance
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Sources.
10
11
12
13
|
# File 'lib/simple_backup/sources.rb', line 10
def initialize
@sources = {}
@default_keep_last = 5
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/simple_backup/sources.rb', line 39
def method_missing(method, *args)
source = create_source(method)
return nil if source.nil?
name = args.shift
options = args.shift
options ||= {}
type = source.type.to_sym
@sources[type] = {} if @sources[type].nil?
raise "Name '#{name}' for source #{type} already used" if @sources[type].has_key?(name.to_sym)
source.keep_last = @default_keep_last
source.keep_last = options[:keep_last] if options[:keep_last]
source.backends = options[:backends] if options[:backends]
source.name = name
source.configure(options)
@@logger.info "Created source for: #{source.desc.strip}"
@sources[type][name.to_sym] = source
end
|
Instance Method Details
#backup ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/simple_backup/sources.rb', line 25
def backup
@sources.each do |type, sources|
sources.each do |name, source|
source.get
end
end
end
|
#cleanup ⇒ Object
33
34
35
36
37
|
# File 'lib/simple_backup/sources.rb', line 33
def cleanup
each do |name, source|
source.cleanup
end
end
|
#default_keep_last=(value) ⇒ Object
15
16
17
|
# File 'lib/simple_backup/sources.rb', line 15
def default_keep_last=(value)
@default_keep_last = value
end
|
#each(&block) ⇒ Object
19
20
21
22
23
|
# File 'lib/simple_backup/sources.rb', line 19
def each(&block)
@sources.each do |type, sources|
sources.each(&block)
end
end
|