Class: FileRecord::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/file_record/directory.rb

Class Method Summary collapse

Class Method Details

.backup(options = {}) ⇒ Object

Backup the tempo directory to tempo_backup/tempo_backup_20140101_HrMnS.tar.gz pass in an optional directory (see create_new) Pass in a timestamp, or default to 20140101_120000



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/file_record/directory.rb', line 35

def backup(options={})
  directory = options.fetch(:directory, Dir.home)
  timestamp = options.fetch(:timestamp, Time.new.strftime("%Y%m%d_%H%M%S"))
  source = File.join(directory, "tempo")
  dest = File.join(directory, "tempo_backups")
  Dir.mkdir dest unless Dir.exists? dest
  destination = File.join(directory, "tempo_backups", "tempo_backup_#{timestamp}.tar.gz")

  io = tar(source)
  gz = gzip(io)

  File.open(destination,"w") do |file|
     file.binmode
     file.write gz.read
  end

  # return the new directory name
  destination
end

.create_new(options = {}) ⇒ Object

Create a new directory structure, copying the contents from directory_structure/tempo into ~/tempo. If a directory is passed in through the options, the tempo directory will be created within that directory instead, in the users home folder

ex. create new(directory: “custom/directory”)

> Users/usrname/custom/directory/tempo



21
22
23
24
25
26
27
28
29
30
# File 'lib/file_record/directory.rb', line 21

def create_new(options={})

  directory = options.fetch(:directory, Dir.home)
  cwd = File.expand_path File.dirname(__FILE__)
  source = File.join(cwd, "directory_structure/tempo")
  if ! Dir.exists? directory
    FileUtils.mkdir_p directory
  end
  FileUtils.cp_r source, directory
end