rubycritic 0.0.5 → 0.0.6

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: e3de50932159be5b26bc5a2cf4afe9eeec17e8dc
4
- data.tar.gz: c7f9620aae8d000fe5f674844158d48296c706c3
3
+ metadata.gz: ff62ecc1acf094e82a10bf40ef08f3e99f503994
4
+ data.tar.gz: b72615619b79aeff062110b689f0795768a81ab4
5
5
  SHA512:
6
- metadata.gz: 28d945ef0e7036d298e1c8ff54b909c7c4c67b777e6ccfad20c548905ccb515fe849c351866b38bbba6765dfd31af610d41ae6c6cede57e469db3b54ee4f44bb
7
- data.tar.gz: 509b8ffc4b0cdcb85cccacbbe242a5a5bc5f0e06e2975d12ac3827d9f168c0426793bcde26d4c48cf953e49ff41ba0039dce216428e8a94f009ba0e964f21522
6
+ metadata.gz: 678cf22b3f926a270505432a1c7c473d782b05e93b647c3cb0754c25d606d35a76ff7af26d44182bfaeeddbc5845e07a8a6c219228b880f562940e5f8b1ec814
7
+ data.tar.gz: 46abcfc03b41e1824bc7acdd017955a2850095faf8ed3996cb698615e74f34d01ef108727dee9df7095d754bbf23c55ca4bdba6fa890106f33fd9893d1d570fb
@@ -0,0 +1,36 @@
1
+ module Rubycritic
2
+
3
+ module ActiveSupport
4
+ def constantize(camel_cased_word)
5
+ names = camel_cased_word.split('::')
6
+
7
+ # Trigger a built-in NameError exception including the ill-formed constant in the message.
8
+ Object.const_get(camel_cased_word) if names.empty?
9
+
10
+ # Remove the first blank element in case of '::ClassName' notation.
11
+ names.shift if names.size > 1 && names.first.empty?
12
+
13
+ names.inject(Object) do |constant, name|
14
+ if constant == Object
15
+ constant.const_get(name)
16
+ else
17
+ candidate = constant.const_get(name)
18
+ next candidate if constant.const_defined?(name, false)
19
+ next candidate unless Object.const_defined?(name)
20
+
21
+ # Go down the ancestors to check it it's owned
22
+ # directly before we reach Object or the end of ancestors.
23
+ constant = constant.ancestors.inject do |const, ancestor|
24
+ break const if ancestor == Object
25
+ break ancestor if ancestor.const_defined?(name, false)
26
+ const
27
+ end
28
+
29
+ # owner is in Object, so raise
30
+ constant.const_get(name, false)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -1,9 +1,12 @@
1
+ require "rubycritic/active_support/methods"
1
2
  require "rubycritic/analysers/reek"
2
3
  require "rubycritic/smell_adapters/reek"
3
4
 
4
5
  module Rubycritic
5
6
 
6
7
  class AnalysersRunner
8
+ include ActiveSupport
9
+
7
10
  ANALYSERS = ["Reek"]
8
11
 
9
12
  def initialize(paths)
@@ -11,15 +14,15 @@ module Rubycritic
11
14
  end
12
15
 
13
16
  def run
14
- smell_adapters
17
+ run_analysers_and_instantiate_adapters
15
18
  end
16
19
 
17
20
  private
18
21
 
19
- def smell_adapters
22
+ def run_analysers_and_instantiate_adapters
20
23
  ANALYSERS.map do |analyser_name|
21
- analyser = Object.const_get("Rubycritic::Analyser::#{analyser_name}").new(@paths)
22
- Object.const_get("Rubycritic::SmellAdapter::#{analyser_name}").new(analyser)
24
+ analyser = constantize("Rubycritic::Analyser::#{analyser_name}").new(@paths)
25
+ constantize("Rubycritic::SmellAdapter::#{analyser_name}").new(analyser)
23
26
  end
24
27
  end
25
28
  end
@@ -15,7 +15,7 @@ module Rubycritic
15
15
  end
16
16
 
17
17
  def file_directory
18
- File.join(REPORT_DIR, File.dirname(@pathname))
18
+ File.join(REPORT_DIR, @pathname.dirname)
19
19
  end
20
20
 
21
21
  def file_name
@@ -6,9 +6,9 @@
6
6
  </thead>
7
7
  <tbody>
8
8
  <% @file_generators.each do |file_generator| %>
9
- <tr>
10
- <td><a href="<%= file_generator.file_pathname %>"><%= file_generator.analysed_file_name %></a></td>
11
- </tr>
9
+ <tr>
10
+ <td><a href="<%= file_generator.file_pathname %>"><%= file_generator.analysed_file_name %></a></td>
11
+ </tr>
12
12
  <% end %>
13
13
  </tbody>
14
14
  </table>
@@ -15,7 +15,7 @@ module Rubycritic
15
15
 
16
16
  def smell_location_path(location)
17
17
  pathname = location.pathname
18
- File.join(root_directory, File.dirname(pathname), "#{pathname.basename.sub_ext("")}.html#L#{location.line}")
18
+ File.join(root_directory, "#{pathname.sub_ext('.html')}#L#{location.line}")
19
19
  end
20
20
 
21
21
  def index_path
@@ -1,3 +1,3 @@
1
1
  module Rubycritic
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require "test_helper"
2
+ require "rubycritic/analysers_runner"
3
+
4
+ describe Rubycritic::AnalysersRunner do
5
+ describe "#run" do
6
+ it "returns an array containing smell adapters" do
7
+ smell_adapters = Rubycritic::AnalysersRunner.new("test/samples/location/file0.rb").run
8
+ smell_adapters.each { |adapter| adapter.must_respond_to(:smells) }
9
+ end
10
+ end
11
+ end
@@ -2,7 +2,7 @@ require "test_helper"
2
2
  require "rubycritic/smells_aggregator"
3
3
 
4
4
  describe Rubycritic::SmellsAggregator do
5
- context "when when analysing smelly files" do
5
+ context "when analysing smelly files" do
6
6
  before do
7
7
  @location1 = Rubycritic::Location.new("./foo", "42")
8
8
  @location2 = Rubycritic::Location.new("./bar", "23")
@@ -8,7 +8,7 @@ describe Rubycritic::SourceLocator do
8
8
  end
9
9
 
10
10
  describe "#paths" do
11
- it "finds a single path" do
11
+ it "finds a single file" do
12
12
  paths = ["file0.rb"]
13
13
  Rubycritic::SourceLocator.new(paths).paths.must_equal paths
14
14
  end
@@ -18,7 +18,7 @@ describe Rubycritic::SourceLocator do
18
18
  Rubycritic::SourceLocator.new(paths).paths.must_equal paths
19
19
  end
20
20
 
21
- it "finds all the paths" do
21
+ it "finds all the files" do
22
22
  paths = ["dir1/file1.rb", "file0.rb"]
23
23
  Rubycritic::SourceLocator.new(["."]).paths.must_equal paths
24
24
  end
@@ -40,7 +40,7 @@ describe Rubycritic::SourceLocator do
40
40
  end
41
41
 
42
42
  describe "#pathnames" do
43
- it "finds a single path" do
43
+ it "finds a single file" do
44
44
  path = "file0.rb"
45
45
  paths = [path]
46
46
  result = [Pathname.new(path)]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycritic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Simoes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -126,6 +126,7 @@ files:
126
126
  - SPEC.md
127
127
  - bin/rubycritic
128
128
  - lib/rubycritic.rb
129
+ - lib/rubycritic/active_support/methods.rb
129
130
  - lib/rubycritic/analysers/config.reek
130
131
  - lib/rubycritic/analysers/flog.rb
131
132
  - lib/rubycritic/analysers/reek.rb
@@ -160,6 +161,7 @@ files:
160
161
  - lib/rubycritic/source_locator.rb
161
162
  - lib/rubycritic/version.rb
162
163
  - rubycritic.gemspec
164
+ - test/lib/rubycritic/analysers_runner_test.rb
163
165
  - test/lib/rubycritic/location_test.rb
164
166
  - test/lib/rubycritic/metric_adapters/flog_adapter_test.rb
165
167
  - test/lib/rubycritic/metric_adapters/reek_adapter_test.rb
@@ -198,11 +200,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
200
  version: '0'
199
201
  requirements: []
200
202
  rubyforge_project:
201
- rubygems_version: 2.1.11
203
+ rubygems_version: 2.2.2
202
204
  signing_key:
203
205
  specification_version: 4
204
206
  summary: Ruby code smell detector
205
207
  test_files:
208
+ - test/lib/rubycritic/analysers_runner_test.rb
206
209
  - test/lib/rubycritic/location_test.rb
207
210
  - test/lib/rubycritic/metric_adapters/flog_adapter_test.rb
208
211
  - test/lib/rubycritic/metric_adapters/reek_adapter_test.rb