preek 0.1.3 → 1.0.0

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: 23aaf624b23cc383b727443a4638f9d8974465ff
4
- data.tar.gz: ba4e3c93bd89f810a2ff58b8d76373fc39153f19
3
+ metadata.gz: 2300b0792702884ce539a9e7204c06f31fc1dcae
4
+ data.tar.gz: 5150fd3103a539732308a852c8efeb07abde9a9c
5
5
  SHA512:
6
- metadata.gz: f8e069e0498d2879120117dca4c13a4679981bef8757a0fe6293705a0c43d69971b64c3c0d7b30717e628601f8f00962b8b586fd9101c346646056732a9fa2ad
7
- data.tar.gz: 331ad8be448eb115fc52bc5ef25f719af4a4f71ac4bc670fcd1d75c7e5b022015e6d7339353fa312ee20c7caac37f075ebd14728ffc1755ed7b5dcf8cb8e0b88
6
+ metadata.gz: d112cda98c69d5b28fd531d64a104e2576f1e656dc1c34adbff5b8f0d6491a342fbe54157201b1a8f99b9f9559db5a4fac7e09f87e084514b5786bffd9caa4dd
7
+ data.tar.gz: 3f8db5a1be25a4125ee1a23b292fd896b024002ac972a68fcf0c1e7d6805abf501169a582db549276edbf6780e14710492bf8736bac81eff3a69aee5226652ae
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/preek.png)](http://badge.fury.io/rb/preek)
1
2
  [![Code Climate](https://codeclimate.com/github/joenas/preek.png)](https://codeclimate.com/github/joenas/preek)
2
3
  [![Build Status](https://travis-ci.org/joenas/preek.png)](https://travis-ci.org/joenas/preek)
3
4
  [![Dependency Status](https://gemnasium.com/joenas/preek.png)](https://gemnasium.com/joenas/preek)
@@ -26,8 +27,19 @@ or
26
27
 
27
28
 
28
29
  ## Usage
30
+ ```bash
31
+ Usage:
32
+ preek smell FILE(S)|DIR
29
33
 
30
- $ preek . or file
34
+ Options:
35
+ -i, [--irresponsible] # include IrresponsibleModule smell in output.
36
+
37
+
38
+ Commands:
39
+ preek help [COMMAND] # Describe available commands or one specific command
40
+ preek smell FILE(S)|DIR # Pretty format Reek output
41
+ preek version # Shows version
42
+ ```
31
43
 
32
44
  At the moment it only supports files, not stuff like this:
33
45
 
data/bin/preek CHANGED
@@ -1,14 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "preek"
3
+ require "preek/cli"
3
4
 
4
- # unless ARGV.empty?
5
- # preek = Preek::Preek.new
6
- # if preek.respond_to? ARGV[0]
7
- # preek.send ARGV.shift.to_sym, ARGV
8
- # else
9
- # preek.parse ARGV
10
- # end
11
- # else
12
- # Preek::Preek.start
13
- # end
14
- Preek::Preek.start
5
+ Preek::CLI.start
data/lib/preek.rb CHANGED
@@ -1,56 +1,8 @@
1
1
  module Preek
2
- require 'reek'
3
2
  require 'thor'
3
+
4
4
  require 'preek/version'
5
5
  require 'preek/smell_collector'
6
6
  require 'preek/smell_reporter'
7
- require 'preek/smell_warning'
8
- # whoop whoop
9
- class Preek < Thor
10
- include Thor::Actions
11
-
12
- desc 'version', 'Shows version'
13
- def version(*)
14
- say VERSION
15
- end
16
-
17
- desc 'smell FILE(S)|DIR', 'Pretty format Reek output'
18
- method_option :irresponsible,
19
- type: :boolean,
20
- aliases: '-i',
21
- desc: 'include IrresponsibleModule smell in output.'
22
- def smell(*args)
23
- args ||= @args
24
- @includes = options.keys.map {|key| _aliases[key.to_sym] }
25
- files, @not_files = args.partition { |file| File.exists? file }
26
- report_smells_for(files, excludes) unless files.empty?
27
- report_not_files
28
- end
29
-
30
- private
31
- def report_smells_for(files, includes)
32
- sources = Reek::Source::SourceLocator.new(files).all_sources
33
- smelly_files = SmellCollector.new(sources, excludes).smelly_files
34
- @reporter = SmellReporter.new(smelly_files)
35
- @reporter.print_smells
36
- end
37
-
38
- def report_not_files
39
- say_status :error, "No such file(s) - #{@not_files*", "}.", :red unless @not_files.empty?
40
- end
41
-
42
- def _aliases
43
- {
44
- irresponsible: 'IrresponsibleModule'
45
- }
46
- end
47
-
48
- def excludes
49
- (exclude_list - @includes)#.map(&:to_s).map(&:capitalize)
50
- end
51
7
 
52
- def exclude_list
53
- %w(IrresponsibleModule)
54
- end
55
- end
56
8
  end
data/lib/preek/cli.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'thor'
2
+
3
+ require 'preek/version'
4
+ require 'preek/smell_collector'
5
+ require 'preek/smell_reporter'
6
+
7
+ module Preek
8
+
9
+ # whoop whoop
10
+ class CLI < Thor
11
+ include Thor::Actions
12
+
13
+ desc 'version', 'Shows version'
14
+ def version(*)
15
+ say VERSION
16
+ end
17
+
18
+ desc 'smell FILE(S)|DIR', 'Pretty format Reek output'
19
+ method_option :irresponsible,
20
+ type: :boolean,
21
+ aliases: '-i',
22
+ desc: 'include IrresponsibleModule smell in output.'
23
+ def smell(*args)
24
+ args ||= @args
25
+ @includes = options.keys.map {|key| _aliases[key.to_sym] }
26
+ @files, @not_files = args.partition { |file| File.exists? file }
27
+ report_smells
28
+ report_not_files
29
+ end
30
+
31
+ private
32
+ def report_smells
33
+ return if @files.empty?
34
+ smelly_files = SmellCollector.new(@files, excludes).smelly_files
35
+ SmellReporter.new(smelly_files).print_smells
36
+ end
37
+
38
+ def report_not_files
39
+ return if @not_files.empty?
40
+ say_status :error, "No such file(s) - #{@not_files.join(', ')}.", :red
41
+ end
42
+
43
+ def _aliases
44
+ {
45
+ irresponsible: 'IrresponsibleModule'
46
+ }
47
+ end
48
+
49
+ def excludes
50
+ (exclude_list - @includes)
51
+ end
52
+
53
+ def exclude_list
54
+ %w(IrresponsibleModule)
55
+ end
56
+ end
57
+ end
@@ -1,24 +1,32 @@
1
+ require 'reek'
2
+
3
+ require 'preek/ext/smell_warning'
4
+
5
+ require 'preek/smell_file'
6
+ require 'preek/smell_klass'
7
+
1
8
  module Preek
2
- require 'reek'
3
- require 'preek/smell_file'
4
9
  # This is a 'Collector'
5
10
  class SmellCollector
6
- def initialize(sources, excludes)
7
- @sources = sources
11
+ def initialize(files, excludes)
12
+ @files = files
8
13
  @excludes = excludes
9
- @files = examine_sources
10
14
  end
11
15
 
12
16
  def smelly_files
13
- @files.compact#reject(&:nil?)
17
+ @smelly_files ||= examine_sources
14
18
  end
15
19
 
16
20
  private
17
21
  def examine_sources
18
- @sources.map do |source|
22
+ sources.map do |source|
19
23
  smells = Reek::Examiner.new(source).smells
20
24
  SmellFile.new(smells, @excludes) unless smells.empty?
21
- end
25
+ end.compact
26
+ end
27
+
28
+ def sources
29
+ Reek::Source::SourceLocator.new(@files).all_sources
22
30
  end
23
31
  end
24
32
  end
@@ -1,28 +1,31 @@
1
1
  module Preek
2
- require 'preek/klass_collector'
3
2
  # A smelly file
4
3
  class SmellFile
4
+ attr_reader :klasses
5
+
5
6
  def initialize(smells, excludes)
6
7
  @smells = smells
7
8
  @excludes = excludes
8
- @klass_collector = KlassCollector.new
9
- add_smells_to_klass
10
- end
11
-
12
- def klasses
13
- @klass_collector.get_klasses
9
+ @klasses = {}
10
+ add_smells_to_klasses
14
11
  end
15
12
 
16
13
  def file
17
14
  @smells.first.source
18
15
  end
19
16
 
17
+ alias :filename :file
18
+
20
19
  private
21
- def add_smells_to_klass
20
+ def add_smells_to_klasses
22
21
  @smells.each do |smell|
23
22
  next if @excludes.include? smell.smell_class
24
- @klass_collector.find(smell.klass).add_smell smell
23
+ find(smell.klass).add smell
25
24
  end
26
25
  end
26
+
27
+ def find(klassname)
28
+ @klasses[klassname.to_sym] ||= SmellKlass.new
29
+ end
27
30
  end
28
31
  end
@@ -5,7 +5,7 @@ module Preek
5
5
  @smells = []
6
6
  end
7
7
 
8
- def add_smell smell
8
+ def add(smell)
9
9
  @smells << smell
10
10
  end
11
11
 
@@ -14,10 +14,7 @@ module Preek
14
14
  end
15
15
 
16
16
  def smells
17
- @smells.map do |smell|
18
- smell.smell_string
19
- #FormatedSmell.new(smell).print_data
20
- end
17
+ @smells.map(&:smell_string)
21
18
  end
22
19
  end
23
20
  end
@@ -1,21 +1,22 @@
1
+ require 'thor/shell/color'
1
2
  module Preek
2
3
  # Here we report the smells in a nice fashion
3
4
  class SmellReporter < Thor::Shell::Color
4
5
  def initialize smelly_files
5
- @smelly_files = smelly_files
6
+ @smelly_files = smelly_files.delete_if {|smell_file| smell_file.klasses.empty? }
6
7
  @padding = 0
7
8
  end
8
9
 
9
10
  def print_smells
10
- @smelly_files.delete_if {|smell_file| smell_file.klasses.empty? }
11
11
  return say_status 'success!', 'No smells detected.' if @smelly_files.empty?
12
12
  print_line
13
- @smelly_files.each do |smell|
14
- say_status 'file', format_path(smell.file), :blue
15
- print_klasses smell.klasses
13
+ @smelly_files.each do |smelly|
14
+ say_status 'file', format_path(smelly.filename), :blue
15
+ print_klasses smelly.klasses
16
16
  end
17
17
  end
18
18
  private
19
+
19
20
  def print_klasses klasses
20
21
  klasses.each do |index, klass|
21
22
  say_status "\n\tclass", klass.name
@@ -38,7 +39,7 @@ module Preek
38
39
  def padding; 0; end
39
40
 
40
41
  def format_path file
41
- File.expand_path(file)#.gsub(Dir.pwd, ".")
42
+ File.expand_path(file)
42
43
  end
43
44
  end
44
45
  end
data/lib/preek/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Preek
2
- VERSION = "0.1.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,13 @@
1
+ module CaptureHelper
2
+ def capture(stream)
3
+ begin
4
+ stream = stream.to_s
5
+ eval "$#{stream} = StringIO.new"
6
+ yield
7
+ result = eval("$#{stream}").string
8
+ ensure
9
+ eval("$#{stream} = #{stream.upcase}")
10
+ end
11
+ result
12
+ end
13
+ end
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
+ require 'capture_helper'
3
+ require 'preek/cli'
2
4
 
3
- describe Preek::Preek do
5
+ describe Preek::CLI do
6
+ include CaptureHelper
4
7
 
5
8
  def test_file(file_name)
6
9
  File.expand_path(File.join(File.dirname(__FILE__),'test_files/',"#{file_name}.rb"))
@@ -14,7 +17,7 @@ describe Preek::Preek do
14
17
  end
15
18
 
16
19
  describe "#parse" do
17
- let(:output) { capture(:stdout) { subject.parse(*args) } }
20
+ let(:output) { capture(:stdout) { subject.smell(*args) } }
18
21
  let(:args) { ['i/am/not/a_file'] }
19
22
 
20
23
  context "with non-existing file in ARGS" do
data/spec/spec_helper.rb CHANGED
@@ -11,16 +11,4 @@ RSpec.configure do |config|
11
11
  config.filter_run :focus
12
12
  config.order = 'random'
13
13
  config.fail_fast = true
14
-
15
- def capture(stream)
16
- begin
17
- stream = stream.to_s
18
- eval "$#{stream} = StringIO.new"
19
- yield
20
- result = eval("$#{stream}").string
21
- ensure
22
- eval("$#{stream} = #{stream.upcase}")
23
- end
24
- result
25
- end
26
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preek
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Neverland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-19 00:00:00.000000000 Z
11
+ date: 2013-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -126,15 +126,16 @@ files:
126
126
  - Rakefile
127
127
  - bin/preek
128
128
  - lib/preek.rb
129
- - lib/preek/klass_collector.rb
129
+ - lib/preek/cli.rb
130
+ - lib/preek/ext/smell_warning.rb
130
131
  - lib/preek/smell_collector.rb
131
132
  - lib/preek/smell_file.rb
132
133
  - lib/preek/smell_klass.rb
133
134
  - lib/preek/smell_reporter.rb
134
- - lib/preek/smell_warning.rb
135
135
  - lib/preek/version.rb
136
136
  - preek.gemspec
137
- - spec/preek_spec.rb
137
+ - spec/capture_helper.rb
138
+ - spec/cli_spec.rb
138
139
  - spec/spec_helper.rb
139
140
  - spec/test_files/irresponsible.rb
140
141
  - spec/test_files/irresponsible_and_lazy.rb
@@ -162,12 +163,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  version: '0'
163
164
  requirements: []
164
165
  rubyforge_project:
165
- rubygems_version: 2.0.3
166
+ rubygems_version: 2.0.2
166
167
  signing_key:
167
168
  specification_version: 4
168
169
  summary: It might reek but its pretty
169
170
  test_files:
170
- - spec/preek_spec.rb
171
+ - spec/capture_helper.rb
172
+ - spec/cli_spec.rb
171
173
  - spec/spec_helper.rb
172
174
  - spec/test_files/irresponsible.rb
173
175
  - spec/test_files/irresponsible_and_lazy.rb
@@ -1,17 +0,0 @@
1
- module Preek
2
- require 'preek/smell_klass'
3
- # This keeps track of classes in a smelly file
4
- class KlassCollector
5
- def initialize
6
- @klasses = {}
7
- end
8
-
9
- def find(klassname)
10
- @klasses[klassname.to_sym] ||= SmellKlass.new
11
- end
12
-
13
- def get_klasses
14
- @klasses
15
- end
16
- end
17
- end