Class: Siba::OptionsBackup

Inherits:
Object
  • Object
show all
Extended by:
FilePlug, LoggerPlug
Defined in:
lib/siba/options_backup.rb

Constant Summary collapse

OPTIONS_BACKUP_FILE_NAME =
"siba_options_backup.yml"

Class Method Summary collapse

Methods included from LoggerPlug

close, create, logger, logger, opened?

Methods included from FilePlug

siba_file, siba_file, siba_file=

Class Method Details

.load_source_from_backup(dir) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/siba/options_backup.rb', line 20

def load_source_from_backup(dir)
  path_to_options_backup = File.join dir, OPTIONS_BACKUP_FILE_NAME
  options_backup = Siba::OptionsLoader.load_yml path_to_options_backup
  Siba.current_dir = SibaCheck.options_string options_backup, "current_dir"
  unless siba_file.file_directory? Siba.current_dir
    begin
      siba_file.file_utils_mkpath Siba.current_dir
    rescue Exception
      logger.error "Can not access the backup current directory #{Siba.current_dir}"
      raise
    end
  end
  SibaTask.new options_backup, "source"
end

.save_options_backup(path_to_options, to_dir) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/siba/options_backup.rb', line 11

def save_options_backup(path_to_options, to_dir)
  data = Siba::FileHelper.read path_to_options
  data << "\n\ncurrent_dir: \"#{Siba::StringHelper.escape_for_yaml(Siba.current_dir)}\""
  options_backup_path = File.join to_dir, OPTIONS_BACKUP_FILE_NAME
  siba_file.run_this do
    Siba::FileHelper.write options_backup_path, data
  end
end