Class: BackupOrganizer::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/backup_organizer/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Configuration

Returns a new instance of Configuration.



6
7
8
9
10
11
# File 'lib/backup_organizer/configuration.rb', line 6

def initialize(options)
  @path, @pattern = options[:path], options[:pattern]

  raise Error::ConfigurationError.new('No path set') unless @path
  raise Error::ConfigurationError.new('No pattern set') unless @path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/backup_organizer/configuration.rb', line 5

def path
  @path
end

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/backup_organizer/configuration.rb', line 5

def pattern
  @pattern
end

Instance Method Details

#directoriesObject



13
14
15
# File 'lib/backup_organizer/configuration.rb', line 13

def directories
  pattern.directories.map {|directory| File.expand_path("./#{directory}", @path)}
end

#move_all_filesObject



17
18
19
20
21
22
23
# File 'lib/backup_organizer/configuration.rb', line 17

def move_all_files
  sources = directories
  destinations = (directories << :delete)[1..-1]
  sources.each_with_index do |source, i|
    FileMover.move_files(source, @pattern.rules[i], destinations[i])
  end
end