Module: QuiversTaskrunner

Defined in:
lib/quiverstaskrunner/version.rb,
lib/quiverstaskrunner/replacetokens.rb,
lib/quiverstaskrunner/restorepoints.rb,
lib/quiverstaskrunner/helpers/clihelper.rb,
lib/quiverstaskrunner/helpers/envhelper.rb,
lib/quiverstaskrunner/helpers/xmlhelper.rb,
lib/quiverstaskrunner/helpers/rakehelper.rb,
lib/quiverstaskrunner/helpers/settingshelper.rb

Defined Under Namespace

Modules: CliHelper, EnvHelper, RakeHelper, SettingsHelper, XmlHelper

Constant Summary collapse

VERSION =
"0.1.2492455"

Class Method Summary collapse

Class Method Details

.create_azure_files_restore_points(files_to_backup) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/quiverstaskrunner/restorepoints.rb', line 7

def create_azure_files_restore_points(files_to_backup)

  # convert single file into an array

  files = files_to_backup.is_a?(Array) ? files_to_backup : (files_to_backup.nil? ? [] : [files_to_backup])

  files.each do |f|
    f_ext = File.extname(f)
    f_backup_ext = ".backup#{f_ext}"
    f_backup = f.gsub(f_ext, f_backup_ext)
    # 1. Delete previous backup files if there are still present

    FileUtils.rm_f(f_backup) if FileTest.exists? f_backup
    # 2. Create backup files

    FileUtils.cp f, f_backup
  end
end

.replace_tokens(files_with_missing_tokens, tokens) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/quiverstaskrunner/replacetokens.rb', line 4

def replace_tokens(files_with_missing_tokens, tokens)
  files = files_with_missing_tokens.is_a?(Array) ? files_with_missing_tokens : [files_with_missing_tokens]
  raise ArgumentError, "'tokens' must be a Hash" unless tokens.is_a?(Hash)

  files.each { |f_path|
    content = nil
    File.open(f_path, "rb") do |f|
      content = f.read
      tokens.each { |k,v|
        content = content.gsub("{{#{k}}}", v)
      }
    end

    File.open(f_path, "w") do |f|
      f.write(content)
    end
  }
end

.restore_and_clean_files(files_to_restore) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/quiverstaskrunner/restorepoints.rb', line 23

def restore_and_clean_files(files_to_restore)

  # convert single file into an array

  files = files_to_restore.is_a?(Array) ? files_to_restore : (files_to_restore.nil? ? [] : [files_to_restore])

  files.each do |f|
    f_ext = File.extname(f)
    f_backup_ext = ".backup#{f_ext}"
    f_backup = f.gsub(f_ext, f_backup_ext)
    # 1. Make sure there are restore files available

    raise StandardError, "Missing restore file #{f_backup}"  unless FileTest.exists? f_backup
    # 2. Delete the modified files

    FileUtils.rm_f(f)
    # 3. Restore modified files

    FileUtils.cp f_backup, f
    # 4. Delete backup files

    FileUtils.rm_f(f_backup)
  end
end