what_now 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/wnow +6 -7
- data/lib/todo.rb +24 -0
- data/lib/what_now.rb +33 -22
- data/spec/todo_spec.rb +33 -0
- data/spec/what_now_spec.rb +34 -24
- data/what_now.gemspec +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c129b4ea1aed4491608b1aa54462eb469f06f69b
|
4
|
+
data.tar.gz: 25a68c0f5b0fd9048c495cdb18447050f846a43f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16dec7d805e9ba4759b3b2835b597e7e31f57bed8828b74dbd3d00d8a8116db1e0d1425e881e12a1027c06aa962ea51c73ad3386abdf8fb3b5748107cab4652a
|
7
|
+
data.tar.gz: 73ef733a215b66af92f7d3fadbc9b9deaed33be14f273480a4601273d2650a289ae05a29f17969e510e9e4a6855e08afb9c61203466ee2706fb8846cb1acb739
|
data/bin/wnow
CHANGED
@@ -13,13 +13,12 @@ class Wnow < Thor
|
|
13
13
|
def find
|
14
14
|
dir = options[:dir] || Dir.pwd
|
15
15
|
ext = options[:ext] ? "/**/*.#{options[:ext]}" : '/**/*.*'
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
puts
|
21
|
-
puts
|
22
|
-
puts
|
16
|
+
creator = TodoCreator.new(
|
17
|
+
ignorecase: options[:ignorecase],
|
18
|
+
pretty: STDOUT.tty?)
|
19
|
+
TodoFinder.new(dir + ext, creator).find.each do |todo|
|
20
|
+
puts todo
|
21
|
+
puts if STDOUT.tty?
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
data/lib/todo.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Contains the abstractions related
|
2
|
+
# to todo's objects
|
3
|
+
require 'colorize'
|
4
|
+
|
5
|
+
class Todo
|
6
|
+
attr_reader :text, :path, :line
|
7
|
+
|
8
|
+
def initialize text, path, line
|
9
|
+
@text = text
|
10
|
+
@path = path
|
11
|
+
@line = line
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"#{@text} at line #{@line} in #{@path}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class PrettyTodo < Todo
|
20
|
+
def to_s
|
21
|
+
"#{@text.red.bold}\nat line #{@line.to_s.blue} in #{@path.blue.underline}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/what_now.rb
CHANGED
@@ -1,34 +1,45 @@
|
|
1
1
|
# What_now definitions
|
2
2
|
|
3
3
|
require 'ptools'
|
4
|
+
require 'todo'
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
class TodoCreator
|
7
|
+
def initialize(opts={})
|
8
|
+
pretty = opts.fetch(:pretty, true)
|
9
|
+
@ignorecase = opts[:ignorecase]
|
10
|
+
@todo_class = pretty ? PrettyTodo : Todo
|
11
|
+
end
|
7
12
|
|
8
|
-
|
9
|
-
|
13
|
+
def match(line, path, line_number)
|
14
|
+
regex = @ignorecase ? /TODO:?\s*(.+)$/i : /TODO:?\s*(.+)$/
|
15
|
+
text = regex.match(line)
|
16
|
+
@todo_class.new(text[1], shortened_path(path), line_number) if text
|
17
|
+
rescue ArgumentError
|
18
|
+
nil
|
19
|
+
end
|
10
20
|
|
11
|
-
|
12
|
-
|
13
|
-
|
21
|
+
private
|
22
|
+
def shortened_path(path)
|
23
|
+
path[Dir.pwd.length+1..path.length]
|
24
|
+
end
|
25
|
+
end
|
14
26
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
27
|
+
class TodoFinder
|
28
|
+
def initialize(pattern, creator)
|
29
|
+
@paths = Dir[pattern].delete_if do |path|
|
30
|
+
File.directory?(path) || File.binary?(path)
|
19
31
|
end
|
32
|
+
@creator = creator
|
33
|
+
end
|
20
34
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
search_line(line, path, i+1)
|
25
|
-
end.delete_if { |l| l.nil? }
|
26
|
-
end
|
35
|
+
def find
|
36
|
+
@paths.flat_map { |file| search_file(file) }
|
37
|
+
end
|
27
38
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
39
|
+
private
|
40
|
+
def search_file(path)
|
41
|
+
File.open(path).each_with_index.map do |line, i|
|
42
|
+
@creator.match(line, path, i+1)
|
43
|
+
end.delete_if { |l| l.nil? }
|
33
44
|
end
|
34
45
|
end
|
data/spec/todo_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
describe Todo do
|
5
|
+
subject { Todo.new('do stuff', './stuff', 10) }
|
6
|
+
|
7
|
+
describe 'public interface' do
|
8
|
+
it { subject.must_respond_to :text }
|
9
|
+
it { subject.must_respond_to :path }
|
10
|
+
it { subject.must_respond_to :line }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#to_s' do
|
14
|
+
it 'should respond with a simple task description' do
|
15
|
+
subject.to_s.must_equal "do stuff at line 10 in ./stuff"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe PrettyTodo do
|
21
|
+
subject { PrettyTodo.new('do stuff', './stuff', 10) }
|
22
|
+
|
23
|
+
it 'shoul be a Todo' do
|
24
|
+
subject.must_be_kind_of Todo
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'correctly formats the output' do
|
28
|
+
output = subject.text.red.bold + "\n"
|
29
|
+
output += "at line #{subject.line.to_s.blue} in #{subject.path.blue.underline}"
|
30
|
+
subject.to_s.must_equal output
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/spec/what_now_spec.rb
CHANGED
@@ -1,57 +1,63 @@
|
|
1
1
|
require_relative 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe '
|
5
|
-
subject { Todo.new('do stuff', './stuff', 10) }
|
6
|
-
it { subject.must_respond_to :text }
|
7
|
-
it { subject.must_respond_to :path }
|
8
|
-
it { subject.must_respond_to :line }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe WhatNow do
|
13
|
-
describe '#search_line' do
|
3
|
+
describe TodoCreator do
|
4
|
+
describe '#match' do
|
14
5
|
describe 'with case sensitivity' do
|
15
6
|
subject do
|
16
|
-
|
7
|
+
TodoCreator.new
|
17
8
|
end
|
18
9
|
|
19
10
|
it 'correctly extracts text from todo' do
|
20
|
-
subject.
|
11
|
+
subject.match('TODO this is a todo', '.', 1)
|
12
|
+
.text.must_match 'this is a todo'
|
21
13
|
end
|
22
14
|
|
23
15
|
it 'returns nil with a non todo line' do
|
24
|
-
|
16
|
+
subject.match('this is not a todo', '.', 1)
|
25
17
|
.must_be_nil
|
26
18
|
end
|
27
19
|
|
28
20
|
it 'returns nil in a downcase todo' do
|
29
|
-
|
21
|
+
subject.match('todo this is not a todo', '.', 1)
|
30
22
|
.must_be_nil
|
31
23
|
end
|
32
24
|
end
|
33
25
|
|
34
26
|
describe 'with case insensitivity' do
|
35
|
-
|
36
|
-
|
27
|
+
subject do
|
28
|
+
TodoCreator.new ignorecase: true
|
37
29
|
end
|
38
30
|
|
39
31
|
it 'extracts the text from the TODO in uppercase' do
|
40
|
-
|
32
|
+
subject.match('TODO this is a todo', '.', 1)
|
41
33
|
.text.must_match 'this is a todo'
|
42
34
|
end
|
43
35
|
|
44
36
|
it 'extracts the text from the TODO in downcase' do
|
45
|
-
|
37
|
+
subject.match('todo this is a todo', '.', 1)
|
46
38
|
.text.must_match 'this is a todo'
|
47
39
|
end
|
48
40
|
end
|
41
|
+
|
42
|
+
describe 'object type returned' do
|
43
|
+
it 'default should be pretty' do
|
44
|
+
TodoCreator.new.match('TODO this is a todo', '.', 1)
|
45
|
+
.must_be_instance_of PrettyTodo
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'non pretty can be specified' do
|
49
|
+
TodoCreator.new(pretty: false).match('TODO this is a todo', '.', 1)
|
50
|
+
.must_be_instance_of Todo
|
51
|
+
end
|
52
|
+
end
|
49
53
|
end
|
54
|
+
end
|
50
55
|
|
51
|
-
|
56
|
+
describe TodoFinder do
|
57
|
+
describe 'search single file' do
|
52
58
|
subject do
|
53
59
|
path = File.dirname(__FILE__) + '/example_file.txt'
|
54
|
-
|
60
|
+
TodoFinder.new(path, TodoCreator.new).find
|
55
61
|
end
|
56
62
|
|
57
63
|
it 'found 2 todos' do
|
@@ -66,14 +72,18 @@ describe WhatNow do
|
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
|
-
describe '
|
75
|
+
describe 'search with a pattern' do
|
70
76
|
it 'considers only specified pattern' do
|
71
|
-
results =
|
77
|
+
results = TodoFinder.new(
|
78
|
+
File.dirname(__FILE__)+'/**/*.txt',
|
79
|
+
TodoCreator.new).find
|
72
80
|
results.length.must_equal 2
|
73
81
|
end
|
74
82
|
|
75
83
|
it 'returns empty array if nothing was found' do
|
76
|
-
results =
|
84
|
+
results = TodoFinder.new(
|
85
|
+
File.dirname(__FILE__)+'/**/*.mooo',
|
86
|
+
TodoCreator.new).find
|
77
87
|
results.must_equal []
|
78
88
|
end
|
79
89
|
end
|
data/what_now.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what_now
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar Cabrera
|
@@ -90,9 +90,11 @@ files:
|
|
90
90
|
- LICENSE
|
91
91
|
- README.md
|
92
92
|
- bin/wnow
|
93
|
+
- lib/todo.rb
|
93
94
|
- lib/what_now.rb
|
94
95
|
- spec/example_file.txt
|
95
96
|
- spec/spec_helper.rb
|
97
|
+
- spec/todo_spec.rb
|
96
98
|
- spec/what_now_spec.rb
|
97
99
|
- what_now.gemspec
|
98
100
|
homepage: https://github.com/aleandros/what_now
|
@@ -120,6 +122,7 @@ signing_key:
|
|
120
122
|
specification_version: 4
|
121
123
|
summary: Find todo comments in your code
|
122
124
|
test_files:
|
123
|
-
- spec/spec_helper.rb
|
124
125
|
- spec/what_now_spec.rb
|
125
126
|
- spec/example_file.txt
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
- spec/todo_spec.rb
|