module CloudBackup class DriverStack attr_accessor :max_items def initialize @list = [] @max_items = 2 @file_names = [] end def list @list end def addable? driver driver.is_a? CloudBackup::Driver end def add_driver konstant @list << konstant end def add_file name @file_names << name end def add_files array @file_names = @file_names + array end def perform_backup! driver_initiate driver_add_files driver_upload_files driver_remove_old_files driver_shut_down_execution end def driver_initiate @list.each do |driver| driver.initiate end end protected def driver_add_files @list.each do |driver| @file_names.each do |file_name| driver.add_file file_name end end end def driver_upload_files @list.each do |driver| driver.upload end end def driver_remove_old_files @list.each do |driver| names = driver.list_by_date (names - names.first(@max_items)).each do |name| driver.remove name end end end def driver_shut_down_execution @list.each do |driver| driver.terminate end end end end