class SimpleBackup::Source::Dir

Public Class Methods

new() click to toggle source
# File lib/simple_backup/source/dir.rb, line 4
def initialize
  @strategy = :bare
end

Public Instance Methods

configure(options = {}) click to toggle source
# File lib/simple_backup/source/dir.rb, line 8
def configure(options = {})
  raise "Must provide :path parameter" unless options[:path]
  @path = options[:path]

  raise "#{@path} is a file - use File source instead of Dir" unless !::File.exist?(@path) or ::File.directory?(@path)
  @strategy = options[:strategy] if options[:strategy]
end

Private Instance Methods

get_path_entries() click to toggle source
# File lib/simple_backup/source/dir.rb, line 26
def get_path_entries
  file = "simple_backup/source/dir_strategy/#{@strategy.to_s}"

  require file
  strategy_name = Object.const_get("SimpleBackup::Source::DirStrategy::#{@strategy.to_s.capitalize}")
  strategy = strategy_name.new

  strategy.get_entries(@path)
rescue Errno::ENOENT
  @@logger.warning "Path '#{@path}' does not exists"
  nil
end
prepare_data() click to toggle source
# File lib/simple_backup/source/dir.rb, line 17
def prepare_data
  return false unless ::File.exist?(@path)

  path_entries = get_path_entries
  FileUtils.cp_r path_entries, @tmp_dir if path_entries

  true
end