Class: Bak::BackupNameGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/bak/backup_name_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, options_hash) ⇒ BackupNameGenerator

Returns a new instance of BackupNameGenerator.



5
6
7
8
# File 'lib/bak/backup_name_generator.rb', line 5

def initialize(filename, options_hash)
    @filename = filename
    @options = options_hash
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



3
4
5
# File 'lib/bak/backup_name_generator.rb', line 3

def filename
  @filename
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/bak/backup_name_generator.rb', line 3

def options
  @options
end

Instance Method Details

#[](item) ⇒ Object



10
11
12
# File 'lib/bak/backup_name_generator.rb', line 10

def [](item)
    @options[item]
end

#[]=(k, v) ⇒ Object



14
15
16
# File 'lib/bak/backup_name_generator.rb', line 14

def []=(k, v)
    @options[k] = v
end

#startObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bak/backup_name_generator.rb', line 18

def start
    filename = @filename
    if @options != {}
        if @options[:date] then filename = _with_date(filename) end
        if @options[:postfix] then filename = _with_postfix(filename, @options[:postfix]) end
        if @options[:prefix] then filename = _with_prefix(filename, @options[:prefix]) end
        if @options[:replace] then filename = _with_replace(filename, @options[:replace]) end
      if @options[:target_path] then filename = _with_target_path(filename, @options[:target_path]) end
    end
    unless @options[:no_bak] then filename = "#{filename}.bak" end

    filename
end