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.
11
12
13
14
|
# File 'lib/simple_backup/sources.rb', line 11
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/simple_backup/sources.rb', line 48
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.tmp_base_path = @tmp_dir if @tmp_dir
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
34
35
36
37
38
39
40
|
# File 'lib/simple_backup/sources.rb', line 34
def backup
@sources.each do |type, sources|
sources.each do |name, source|
source.get
end
end
end
|
#cleanup ⇒ Object
42
43
44
45
46
|
# File 'lib/simple_backup/sources.rb', line 42
def cleanup
each do |name, source|
source.cleanup
end
end
|
#default_keep_last=(value) ⇒ Object
16
17
18
|
# File 'lib/simple_backup/sources.rb', line 16
def default_keep_last=(value)
@default_keep_last = value
end
|
#each(&block) ⇒ Object
28
29
30
31
32
|
# File 'lib/simple_backup/sources.rb', line 28
def each(&block)
@sources.each do |type, sources|
sources.each(&block)
end
end
|
#tmp_dir(path) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/simple_backup/sources.rb', line 20
def tmp_dir(path)
raise "Temporary path '#{path}' does not exists" unless ::File.exist?(path)
raise "Temporary path '#{path}' is not a directory" unless ::File.directory?(path)
raise "Temporary path '#{path}' is not writable" unless ::File.writable?(path)
@tmp_dir = path
@@logger.info "Replaced temporary path to '#{@tmp_dir}'"
end
|