class RBT::BackupProgram

Public Class Methods

new( array_these_programs = [] ) click to toggle source
#

initialize

The first argument is an array, listing which programs to backup.

#
# File lib/rbt/utility_scripts/backup_program.rb, line 33
def initialize(
    array_these_programs = []
  )
  reset
  unless array_these_programs.empty?
    set_array_these_programs(array_these_programs)
    backup_these_programs
  end
end

Public Instance Methods

backup_these_programs() click to toggle source
#

backup_these_programs

This is the actual powerhorse of the class.

#
# File lib/rbt/utility_scripts/backup_program.rb, line 69
def backup_these_programs
  # ======================================================================= #
  # Copy to new directory.
  # ======================================================================= #
  @target_dir = temp_directory?+'BackupProgram_'+@time_now+'/'
  remove(@target_dir) if File.exist? @target_dir # If it exists.
  create_directory @target_dir
  cd @target_dir
  e @target_dir
  @array_these_programs.each { |program|
    target = programs_directory?+program.capitalize
    @target_dir << program+'/'
    cmd = 'cp -rv '+target
    cmd << ' .'
    if File.exist? target
      esystem cmd
    else
      warn target+' does not exist.'
    end 
  }
  create_log
  notify_user_of_task_being_finished
end
Also aliased as: run
create_log() click to toggle source
#

create_log

Create a log file here.

#
# File lib/rbt/utility_scripts/backup_program.rb, line 108
def create_log
  into = @target_dir+'/ProgramsFile'
  e sfile(into)
  write_what_into(
    'We stored these programs: '+
    @array_these_programs.join(' ').downcase,
    into
  )
end
notify_user_of_task_being_finished() click to toggle source
#

notify_user_of_task_being_finished

#
# File lib/rbt/utility_scripts/backup_program.rb, line 96
def notify_user_of_task_being_finished
  e 'If you wish to change directory to that target, do:'
  e
  e "  cd #{sdir(@target_dir)}"
  e
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/backup_program.rb, line 46
def reset
  super()
  # ======================================================================= #
  # === @time_now
  # ======================================================================= #
  @time_now = ::Time.now.strftime '%d.%m.%Y'
end
run()
set_array_these_programs(i) click to toggle source
#

set_array_these_programs

We must keep in mind that i should be an Array.

#
# File lib/rbt/utility_scripts/backup_program.rb, line 59
def set_array_these_programs(i)
  i = [i].flatten.compact # <- Ensure that it is an Array.
  @array_these_programs = i
end