babydebugger 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/babydebugger +6 -0
- data/lib/babydebugger.rb +132 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7d0f2b10dd9deba30102269e8bec4f816f88ea7
|
4
|
+
data.tar.gz: d5d464030128ae0d742226404fd35002db0ba53f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5368d5229bafa32792458e7ed2bb8b9d38d26e2b83cf1e4054561d3959ba05718c784ce4651c18d54db2cbccfedfe0f7fe3ad25df35fe9f1070b1acbac62c5a4
|
7
|
+
data.tar.gz: 48373f28d98481eb4965a937a9770a2856c4cdcf0a9ed7c7622ecbff15c968f2be58ac37e1e3ecd44ea59f3d14de08ab62abec48c3cd2e7c3a34ddd556b7e7de
|
data/bin/babydebugger
ADDED
data/lib/babydebugger.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
class Babydebugger
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :mode, :lines_modified, :files_modified, :word
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.go(args)
|
8
|
+
Babydebugger.mode = ''
|
9
|
+
Babydebugger.lines_modified = 0
|
10
|
+
Babydebugger.files_modified = 0
|
11
|
+
|
12
|
+
process_args(args)
|
13
|
+
load_files
|
14
|
+
print_stats
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.print_usage
|
18
|
+
puts "USAGE: prybaby [option]"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.print_help
|
22
|
+
print_usage
|
23
|
+
puts "-r: Remove breakpoints from files."
|
24
|
+
puts "-c: Comment out lines with debugger breakpoints."
|
25
|
+
puts "-u: Uncomment lines with debugger breakpoints."
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.process_args(args)
|
29
|
+
if args == nil
|
30
|
+
self.mode = 'c'
|
31
|
+
else
|
32
|
+
args = args.gsub('-', '')
|
33
|
+
self.mode = 'h' if args == '-help'
|
34
|
+
if args.length > 1 || args.scan(/u|r|c|h/).empty?
|
35
|
+
self.mode = 'e'
|
36
|
+
elsif
|
37
|
+
self.mode = args
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.load_files()
|
43
|
+
if self.mode == 'r'
|
44
|
+
Dir.glob(File.join(".", "**", "*.js")).each { |file| remove_breakpoints(file) }
|
45
|
+
elsif self.mode == 'c'
|
46
|
+
Dir.glob(File.join(".", "**", "*.js")).each { |file| comment_out_breakpoints(file) }
|
47
|
+
elsif self.mode == 'u'
|
48
|
+
Dir.glob(File.join(".", "**", "*.js")).each { |file| remove_comments_from_breakpoints(file) }
|
49
|
+
elsif self.mode == 'e'
|
50
|
+
print_usage
|
51
|
+
elsif self.mode == 'h'
|
52
|
+
print_help
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.remove_breakpoints(file)
|
57
|
+
self.word = 'removed'
|
58
|
+
file_changed = false
|
59
|
+
temp_file = Tempfile.new('tempfile')
|
60
|
+
|
61
|
+
open(file, 'r').each do |l|
|
62
|
+
if l.include?('debugger')
|
63
|
+
self.lines_modified += 1
|
64
|
+
file_changed = true
|
65
|
+
else
|
66
|
+
temp_file << l
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if file_changed
|
71
|
+
temp_file.close
|
72
|
+
FileUtils.mv(temp_file.path, file)
|
73
|
+
self.files_modified += 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.comment_out_breakpoints(file)
|
78
|
+
self.word = 'commented out'
|
79
|
+
file_changed = false
|
80
|
+
temp_file = Tempfile.new('tempfile')
|
81
|
+
|
82
|
+
open(file, 'r').each do |l|
|
83
|
+
if l.strip[0] == '//'
|
84
|
+
temp_file << l
|
85
|
+
elsif l.include?('debugger')
|
86
|
+
self.lines_modified += 1
|
87
|
+
file_changed = true
|
88
|
+
|
89
|
+
temp_file << "#{' ' * l.index('debugger')}\// #{l.strip}\n"
|
90
|
+
else
|
91
|
+
temp_file << l
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
if file_changed
|
96
|
+
temp_file.close
|
97
|
+
FileUtils.mv(temp_file.path, file)
|
98
|
+
self.files_modified += 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.remove_comments_from_breakpoints(file)
|
103
|
+
self.word = 'uncommented'
|
104
|
+
file_changed = false
|
105
|
+
temp_file = Tempfile.new('tempfile')
|
106
|
+
|
107
|
+
open(file, 'r').each do |l|
|
108
|
+
if l.include?('debugger') && l.include?('//')
|
109
|
+
spaces = l.index('//')
|
110
|
+
temp_file << "#{' ' * spaces}#{l[spaces + 2..l.length]}"
|
111
|
+
self.lines_modified += 1
|
112
|
+
file_changed = true
|
113
|
+
else
|
114
|
+
temp_file << l
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
if file_changed
|
119
|
+
temp_file.close
|
120
|
+
FileUtils.mv(temp_file.path, file)
|
121
|
+
self.files_modified += 1
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.print_stats
|
126
|
+
if self.lines_modified == 0 && self.files_modified == 0
|
127
|
+
puts 'Babydebugger: No changes were made.'
|
128
|
+
else
|
129
|
+
puts "Babydebugger: #{self.lines_modified} lines were #{self.word} in #{self.files_modified} files."
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: babydebugger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cyrus Ghazanfar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem that quickly removes debugger breakpoints from code
|
14
|
+
email: cghazanfar10@gmail.com
|
15
|
+
executables:
|
16
|
+
- babydebugger
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/babydebugger
|
21
|
+
- lib/babydebugger.rb
|
22
|
+
homepage: https://github.com/cyzanfar/babydebugger
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.4.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: babydebugger
|
46
|
+
test_files: []
|
47
|
+
has_rdoc:
|