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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a13ab4077826fea72978ebdc4df7590224becb4
4
- data.tar.gz: 4cbc448fe9fed549a45158f1e958490783b42827
3
+ metadata.gz: 22e94ada9391a63cbcf79bb1d3a4ca9f6f6962e2
4
+ data.tar.gz: ad69ca1e8fac29ee9e76c27177e98c082a27b6b2
5
5
  SHA512:
6
- metadata.gz: 7f845892a4cae2342b01ff3e31b8ae8efba71b57551b396c8c88bb2aea35a7529a3db13eebc17436210f471f10f9956d0701a2db902a5a15905e80dae81f1be2
7
- data.tar.gz: c5dccc5be39cade9d1f0ae61af352ed70a8da55fea24d29c030c39d60100d5afcda1f5ba5448a1ea7e6e70b0c31c273acef6c89f0b8f11fe3611840e8ddc34d1
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
- text = /TODO:?\s*(.+)$/i.match(line)
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
- todos = []
16
- unless File.binary?(path)
17
- File.open(path).each_with_index do |line, i|
18
- result = search_line(line, path, i+1)
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
- todos = []
27
- Dir[pattern].each do |file|
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
@@ -11,17 +11,40 @@ end
11
11
 
12
12
  describe WhatNow do
13
13
  describe '#search_line' do
14
- subject do
15
- WhatNow.search_line('TODO this is a todo', 1, '.')
16
- end
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
- it 'correctly extracts text from todo' do
19
- subject.text.must_match 'this is a todo'
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
- it 'returns nil with a non todo line' do
23
- WhatNow.search_line('this is not a todo', 1, '.')
24
- .must_be_nil
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'what_now'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.4'
4
4
  s.date = '2014-02-27'
5
5
  s.summary = 'Find todo comments in your code'
6
6
  s.description = 'Executable for finding todo comments on directories'
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgar Cabrera