coffee_trace 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -40,6 +40,10 @@ Coffee Trace will remove all log statements that it added to files below the cur
|
|
40
40
|
|
41
41
|
***
|
42
42
|
|
43
|
+
For those interested in the source code, I was experimenting with a pattern where class names are not nouns, but the single responsibility of the class. I am not convinced yet that it is a pattern I'd use on a bigger project, but it is quite interesting and seems to help keep classes small and testable.
|
44
|
+
|
45
|
+
***
|
46
|
+
|
43
47
|
Copyright (c) 2011 Chris Aitchison. See LICENSE for details.
|
44
48
|
|
45
49
|
|
data/lib/coffee_trace/cli.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module CoffeeTrace
|
2
2
|
class CLI
|
3
|
-
|
4
3
|
def initialize insert_logging=CoffeeTrace::InsertLogging.new
|
5
4
|
@insert_logging = insert_logging
|
6
5
|
@files = Dir.glob "**/*.coffee"
|
@@ -8,27 +7,27 @@ module CoffeeTrace
|
|
8
7
|
|
9
8
|
def insert_logging
|
10
9
|
@files.each do |file|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
prefix =File.basename file, ".coffee"
|
11
|
+
result = @insert_logging.into File.readlines(file), prefix
|
12
|
+
write_lines file, result
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
17
16
|
def remove_logging
|
18
17
|
@files.each do |file|
|
19
|
-
|
18
|
+
lines = @insert_logging.into File.readlines(file)
|
20
19
|
result = lines.select do |line|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
/console\.log.*#coffee_trace.*/.match(line).nil?
|
21
|
+
end
|
22
|
+
write_lines file, result
|
24
23
|
end
|
25
24
|
end
|
26
|
-
|
25
|
+
|
26
|
+
private
|
27
27
|
def write_lines(path, data)
|
28
28
|
File.open(path, "wb") do |file|
|
29
29
|
file.puts data
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
33
32
|
end
|
34
33
|
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
module CoffeeTrace
|
2
|
-
|
1
|
+
module CoffeeTrace
|
3
2
|
class InsertLogStatement
|
4
|
-
|
5
3
|
def for line, prefix=nil
|
6
4
|
leading_spaces, method_name, args = parse_function line
|
7
5
|
return unless leading_spaces
|
@@ -13,17 +11,14 @@ module CoffeeTrace
|
|
13
11
|
end
|
14
12
|
|
15
13
|
private
|
16
|
-
|
17
14
|
def parse_function line
|
18
15
|
no_arg_function_match = line.scan(/^( *)(\w+): * \(? *\)? *[-=]> *$/)
|
19
|
-
|
20
|
-
no_arg_function_match[0]
|
16
|
+
no_arg_function_match.empty? ? parse_function_with_args(line) : no_arg_function_match.first
|
21
17
|
end
|
22
18
|
|
23
19
|
def parse_function_with_args line
|
24
20
|
arg_function_match = line.scan(/^( *)(\w+): *\((.*)\) *[-=]> *$/)
|
25
|
-
|
26
|
-
return arg_function_match[0]
|
21
|
+
arg_function_match.empty? ? nil : arg_function_match.first
|
27
22
|
end
|
28
23
|
end
|
29
24
|
|
@@ -9,8 +9,8 @@ module CoffeeTrace
|
|
9
9
|
result = []
|
10
10
|
lines.each do |line|
|
11
11
|
result.pop if is_coffee_trace_log?(line)
|
12
|
-
|
13
|
-
|
12
|
+
result << line
|
13
|
+
result << (@insert_log_statement.for line, prefix)
|
14
14
|
end
|
15
15
|
result.compact
|
16
16
|
end
|
data/lib/coffee_trace/version.rb
CHANGED
@@ -31,7 +31,6 @@ describe CoffeeTrace::InsertLogStatement do
|
|
31
31
|
assert " renderPoi: (poi) =>", " console.log 'renderPoi', poi #coffee_trace"
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
34
|
it "handles trailing spaces" do
|
36
35
|
assert " initialize: -> ", " console.log 'initialize' #coffee_trace"
|
37
36
|
end
|
@@ -39,6 +38,7 @@ describe CoffeeTrace::InsertLogStatement do
|
|
39
38
|
it "adds a prefix if given" do
|
40
39
|
assert_with_prefix " initialize: -> ","trace_logger"," console.log 'trace_logger-initialize' #coffee_trace"
|
41
40
|
end
|
41
|
+
|
42
42
|
it "indents correctly" do
|
43
43
|
assert "a: ->", " console.log 'a' #coffee_trace"
|
44
44
|
assert " a: ->", " console.log 'a' #coffee_trace"
|