Class: Dabcup::Operation::List

Inherits:
Base
  • Object
show all
Defined in:
lib/dabcup/operation/list.rb

Instance Attribute Summary

Attributes inherited from Base

#database

Instance Method Summary collapse

Methods inherited from Base

#best_dumps_path, #best_local_dumps_path, #check, #initialize, #remove_local_dump?, #same_ssh_as_database?, #terminate

Constructor Details

This class inherits a constructor from Dabcup::Operation::Base

Instance Method Details

#run(args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dabcup/operation/list.rb', line 4

def run(args)
  max_length = 0
  main_dumps = main_storage.list
  spare_dumps = spare_storage ? spare_storage.list : []
  # Intersection of main_dumps and spare_dumps
  dumps = main_dumps + spare_dumps.select do |dump| not main_dumps.include?(dump) end
  # Get length of the longest name
  max_length= (dumps.map {|d| d.name}.max {|l, r| l <=> r} || '').size
  # Prints names, sizes and flags
  dumps.each do |dump|
    name_str = dump.name.ljust(max_length + 2)
    size_str = (dump.size / 1024).to_s.rjust(8)
    location = main_dumps.include?(dump) ? 'M' : ' '
    location += spare_dumps.include?(dump) ? 'S' : ' '
    puts "#{name_str}#{size_str} KB #{location}"
  end
end