Class: AppStage::DeleteFiles

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DeleteFiles

Returns a new instance of DeleteFiles.



4
5
6
# File 'lib/delete_files.rb', line 4

def initialize(options)
  @options = options
end

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/delete_files.rb', line 8

def execute
  begin
    files_json = ListFiles.new(@options).getFileList
    pattern = @options[:delete] || ".*"

    matching_files = files_json.select{|f| f['name'].match(/#{pattern}/)}
    puts "Deleting #{matching_files.count} files"

    matching_files.each do |rf|
      puts " deleting #{rf['name']}"
      delete_file(rf['id'])
    end
    0
  rescue Exception => e
    puts "Delete failed - #{e.message}"
    -1
  end
end