module System

Public Class Methods

clean(str) click to toggle source
# File lib/system.rb, line 44
def self.clean(str)
  str.gsub!(".", "-dot-")
  str.gsub!("_", "-")
  str.gsub!("\n", "")
  str.gsub!(/[^0-9a-z\-_]/i, '')
  return str
end
db_credentials() click to toggle source
# File lib/system.rb, line 10
def self.db_credentials
  db_config = YAML.load_file("#{Rails.root.to_s}/config/database.yml")
  db_config[Rails.env]
end
hostname() click to toggle source
# File lib/system.rb, line 6
def self.hostname
  `hostname`.to_str.gsub!("\n", "")
end
prompt(prompt, noecho = false) click to toggle source
# File lib/system.rb, line 52
def self.prompt(prompt, noecho = false)
  STDOUT.print prompt
  STDOUT.flush
  if noecho
    return STDIN.noecho(&:gets).chomp
  else
    return STDIN.gets.chomp
  end
end
run(command) click to toggle source

Run system commands

# File lib/system.rb, line 16
def self.run(command)
  result = system(command)
  raise("error, process exited with status #{$?.exitstatus}") unless result
end
tarzip_folders(folders) click to toggle source

Creates app tar file

# File lib/system.rb, line 22
def self.tarzip_folders(folders)
  application_tar = Tempfile.new("app")
  ex_folders = ''
  folders.each { |folder|
    unless File.exist?(folder)
      print "\nWARNING: Folder \'" + folder + "\' does not exist! Excluding from backup."
    else
      ex_folders << folder << ' '
    end
  }
  if ex_folders.length > 0
    cmd = "tar --dereference -czpf #{application_tar.path} #{ex_folders}"
    run(cmd)
  end
  return application_tar
end
unzip_file(tarball) click to toggle source
# File lib/system.rb, line 39
def self.unzip_file(tarball)
  cmd = "tar xpf #{tarball.path}"
  run(cmd)
end