Class: ByebugCleaner::Cleaner

Inherits:
Object
  • Object
show all
Includes:
ByebugCleaner
Defined in:
lib/byebug/cleaner/cleaner.rb

Constant Summary

Constants included from ByebugCleaner

VERSION

Class Method Summary collapse

Methods included from ByebugCleaner

cyan_str, green_str

Class Method Details

.clean(argv) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/byebug/cleaner/cleaner.rb', line 7

def self.clean argv

#Get options for clean
	optparse = ArgumentParser.new
	options = optparse.parse(argv[-1..argv.size])


	root = Pathname.new("#{Dir.pwd}")
	pwd = "#{Dir.pwd}/#{options.dir}"
	puts "Folder for searching is #{options.dir}"


	dirs = Dir[ File.join(pwd, '**', '*') ]
	dirs.delete_if {|f| File.directory?(f) }

	filelist = Rake::FileList.new
	filelist.include(dirs)

	results = []
	filelist.each do |file_name|
		str = IO.read(file_name)    
	next if !str.match(/.*byebug.*/)
	FileUtils.cp(file_name, "#{file_name}.backup") if options.backup
	file_path = Pathname.new(file_name)
	file_clean_path = file_path.relative_path_from(root) 

	text = File.read(file_name)
		new_content = text.gsub(/.*byebug.*/, "")

		File.open(file_name, "w") {|file| file.puts new_content } 

		results << file_clean_path
 	end

 	if results.size > 0
 		puts "Files was changed:"
 		results.each do |file_name| 
 			puts ByebugCleaner::green_str(" - #{file_name}")
 		end
 	else
 		puts ByebugCleaner::cyan_str("Byebug wasn't found.")
 	end
end