Class: Tms::Comparison

Inherits:
Object
  • Object
show all
Defined in:
lib/tms/comparison.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backup_a, backup_b) ⇒ Comparison

Returns a new instance of Comparison.



8
9
10
# File 'lib/tms/comparison.rb', line 8

def initialize(backup_a, backup_b)
  @backup_a, @backup_b = backup_a, backup_b
end

Instance Attribute Details

#backup_aObject (readonly)

Returns the value of attribute backup_a.



7
8
9
# File 'lib/tms/comparison.rb', line 7

def backup_a
  @backup_a
end

#backup_bObject (readonly)

Returns the value of attribute backup_b.



7
8
9
# File 'lib/tms/comparison.rb', line 7

def backup_b
  @backup_b
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tms/comparison.rb', line 12

def run
  @a_total, @b_total = 0, 0
  begin
    if Backup.filter_dirs?
      Backup.filter_dirs.each do |real_dir|
        real_dir = File.expand_path(real_dir)
        dir = Tms::Backup.tm_path(real_dir)
        compare(backup_a.path / dir, backup_b.path / dir, Path.new(real_dir))
      end
    else
      root_dirs = (backup_a.path.children(false) | backup_b.path.children(false)).sort
      root_dirs.reject!{ |root_dir| root_dir.path[0, 1] == '.' }
      root_dirs.each do |dir|
        real_dir = Tms::Backup.real_path(dir)
        compare(backup_a.path / dir, backup_b.path / dir, Path.new('/', real_dir))
      end
    end
  rescue Interrupt
    puts
    puts 'Interrupted'
  end
  if Tms::Backup.show_both_sizes?
    line [colorize('Total:', :total), space(@a_total), space(@b_total)].join(' ')
  else
    line [colorize('Total:', :total), space(@b_total)].join(' ')
  end
end