Permalink
Browse files

Use statistics from Suggest command for badge numbers

This patch updates the badge generation process to use the objects determined
by Inch::API::Suggest (instead of all objects in the codebase).

The reasons:

* the badges should mimick the output of `inch suggest` rather than `inch stats`
* to encourage people to document their code, low priority objects should
  not count against the overall assessment of the badge

After this change, low priority objects (like private methods and objects marked
as :nodoc: or @private) are no longer relevant for the badge generator.
(They are however still displayed in the status page, which continues to give
the complete picture.)
1 parent 2d07181 commit 51555d50d21e234fa240fc9920cf7c27310ff542 @rrrene committed Feb 25, 2014
Showing with 23 additions and 5 deletions.
  1. +23 −5 _plugins/inch/pages/repo.rb
@@ -8,7 +8,9 @@ def all
end
def badge_numbers
- grade_lists.map { |list| list.objects.size }
+ grade_lists.map do |list|
+ relevant_objects_graded(list.grade).size
+ end
end
def description
@@ -62,6 +64,10 @@ def to_liquid
private
+ def codebase
+ @codebase ||= Inch::Codebase.parse(local_path)
+ end
+
def file?(filename)
File.exists?( File.join(localpath, filename) )
end
@@ -85,10 +91,7 @@ def git_url
end
def list
- @list ||= begin
- codebase = Inch::Codebase.parse(local_path)
- Inch::API::List.new(codebase, {})
- end
+ @list ||= Inch::API::List.new(codebase, {})
end
def liquify_objects(objects)
@@ -110,9 +113,24 @@ def object_count
@object_count ||= list.objects.size
end
+ # Returns only objects with non-negative priority
+ def relevant_objects
+ suggest.all_objects
+ end
+
+ def relevant_objects_graded(grade)
+ relevant_objects.select do |object|
+ object.grade == grade
+ end
+ end
+
def repo_name
name.split('/').last
end
+
+ def suggest
+ @suggest ||= Inch::API::Suggest.new(codebase, {})
+ end
end
end
end

0 comments on commit 51555d5

Please sign in to comment.