Class: Mutx::Support::FilesCleanner

Inherits:
Object
  • Object
show all
Defined in:
lib/mutx/support/files_cleanner.rb

Class Method Summary collapse

Class Method Details

.all_console_output_reportsObject



94
95
96
97
98
# File 'lib/mutx/support/files_cleanner.rb', line 94

def self.all_console_output_reports
  Dir["#{Dir.pwd}/mutx/temp/*.*"].select do |file|
    !file.scan(/mutx_co_\d+\.out/).empty?
  end
end

.all_mutx_reportsObject



48
49
50
51
52
# File 'lib/mutx/support/files_cleanner.rb', line 48

def self.all_mutx_reports
  Dir["#{Dir.pwd}/mutx/temp/*.*"].select do |file|
    !file.scan(/mutx_report_\d+\.html/).empty?
  end
end

.clear_mutx_logObject



115
116
117
118
119
120
121
# File 'lib/mutx/support/files_cleanner.rb', line 115

def self.clear_mutx_log
  mutx_log_file_path = "#{Dir.pwd}/mutx/logs/mutx.log"
  if File.exist? mutx_log_file_path
    File.delete(mutx_log_file_path)
    File.open(mutx_log_file_path, "a+"){}
  end
end

.clear_sidekiq_logObject



107
108
109
110
111
112
113
# File 'lib/mutx/support/files_cleanner.rb', line 107

def self.clear_sidekiq_log
  sidekiq_file_path = "#{Dir.pwd}/mutx/sidekiq_log"
  if File.exist? sidekiq_file_path
    File.delete(sidekiq_file_path)
    File.open(sidekiq_file_path, "a+"){}
  end
end

.delete_all_console_output_filesBoolean

Deletes all mutx execution output files

Returns:

  • (Boolean)

    if has deleted files



88
89
90
91
92
# File 'lib/mutx/support/files_cleanner.rb', line 88

def self.delete_all_console_output_files
  not all_console_output_reports.each do |file|
    delete_file(file)
  end.empty?
end

.delete_all_mutx_reportsBoolean

Deletes all mutx html reports files

Returns:

  • (Boolean)

    if has deleted reports



67
68
69
70
71
72
# File 'lib/mutx/support/files_cleanner.rb', line 67

def self.delete_all_mutx_reports
  not all_mutx_reports.each do |file|
    self.delete_file(file)
  end.empty?

end

.delete_console_output_for(result_id) ⇒ Object



100
101
102
103
104
105
# File 'lib/mutx/support/files_cleanner.rb', line 100

def self.delete_console_output_for result_id
  file=all_console_output_reports.select do |file|
    file.include? result_id
  end.first
  delete_file(file) if file
end

.delete_console_outputs_filesBoolean

Deletes mutx execution output files

Returns:

  • (Boolean)

    for success



76
77
78
79
80
81
82
83
84
# File 'lib/mutx/support/files_cleanner.rb', line 76

def self.delete_console_outputs_files
  (Mutx::Support::Git.reset_hard and Mutx::Support::Git.pull) if Mutx::Support::Configuration.use_git?
  begin
    self.delete_all_console_output_files
    true
  rescue
    false
  end
end

.delete_file(file_name) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/mutx/support/files_cleanner.rb', line 18

def self.delete_file file_name
  begin
    File.delete("#{file_name}") and true
  rescue
    false
  end
end

.delete_html_report_for(result_id) ⇒ Object



41
42
43
44
45
46
# File 'lib/mutx/support/files_cleanner.rb', line 41

def self.delete_html_report_for result_id
  file = all_mutx_reports.select do |file|
    file.include? result_id
  end.first
  delete_file(file) if file
end

.delete_mutx_folderBoolean

Deletes mutx folder. Used by ‘bye command’

Returns:

  • (Boolean)

    for success



125
126
127
128
129
130
131
132
133
# File 'lib/mutx/support/files_cleanner.rb', line 125

def self.delete_mutx_folder
  begin
    location = "#{Dir.pwd}/mutx"
    FileUtils.rm_rf(location)
    true
  rescue
    false
  end
end

.delete_mutx_reportsObject

Deletes all mutx html reports



55
56
57
58
59
60
61
62
63
# File 'lib/mutx/support/files_cleanner.rb', line 55

def self.delete_mutx_reports
  # Get all html report files
  (Mutx::Support::Git.reset_hard and Mutx::Support::Git.pull) if Mutx::Support::Configuration.use_git?
  begin
    self.delete_all_mutx_reports
  rescue
    false
  end
end

.delete_mutx_reports_dirObject



26
27
28
29
30
# File 'lib/mutx/support/files_cleanner.rb', line 26

def self.delete_mutx_reports_dir
  location = "#{Dir.pwd}/mutx/mutx_reports"
  FileUtils.rm_rf(location)
  Dir.mkdir(location)
end

.delete_report_which_has(text) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/mutx/support/files_cleanner.rb', line 32

def self.delete_report_which_has text
  text = text.to_s if text.respond_to? :to_s
  report = all_mutx_reports.select do |file|
    file.include? text
  end.first

  delete_file(report)
end

.start!Object

Delete all mutx_reports html files



9
10
11
12
13
14
15
16
# File 'lib/mutx/support/files_cleanner.rb', line 9

def self.start!
  begin
    self.delete_mutx_reports_dir
  rescue
    false
  end

end