rubycritic 0.0.15 → 0.0.16

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: 68c58782f25f2ad071d05ae5060034e4f2b77832
4
- data.tar.gz: 61ae75fea93cde03f7e9ab378e363f345eb8f184
3
+ metadata.gz: 5a43f9d486a902fa7eda73e1df3e492cdb6ab085
4
+ data.tar.gz: a29c16803a4e83f4b559065630b024b76b45a69c
5
5
  SHA512:
6
- metadata.gz: 15a35a6440ba6536d6989451ec60d0d8037303e93c47049aaa73c05846ea65f22bad0517084510811ed9cfa794acf86f0f5dc512cee37320841cff402fb381ba
7
- data.tar.gz: 493ebc3d9f648e39ca5869d397dfcd4af1bc5facb5c1a669eda9a358bce67f85c21b93c7781ae8dbce3a9c4a34bdf98b8df788c08964e5214affb957a081edd6
6
+ metadata.gz: d0720b07a319110c0cb31dc6c5ca1ec69fef4eb60d7759069ba1e1e869a16f537d1e7d49553aa5ca544ccc91993c481f16f6fe7da2abe8917358499f952e2436
7
+ data.tar.gz: 05e48772690e0230b7e8d5788751204e754ccaaf0c4e40d72a4e5520fc0bad81ddc3f87a09f141d9a494372de94ae9c1e6df5adf808d2b765de22a3ae23294d1
@@ -13,11 +13,12 @@ module Rubycritic
13
13
  end
14
14
 
15
15
  def root=(path)
16
- @root = if Pathname(path).relative?
17
- File.expand_path(path)
18
- else
19
- path
20
- end
16
+ @root =
17
+ if Pathname(path).relative?
18
+ File.expand_path(path)
19
+ else
20
+ path
21
+ end
21
22
  end
22
23
  end
23
24
  end
@@ -31,9 +31,11 @@ module Rubycritic
31
31
  end
32
32
 
33
33
  def complexity_per_method
34
- complexity.fdiv(methods_count).round(1)
35
- rescue ZeroDivisionError
36
- "N/A"
34
+ if methods_count == 0
35
+ "N/A"
36
+ else
37
+ complexity.fdiv(methods_count).round(1)
38
+ end
37
39
  end
38
40
 
39
41
  def has_smells?
@@ -23,7 +23,7 @@ module Rubycritic
23
23
  end
24
24
 
25
25
  def file_directory
26
- root_directory
26
+ @file_directory ||= root_directory
27
27
  end
28
28
 
29
29
  def file_name
@@ -34,6 +34,12 @@ module Rubycritic
34
34
  raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
35
35
  end
36
36
 
37
+ private
38
+
39
+ def root_directory
40
+ @root_directory ||= Pathname.new(::Rubycritic.configuration.root)
41
+ end
42
+
37
43
  def get_binding
38
44
  binding
39
45
  end
@@ -14,7 +14,7 @@ module Rubycritic
14
14
  end
15
15
 
16
16
  def file_directory
17
- File.join(root_directory, @pathname.dirname)
17
+ @file_directory ||= root_directory + @pathname.dirname
18
18
  end
19
19
 
20
20
  def file_name
@@ -26,7 +26,7 @@ module Rubycritic
26
26
  File.readlines(@pathname).each.with_index(LINE_NUMBER_OFFSET) do |line_text, line_number|
27
27
  location = Location.new(@pathname, line_number)
28
28
  line_smells = @analysed_file.smells_at_location(location)
29
- file_code << Line.new(line_text, line_smells).render
29
+ file_code << Line.new(file_directory, line_text, line_smells).render
30
30
  end
31
31
 
32
32
  file_body = TEMPLATE.result(get_binding { file_code })
@@ -5,7 +5,7 @@ module Rubycritic
5
5
 
6
6
  class CurrentCodeFile < CodeFile
7
7
  def file_directory
8
- root_directory
8
+ @file_directory ||= root_directory
9
9
  end
10
10
 
11
11
  def file_name
@@ -8,7 +8,10 @@ module Rubycritic
8
8
  NORMAL_TEMPLATE = erb_template("line.html.erb")
9
9
  SMELLY_TEMPLATE = erb_template("smelly_line.html.erb")
10
10
 
11
- def initialize(text, smells)
11
+ attr_reader :file_directory
12
+
13
+ def initialize(file_directory, text, smells)
14
+ @file_directory = file_directory
12
15
  @text = CGI::escapeHTML(text.chomp)
13
16
  @smells = smells
14
17
  @template =
@@ -13,7 +13,7 @@
13
13
  <% @analysed_files.each do |analysed_file| %>
14
14
  <tr>
15
15
  <td class="first-cell">
16
- <a href="<%= file_path(analysed_file.pathname) %>"><%= analysed_file.name %></a>
16
+ <a href="<%= file_path(analysed_file.pathname.sub_ext('.html')) %>"><%= analysed_file.name %></a>
17
17
  </td>
18
18
  <td class="numeric-cell"><%= analysed_file.churn %></td>
19
19
  <td class="numeric-cell"><%= analysed_file.complexity %></td>
@@ -10,11 +10,11 @@
10
10
  </head>
11
11
  <body>
12
12
  <header class="project-header group">
13
- <h1 class="logo"><a href="<%= file_path('overview') %>" class="logo-link">RubyCritic</a></h1>
13
+ <h1 class="logo"><a href="<%= file_path('overview.html') %>" class="logo-link">RubyCritic</a></h1>
14
14
  <nav class="project-nav">
15
- <a href="<%= file_path('overview') %>" class="project-nav-item">Overview</a>
16
- <a href="<%= file_path('code_index') %>" class="project-nav-item">Code</a>
17
- <a href="<%= file_path('smells_index') %>" class="project-nav-item">Smells</a>
15
+ <a href="<%= file_path('overview.html') %>" class="project-nav-item">Overview</a>
16
+ <a href="<%= file_path('code_index.html') %>" class="project-nav-item">Code</a>
17
+ <a href="<%= file_path('smells_index.html') %>" class="project-nav-item">Smells</a>
18
18
  </nav>
19
19
  </header>
20
20
  <%= yield %>
@@ -8,27 +8,37 @@ module Rubycritic
8
8
  end
9
9
 
10
10
  def javascript_tag(file)
11
- "<script src='" + asset_path(File.join("javascripts", "#{file}.js")) + "'></script>"
11
+ "<script src='" + asset_path("javascripts", "#{file}.js").to_s + "'></script>"
12
12
  end
13
13
 
14
14
  def stylesheet_path(file)
15
- asset_path(File.join("stylesheets", "#{file}.css"))
15
+ asset_path("stylesheets", "#{file}.css")
16
16
  end
17
17
 
18
- def asset_path(file)
19
- File.join(root_directory, "assets", file)
18
+ def asset_path(*fragments)
19
+ relative_path(([root_directory, "assets"] + fragments).reduce(:+))
20
20
  end
21
21
 
22
22
  def file_path(file)
23
- File.join(root_directory, Pathname(file).sub_ext(".html"))
23
+ relative_path(root_directory + file)
24
24
  end
25
25
 
26
26
  def smell_location_path(location)
27
- File.join(root_directory, "#{location.pathname.sub_ext('.html')}#L#{location.line}")
27
+ relative_path(root_directory + "#{location.pathname.sub_ext('.html')}#L#{location.line}")
28
+ end
29
+
30
+ private
31
+
32
+ def relative_path(pathname)
33
+ pathname.relative_path_from(file_directory)
34
+ end
35
+
36
+ def file_directory
37
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
28
38
  end
29
39
 
30
40
  def root_directory
31
- ::Rubycritic.configuration.root
41
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
32
42
  end
33
43
  end
34
44
 
@@ -1,3 +1,3 @@
1
1
  module Rubycritic
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycritic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Simoes