Class: Raz::Backuper
- Inherits:
-
Object
- Object
- Raz::Backuper
- Defined in:
- lib/raz/backuper.rb
Instance Attribute Summary collapse
- #destination_path ⇒ String readonly
- #parsed_entries ⇒ Array<DirEntry | FileEntry> readonly
Instance Method Summary collapse
-
#backup ⇒ Object
Main method to back all files from configuration.
-
#initialize(config, destination_path) ⇒ Backuper
constructor
A new instance of Backuper.
- #investigate ⇒ Object
Constructor Details
#initialize(config, destination_path) ⇒ Backuper
Returns a new instance of Backuper.
20 21 22 23 |
# File 'lib/raz/backuper.rb', line 20 def initialize(config, destination_path) @config = config @destination_path = File.(destination_path) end |
Instance Attribute Details
#destination_path ⇒ String (readonly)
12 13 14 |
# File 'lib/raz/backuper.rb', line 12 def destination_path @destination_path end |
Instance Method Details
#backup ⇒ Object
Main method to back all files from configuration
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/raz/backuper.rb', line 37 def backup FileUtils.mkdir_p(@destination_path) dest_contents = FileOperations.dir_entries(@destination_path) unless dest_contents.empty? raise "Can only operate on empty or non-existing directory! Directory #{@destination_path} contains: #{dest_contents}" end # run before procs (@config.procs[:before_backup] || []).each do |proc| instance_eval &proc end investigate if @parsed_entries.nil? @copied_paths = [] @parsed_entries.each do |entry| copy_entry_to_dest(entry) end # save info for restorer save_info # backup config folder FileOperations.copy_item(File.dirname(@config.path), @destination_path) FileUtils.mv(File.join(@destination_path, CONFIG_FOLDER_BASE_PATH), File.join(@destination_path, BACKUP_CONFIG_FOLDER_BASE_PATH)) # run after procs (@config.procs[:after_backup] || []).each do |proc| instance_eval &proc end end |
#investigate ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/raz/backuper.rb', line 25 def investigate @file_system = FileSystem.new @parsed_entries = [] # process all items from configuration file @config.items.each do |item| process_item(item) end end |