Class: Kaya::Support::FilesCleanner

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

Class Method Summary collapse

Class Method Details

.all_console_output_reportsObject



93
94
95
96
97
# File 'lib/kaya/support/files_cleanner.rb', line 93

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

.all_kaya_reportsObject



47
48
49
50
51
# File 'lib/kaya/support/files_cleanner.rb', line 47

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

.clear_kaya_logObject



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

def self.clear_kaya_log
  kaya_log_file_path = "#{Dir.pwd}/kaya/kaya_log"
  if File.exist? kaya_log_file_path
    File.delete(kaya_log_file_path)
    File.open(kaya_log_file_path, "a+"){}
  end
end

.clear_sidekiq_logObject



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

def self.clear_sidekiq_log
  sidekiq_file_path = "#{Dir.pwd}/kaya/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 kaya execution output files

Returns:

  • (Boolean)

    if has deleted files



87
88
89
90
91
# File 'lib/kaya/support/files_cleanner.rb', line 87

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

.delete_all_kaya_reportsBoolean

Deletes all kaya html reports files

Returns:

  • (Boolean)

    if has deleted reports



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

def self.delete_all_kaya_reports
  not all_kaya_reports.each do |file|
    self.delete_file(file)
  end.empty?

end

.delete_console_output_for(result_id) ⇒ Object



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

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 kaya execution output files

Returns:

  • (Boolean)

    for success



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

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

.delete_file(file_name) ⇒ Object



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

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

.delete_html_report_for(result_id) ⇒ Object



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

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

.delete_kaya_folderBoolean

Deletes kaya folder. Used by ‘bye command’

Returns:

  • (Boolean)

    for success



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

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

.delete_kaya_reportsObject

Deletes all kaya html reports



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

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

.delete_kaya_reports_dirObject



25
26
27
28
29
# File 'lib/kaya/support/files_cleanner.rb', line 25

def self.delete_kaya_reports_dir
  location = "#{Dir.pwd}/kaya/kaya_reports"
  FileUtils.rm_rf(location)
  Dir.mkdir(location)
end

.delete_report_which_has(text) ⇒ Object



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

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

  delete_file(report)
end

.start!Object

Delete all kaya_reports html files



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

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

end