lutra 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 120c9b5137a29993b0cf99cf77d4fd973ca5c6dc
4
- data.tar.gz: 129e3e23967864255313f50b34a202ca299bf4d0
3
+ metadata.gz: 7337112eafc3be539708c9e4ca191af02a8948cd
4
+ data.tar.gz: b3d62818e4b3ef41951f905d6ac8ae1e01b19da7
5
5
  SHA512:
6
- metadata.gz: 2eca1f7883a4068402aef57296caa1d031f7d2e69e7dd88e911e53723c055b424b7ab32b728fb20381910b180b748a3353900c30009528882b9190e6a059e590
7
- data.tar.gz: 05f875eb64f93cc561629ade90eac7fb4800ec968c4cf05e3555cdb5bdf8f5c4ea1b590d9db301259399d6be8cf835bb7074cd8295c533b5c2b8418430c97d3a
6
+ metadata.gz: 2fe4243548f43a30468271ff6c718519331955f499c09c0f305f8451b4080e0d07bbac6c7dd45bca0f08de7e98be233547189cf6289839a7e469b8c93efd1242
7
+ data.tar.gz: 02733a43a2d7c3e2958bdf02feb18f9871cd584980a11c76d0b32c2a72b51017f97d0d20bdf2703fe2f3830d8a1cbc44f98b3b3d8f4d4608a85adf4c7a537086
data/bin/lutra CHANGED
@@ -9,7 +9,6 @@ color = STDOUT.tty?
9
9
  usage = 'Usage: lutra [OPTIONS] [PATH]'
10
10
  tags = Lutra::TAGS
11
11
  comments = Lutra::COMMENTS
12
- formatter_name = :default
13
12
  formatter_opts = {}
14
13
 
15
14
  ARGV.options do |o|
@@ -24,10 +23,6 @@ ARGV.options do |o|
24
23
  comments = com.split(',').map(&:strip)
25
24
  end
26
25
 
27
- o.on('-f', '--formatter=NAME', 'Use your own formatter') do |name|
28
- formatter_name = name.to_sym
29
- end
30
-
31
26
  o.on('-s', '--text-size=SIZE', 'Set text size for formatter') do |size|
32
27
  formatter_opts[:text_size] = size.to_i
33
28
  end
@@ -55,7 +50,8 @@ rescue => e
55
50
  exit 1
56
51
  end
57
52
 
58
- scanner = Lutra::Scanner.new(tags: tags, comments: comments)
53
+ formatter = Lutra::Formatters::Default.new(formatter_opts)
54
+ scanner = Lutra::Scanner.new(formatter)
59
55
 
60
56
  Find.find(*paths) do |path|
61
57
  unless paths.include?(path)
@@ -65,7 +61,7 @@ Find.find(*paths) do |path|
65
61
  next if File.directory?(path)
66
62
 
67
63
  begin
68
- scanner.scan_file(path)
64
+ scanner.scan_file(path, tags, comments)
69
65
  rescue Errno::ENOENT => e
70
66
  STDERR.puts "lutra: #{e.message} (broken symlink?)" if verbose
71
67
  rescue => e
@@ -73,8 +69,4 @@ Find.find(*paths) do |path|
73
69
  end
74
70
  end
75
71
 
76
- formatter = Lutra::Formatter.new(formatter_opts)
77
- formatter.set(formatter_name)
78
- formatter.display(scanner.notes)
79
-
80
72
  exit
@@ -1,5 +1,4 @@
1
1
  require 'lutra/scanner'
2
- require 'lutra/formatter'
3
2
  require 'lutra/formatters/base'
4
3
  require 'lutra/formatters/default'
5
4
 
@@ -10,5 +9,4 @@ module Lutra
10
9
  NotImplementedError = Class.new(StandardError)
11
10
  EmptyTagListError = Class.new(StandardError)
12
11
  EmptyCommentListError = Class.new(StandardError)
13
- FormatterNotFound = Class.new(StandardError)
14
12
  end
@@ -2,31 +2,31 @@ require 'lutra/note'
2
2
 
3
3
  module Lutra
4
4
  class Scanner
5
- attr_accessor :tags, :comments
6
- attr_reader :notes
5
+ attr_reader :formatter
7
6
 
8
- def initialize(tags: Lutra::TAGS, comments: Lutra::COMMENTS)
9
- raise EmptyTagListError if tags.empty?
10
- raise EmptyCommentListError if comments.empty?
11
-
12
- @tags, @comments = tags, comments
13
- @notes = []
7
+ def initialize(formatter = Formatters::Default.new)
8
+ @formatter = formatter
14
9
  end
15
10
 
16
- def scan_file(path)
17
- extract(File.open(path), path)
11
+ def scan_file(path, tags, comments)
12
+ notes = extract(File.open(path), path, tags, comments)
13
+
14
+ formatter.display(notes)
18
15
  end
19
16
 
20
17
  private
21
18
 
22
- def extract(source, path)
23
- regexp = compile_regexp(@comments, @tags)
19
+ def extract(source, path, tags, comments)
20
+ regexp = compile_regexp(comments, tags)
21
+ notes = []
24
22
 
25
23
  source.each_with_index do |line, i|
26
24
  if result = regexp.match(line)
27
- @notes << Note.new(result[:tag], result[:comment], result[:text], i + 1, path)
25
+ notes << Note.new(result[:tag], result[:comment], result[:text], i + 1, path)
28
26
  end
29
27
  end
28
+
29
+ notes
30
30
  end
31
31
 
32
32
  def compile_regexp(comments, tags)
@@ -1,3 +1,3 @@
1
1
  module Lutra
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -4,46 +4,36 @@ describe Lutra::Scanner do
4
4
  context '.new' do
5
5
  subject { described_class }
6
6
 
7
- it 'default tags' do
8
- expect(subject.new.tags).to eq(['TODO', 'FIXME', 'OPTIMIZE'])
9
- end
10
-
11
- it 'custom tags' do
12
- expect(subject.new(tags: ['X']).tags).to eq(['X'])
13
- end
14
-
15
- it 'default comments' do
16
- expect(subject.new.comments).to eq(['#', '%', ';', '//', '--'])
17
- end
18
-
19
- it 'custom comments' do
20
- expect(subject.new(comments: ['#']).comments).to eq(['#'])
7
+ it 'default formatter' do
8
+ expect(subject.new.formatter).to be_a(Lutra::Formatters::Default)
21
9
  end
22
10
  end
23
11
 
24
- context '#scan_file' do
25
- let(:filename) { data_file('sample') }
26
- let(:notes) { subject.notes }
12
+ context '#extract' do
13
+ let(:path) { data_file('sample') }
14
+ let(:file) { File.open(path) }
15
+ let(:tags) { Lutra::TAGS }
16
+ let(:comm) { Lutra::COMMENTS }
27
17
 
28
- before { subject.scan_file(filename) }
18
+ subject { described_class.new.send(:extract, file, path, tags, comm) }
29
19
 
30
20
  it 'have todo, fixme and optimize' do
31
- expect(notes.map(&:tag)).to eq(['TODO', 'FIXME', 'OPTIMIZE'])
21
+ expect(subject.map(&:tag)).to eq(['TODO', 'FIXME', 'OPTIMIZE'])
32
22
  end
33
23
 
34
24
  context 'with custom tags' do
35
- subject { described_class.new(tags: ['TODO']) }
25
+ let(:tags) { ['TODO'] }
36
26
 
37
27
  it 'returns notes with only specified tag' do
38
- expect(notes.map(&:tag)).to eq(['TODO'])
28
+ expect(subject.map(&:tag)).to eq(['TODO'])
39
29
  end
40
30
  end
41
31
 
42
32
  context 'with custom comments' do
43
- subject { described_class.new(comments: ['#']) }
33
+ let(:comm) { ['#'] }
44
34
 
45
35
  it 'returns notes with only specified comments' do
46
- expect(notes.map(&:comment)).to eq(['#'])
36
+ expect(subject.map(&:comment)).to eq(['#'])
47
37
  end
48
38
  end
49
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Artemev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse tags (todo, fixme, optimize) in your source code
14
14
  email:
@@ -22,8 +22,6 @@ files:
22
22
  - README.md
23
23
  - bin/lutra
24
24
  - lib/lutra.rb
25
- - lib/lutra/formatter.rb
26
- - lib/lutra/formatter_entry.rb
27
25
  - lib/lutra/formatters/base.rb
28
26
  - lib/lutra/formatters/default.rb
29
27
  - lib/lutra/note.rb
@@ -31,7 +29,6 @@ files:
31
29
  - lib/lutra/version.rb
32
30
  - lutra.gemspec
33
31
  - spec/fixtures/sample
34
- - spec/lib/formatter_spec.rb
35
32
  - spec/lib/formatters/base_spec.rb
36
33
  - spec/lib/formatters/default_spec.rb
37
34
  - spec/lib/scanner_spec.rb
@@ -64,7 +61,6 @@ specification_version: 4
64
61
  summary: In source annotaions parser
65
62
  test_files:
66
63
  - spec/fixtures/sample
67
- - spec/lib/formatter_spec.rb
68
64
  - spec/lib/formatters/base_spec.rb
69
65
  - spec/lib/formatters/default_spec.rb
70
66
  - spec/lib/scanner_spec.rb
@@ -1,47 +0,0 @@
1
- require 'lutra/formatter_entry'
2
-
3
- module Lutra
4
- class Formatter
5
- attr_reader :formatters, :current
6
-
7
- def initialize(options = {})
8
- @options = options
9
- @current = :default
10
- @formatters = [default_formatter]
11
- end
12
-
13
- def get(name)
14
- @formatters.find do |f|
15
- f.name == name || f.short == name
16
- end
17
- end
18
-
19
- def set(name)
20
- if get(name)
21
- @current = name
22
- else
23
- raise FormatterNotFound
24
- end
25
- end
26
-
27
- def add(name, short_name, class_name)
28
- if formatter?(class_name)
29
- @formatters << FormatterEntry.new(name, short_name, class_name)
30
- end
31
- end
32
-
33
- def display(notes)
34
- get(@current).class_name.new(@options).display(notes)
35
- end
36
-
37
- private
38
-
39
- def formatter?(class_name)
40
- class_name.new.respond_to?(:display)
41
- end
42
-
43
- def default_formatter
44
- FormatterEntry.new(:default, :d, Lutra::Formatters::Default)
45
- end
46
- end
47
- end
@@ -1,3 +0,0 @@
1
- module Lutra
2
- FormatterEntry = Struct.new(:name, :short, :class_name)
3
- end
@@ -1,48 +0,0 @@
1
- describe Lutra::Formatter do
2
- context '.new' do
3
- it 'have one formatter' do
4
- expect(subject.formatters.size).to eq(1)
5
- end
6
-
7
- it 'have default formatter' do
8
- expect(subject.formatters.first[:name]).to eq(:default)
9
- end
10
- end
11
-
12
- context '#add' do
13
- it 'adds new formatter' do
14
- expect(subject.add(:new, :n, Lutra::Formatters::Default).size).to eq(2)
15
- end
16
- end
17
-
18
- context '#get' do
19
- it 'finds formatter by name' do
20
- expect(subject.get(:default)[:name]).to eq(:default)
21
- end
22
-
23
- it 'finds formatter short name' do
24
- expect(subject.get(:d)[:name]).to eq(:default)
25
- end
26
- end
27
-
28
- context '#set' do
29
- it 'sets default formatter' do
30
- subject.set(:default)
31
- expect(subject.current).to eq(:default)
32
- end
33
-
34
- it 'raise error when formatter dont exist' do
35
- expect {
36
- subject.set(:poke)
37
- }.to raise_error(Lutra::FormatterNotFound)
38
- end
39
- end
40
-
41
- context '#display' do
42
- let(:out) { capture_stdout { subject.display([]) } }
43
-
44
- it 'prints notes with selected formatter' do
45
- expect(out).to eq('')
46
- end
47
- end
48
- end