what_now 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/bin/wnow +2 -0
- data/lib/what_now.rb +14 -13
- data/spec/what_now_spec.rb +31 -8
- data/what_now.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22e94ada9391a63cbcf79bb1d3a4ca9f6f6962e2
|
4
|
+
data.tar.gz: ad69ca1e8fac29ee9e76c27177e98c082a27b6b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48e5808a0a2fa8f506ebc1db6ea30db35d0061393aba017dcde97c21b8986326eb750edefcbcb8fbffae8310d042aa082db65fb882f99b7d4a2341db4d80af4d
|
7
|
+
data.tar.gz: 9bd24a4355ee83214fcc4a68c1a5e266844e2ed574f19678ae30c95b754de423b40aa2e5ab3a1ed75e948e5fd911614308155781912f0bb00f72abaf07417d3d
|
data/README.md
CHANGED
@@ -31,3 +31,5 @@ Where 'this is the text' will be returned, together with the path and line numbe
|
|
31
31
|
You can also use the options *--dir, -d*, in order to specify the directory in which
|
32
32
|
todos are going to be looked for, and *--ext -e* for checking only certain file extension
|
33
33
|
(without prepending the '.', this means, call *--ext rb* instead of *--ext .rb*).
|
34
|
+
You can optionally ignore casing for your *TODO* comments, in which case you may
|
35
|
+
pass the option *--ignorecase, -i*.
|
data/bin/wnow
CHANGED
@@ -9,9 +9,11 @@ class Wnow < Thor
|
|
9
9
|
desc 'find', 'search files in directory for todo elements (default command)'
|
10
10
|
option :dir, aliases: '-d'
|
11
11
|
option :ext, aliases: '-e'
|
12
|
+
option :ignorecase, aliases: '-i'
|
12
13
|
def find
|
13
14
|
dir = options[:dir] || Dir.pwd
|
14
15
|
ext = options[:ext] ? "/**/*.#{options[:ext]}" : '/**/*.*'
|
16
|
+
WhatNow.ignorecase if options[:ignorecase]
|
15
17
|
todos = WhatNow.search_directory(dir + ext)
|
16
18
|
todos.each do |t|
|
17
19
|
printable_path = options[:dir] ? t.path : t.path[Dir.pwd.length+1..t.path.length]
|
data/lib/what_now.rb
CHANGED
@@ -2,32 +2,33 @@
|
|
2
2
|
|
3
3
|
require 'ptools'
|
4
4
|
|
5
|
+
# TODO this struct should know how to print itself
|
5
6
|
Todo = Struct.new :text, :path, :line
|
6
7
|
|
7
8
|
module WhatNow
|
8
9
|
class << self
|
10
|
+
|
11
|
+
def ignorecase
|
12
|
+
@ignorecase = true
|
13
|
+
end
|
14
|
+
|
9
15
|
def search_line(line, line_number, path)
|
10
|
-
|
16
|
+
regex = @ignorecase ? /TODO:?\s*(.+)$/i : /TODO:?\s*(.+)$/
|
17
|
+
text = regex.match(line)
|
11
18
|
Todo.new(text[1], line_number, path) if text
|
12
19
|
end
|
13
20
|
|
14
21
|
def search_file(path)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
todos << result if result
|
20
|
-
end
|
21
|
-
end
|
22
|
-
todos
|
22
|
+
return [] if File.binary? path
|
23
|
+
File.open(path).each_with_index.map do |line, i|
|
24
|
+
search_line(line, path, i+1)
|
25
|
+
end.delete_if { |l| l.nil? }
|
23
26
|
end
|
24
27
|
|
25
28
|
def search_directory(pattern)
|
26
|
-
|
27
|
-
|
28
|
-
todos = todos + search_file(file)
|
29
|
+
Dir[pattern].flat_map do |file|
|
30
|
+
search_file(file)
|
29
31
|
end
|
30
|
-
todos
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
data/spec/what_now_spec.rb
CHANGED
@@ -11,17 +11,40 @@ end
|
|
11
11
|
|
12
12
|
describe WhatNow do
|
13
13
|
describe '#search_line' do
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
describe 'with case sensitivity' do
|
15
|
+
subject do
|
16
|
+
WhatNow.search_line('TODO this is a todo', 1, '.')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'correctly extracts text from todo' do
|
20
|
+
subject.text.must_match 'this is a todo'
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
23
|
+
it 'returns nil with a non todo line' do
|
24
|
+
WhatNow.search_line('this is not a todo', 1, '.')
|
25
|
+
.must_be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns nil in a downcase todo' do
|
29
|
+
WhatNow.search_line('todo this is not a todo', 1, '.')
|
30
|
+
.must_be_nil
|
31
|
+
end
|
20
32
|
end
|
21
33
|
|
22
|
-
|
23
|
-
|
24
|
-
.
|
34
|
+
describe 'with case insensitivity' do
|
35
|
+
before do
|
36
|
+
WhatNow.ignorecase
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'extracts the text from the TODO in uppercase' do
|
40
|
+
WhatNow.search_line('TODO this is a todo', 1, '.')
|
41
|
+
.text.must_match 'this is a todo'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'extracts the text from the TODO in downcase' do
|
45
|
+
WhatNow.search_line('todo this is a todo', 1, '.')
|
46
|
+
.text.must_match 'this is a todo'
|
47
|
+
end
|
25
48
|
end
|
26
49
|
end
|
27
50
|
|
data/what_now.gemspec
CHANGED