notes 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +10 -10
- data/lib/notes.rb +9 -5
- data/test/data/sample.c +6 -3
- data/test/notes_test.rb +8 -0
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
== grep annotations in source files
|
4
4
|
|
5
5
|
This lib provides a Ruby library and command line tool to find annotations in source files such as:
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
* TODO
|
7
|
+
* FIXME
|
8
|
+
* OPTIMIZE
|
9
9
|
Custom tags can also be found.
|
10
10
|
|
11
11
|
The purpose of this code is to get a generic version of the `rake notes' command (only used for Ruby on Rails applications).
|
@@ -35,12 +35,12 @@ For details, see the help.
|
|
35
35
|
-a, --all Search TODO, FIXME and OPTIMIZE annotations
|
36
36
|
-t, --todo Search TODO annotations
|
37
37
|
-f, --fixme Search FIXME annotations
|
38
|
-
-
|
38
|
+
-z, --optimize Search OPTIMIZE annotations
|
39
39
|
-c, --custom=TAG Search TAG annotations
|
40
40
|
-o, --out=FILE Save output in FILE
|
41
41
|
-v, --version Print notes version
|
42
42
|
Example: notes -ac IMPROVE test.c lib
|
43
|
-
will search for TODO, FIXME, OPTIMIZE and IMPROVE annotations in test.c lib directory.
|
43
|
+
will search for TODO, FIXME, OPTIMIZE and IMPROVE annotations in test.c file and lib directory.
|
44
44
|
|
45
45
|
Another example:
|
46
46
|
|
@@ -71,11 +71,11 @@ This code can be used as a Ruby lib. Let's see how it works in irb:
|
|
71
71
|
|
72
72
|
$ irb
|
73
73
|
>> require 'notes'
|
74
|
-
>> AnnotationExtractor.tags << "FOO"
|
75
|
-
>> notes = AnnotationExtractor.new "test/data/sample.c"
|
76
|
-
>> notes.list
|
77
|
-
>> notes.get "FIXME"
|
78
|
-
>> notes.write "TODO.rdoc"
|
74
|
+
>> AnnotationExtractor.tags << "FOO" # Add custom tag
|
75
|
+
>> notes = AnnotationExtractor.new "test/data/sample.c" # Parse file
|
76
|
+
>> notes.list # Return the array of annotations
|
77
|
+
>> notes.get "FIXME" # Return the array of FIXME annotations only
|
78
|
+
>> notes.write "TODO.rdoc" # Write all annotations in a file
|
79
79
|
|
80
80
|
== License
|
81
81
|
|
data/lib/notes.rb
CHANGED
@@ -10,7 +10,7 @@ require 'rubygems'
|
|
10
10
|
require 'rak'
|
11
11
|
|
12
12
|
class AnnotationExtractor
|
13
|
-
VERSION = "0.0.
|
13
|
+
VERSION = "0.0.2"
|
14
14
|
|
15
15
|
# An annotation class.
|
16
16
|
class Annotation
|
@@ -68,9 +68,10 @@ class AnnotationExtractor
|
|
68
68
|
|
69
69
|
private
|
70
70
|
|
71
|
-
# Extract
|
71
|
+
# Extract annotations.
|
72
72
|
def extract
|
73
73
|
tags = self.class.tags.join("|")
|
74
|
+
suffix = "\s?:?" # Allowed annotation suffix.
|
74
75
|
source = @source.join(" ")
|
75
76
|
|
76
77
|
# Because of different rak versions,
|
@@ -84,12 +85,15 @@ class AnnotationExtractor
|
|
84
85
|
# 0.9 is the current rak version from rubygems.
|
85
86
|
# 1.1 is the current rak version from the github repo.
|
86
87
|
if rak_version == "1.1"
|
87
|
-
|
88
|
+
#TODO /^(.+):(\d+):...?
|
89
|
+
regex = /^(.*):(\d*):.*(#{tags})#{suffix}(.*)$/
|
88
90
|
else
|
89
|
-
regex = /^([^\s]+)\s+(\d+)\|.*(#{tags})
|
91
|
+
regex = /^([^\s]+)\s+(\d+)\|.*(#{tags})#{suffix}(.*)$/
|
90
92
|
end
|
93
|
+
# TODO extract first matching annotation if there're many on a line.
|
94
|
+
# e.g. "TODO: Rename $TODOLIST variable."
|
91
95
|
|
92
|
-
out = `rak '#{tags}' #{source}`.strip
|
96
|
+
out = `rak '(#{tags})#{suffix}\s+' #{source}`.strip
|
93
97
|
|
94
98
|
@list = out.split("\n").map do |l|
|
95
99
|
if l =~ regex
|
data/test/data/sample.c
CHANGED
@@ -23,13 +23,13 @@ int main()
|
|
23
23
|
size_t a_size = sizeof(struct sockaddr_in);
|
24
24
|
void *buffer = malloc(STEP);
|
25
25
|
|
26
|
-
//FIXME first fixme thing
|
26
|
+
//FIXME: first fixme thing
|
27
27
|
int port = 4242;
|
28
28
|
|
29
29
|
/* address server sock */
|
30
30
|
struct sockaddr_in addr = {AF_INET, htons(port), {htonl(INADDR_ANY)}};
|
31
31
|
|
32
|
-
//TODO second todo thing!
|
32
|
+
//TODO : second todo thing!
|
33
33
|
/* client sock */
|
34
34
|
struct sockaddr_in client;
|
35
35
|
|
@@ -39,10 +39,13 @@ int main()
|
|
39
39
|
/* bind socket to local */
|
40
40
|
bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in));
|
41
41
|
|
42
|
-
//OPTIMIZE make it better
|
42
|
+
//OPTIMIZE make it better
|
43
43
|
while(1)
|
44
44
|
{
|
45
45
|
//FOO a custom tag
|
46
|
+
//FOOBAR this should not be found if 'FOO' is asked. Same thing for:
|
47
|
+
//TODOLIST blah blah
|
48
|
+
//TODO_LIST etc.
|
46
49
|
while (recvfrom(sock, buffer, size, MSG_PEEK, NULL, NULL) == size)
|
47
50
|
buffer = realloc(buffer, size += STEP); //TODO hello world
|
48
51
|
|
data/test/notes_test.rb
CHANGED
@@ -23,6 +23,14 @@ class NotesTest < Test::Unit::TestCase
|
|
23
23
|
notes = AnnotationExtractor.new(@sample)
|
24
24
|
assert_equal 6, notes.list.size
|
25
25
|
|
26
|
+
# Test exact text
|
27
|
+
assert_equal "first thing to do", notes.list[0].text
|
28
|
+
assert_equal "first fixme thing", notes.list[1].text
|
29
|
+
assert_equal "second todo thing!", notes.list[2].text
|
30
|
+
assert_equal "make it better", notes.list[3].text
|
31
|
+
assert_equal "a custom tag", notes.list[4].text
|
32
|
+
assert_equal "hello world", notes.list[5].text
|
33
|
+
|
26
34
|
AnnotationExtractor.tags = "OPTIMIZE"
|
27
35
|
notes = AnnotationExtractor.new(@sample)
|
28
36
|
assert_equal 1, notes.list.size
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vivien Didelot
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-02 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|