chrisjpowers-rdoc_metric 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.
- data/LICENSE +19 -0
- data/README.rdoc +26 -0
- data/bin/rdoc_metric +8 -0
- data/lib/rdoc_metric.rb +108 -0
- metadata +65 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2009 Chris Powers
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
= RdocMetric
|
|
2
|
+
|
|
3
|
+
<em>A gem for analyzing how much of your Ruby code is documented with Rdoc.</em>
|
|
4
|
+
|
|
5
|
+
Developed by Chris Powers (http://github.com/chrisjpowers)
|
|
6
|
+
|
|
7
|
+
Version 0.1 -- September 10, 2009
|
|
8
|
+
|
|
9
|
+
The RdocMetric class parses through ruby files and determines how
|
|
10
|
+
well documented they are. It looks for an rdoc comment for
|
|
11
|
+
each class, module, method, attribute and constant declaration to
|
|
12
|
+
determine if documentation exists.
|
|
13
|
+
|
|
14
|
+
The gem installs the <tt>rdoc_metric</tt> command line program. You
|
|
15
|
+
can use it without any arguments to parse all the ruby files in the
|
|
16
|
+
current directory and all subdirectories, or you can pass it a
|
|
17
|
+
specific path.
|
|
18
|
+
|
|
19
|
+
$ rdoc_metric
|
|
20
|
+
|
|
21
|
+
or
|
|
22
|
+
|
|
23
|
+
$ rdoc_metric my_app/app/models # only parses .rb files in models dir
|
|
24
|
+
|
|
25
|
+
So far this is a very rudimentary implementation, so please feel
|
|
26
|
+
free to fork and improve!
|
data/bin/rdoc_metric
ADDED
data/lib/rdoc_metric.rb
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Developed by Chris Powers (http://github.com/chrisjpowers)
|
|
2
|
+
# Version 0.1 -- September 10, 2009
|
|
3
|
+
#
|
|
4
|
+
# The RdocMetric class parses through ruby files and determines how
|
|
5
|
+
# well documented they are. It looks for a comment on the line before
|
|
6
|
+
# each class, module, method, attribute and constant declaration to
|
|
7
|
+
# determine if documentation exists.
|
|
8
|
+
#
|
|
9
|
+
# Calling the #to_s method will output a list of all the parsed files,
|
|
10
|
+
# displaying how many of each declaration were documented, along with
|
|
11
|
+
# an overall percentage of coverage.
|
|
12
|
+
#
|
|
13
|
+
# Currently there is no weight given to classes vs. methods vs. constants,
|
|
14
|
+
# the percentage is simply based on the overall entity count.
|
|
15
|
+
#
|
|
16
|
+
class RdocMetric
|
|
17
|
+
|
|
18
|
+
# Accepts a path that is sent to Dir.glob
|
|
19
|
+
#
|
|
20
|
+
# Ex: <tt>RdocMetric.new("/apps/my_app/**/*.rb")
|
|
21
|
+
def initialize(path)
|
|
22
|
+
files = Dir.glob(path)
|
|
23
|
+
@files = files.map {|f| RdocFile.new(f) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# The overall percentage of coverage as an integer
|
|
27
|
+
def score
|
|
28
|
+
@files.inject(0) {|sum, file| sum += file.score } / @files.length
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Outputs the full listing of rdoc coverage for all parsed files.
|
|
32
|
+
def to_s
|
|
33
|
+
out = "* * * Total Rdoc Coverage: #{score}% * * *\n\n"
|
|
34
|
+
return out + @files.map(&:to_s).join("\n") + "\n" + out
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# models a single parsed file
|
|
39
|
+
class RdocFile
|
|
40
|
+
def initialize(filepath)
|
|
41
|
+
@filepath = filepath
|
|
42
|
+
@methods = []
|
|
43
|
+
@classes = []
|
|
44
|
+
@modules = []
|
|
45
|
+
@attrs = []
|
|
46
|
+
@constants = []
|
|
47
|
+
parse_file!
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Percentage of rdoc coverage for this file as an Integer
|
|
51
|
+
def score
|
|
52
|
+
total = 0
|
|
53
|
+
docs = 0
|
|
54
|
+
[@classes, @modules, @methods, @constants, @attrs].each do |collection|
|
|
55
|
+
collection.each do |item|
|
|
56
|
+
total += 1
|
|
57
|
+
docs += 1 if item
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
return 100 if total == 0
|
|
61
|
+
return ((docs.to_f / total) * 100).to_i
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Outputs the coverage breakdown message for this file.
|
|
65
|
+
def to_s
|
|
66
|
+
out = "Rdoc Coverage for #{@filepath}: #{score}%\n"
|
|
67
|
+
out += " Classes: #{@classes.select{|c| c }.length}/#{@classes.length}\n" unless @classes.empty?
|
|
68
|
+
out += " Modules: #{@modules.select{|c| c }.length}/#{@modules.length}\n" unless @modules.empty?
|
|
69
|
+
out += " Methods: #{@methods.select{|c| c }.length}/#{@methods.length}\n" unless @methods.empty?
|
|
70
|
+
out += " Attributes: #{@attrs.select{|c| c }.length}/#{@attrs.length}\n" unless @attrs.empty?
|
|
71
|
+
out += " Constants: #{@constants.select{|c| c }.length}/#{@constants.length}\n" unless @constants.empty?
|
|
72
|
+
out
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
# Parses through file, adds true or false entries into collections
|
|
78
|
+
# as it encounters documented and undocumented declarations, respectively
|
|
79
|
+
def parse_file!
|
|
80
|
+
File.open(@filepath, 'r') do |f|
|
|
81
|
+
last_line = ''
|
|
82
|
+
while this_line = f.gets
|
|
83
|
+
coll = case this_line
|
|
84
|
+
when /^\s*def / : @methods
|
|
85
|
+
when /^\s*class / : @classes
|
|
86
|
+
when /^\s*module / : @modules
|
|
87
|
+
when /^\s*(attr_reader|attr_accessor|attr_writer) / : @attrs
|
|
88
|
+
when /^\s*[^a-z =]+\s*=/ : @constants
|
|
89
|
+
else nil
|
|
90
|
+
end
|
|
91
|
+
# add a true entry if comment precedes declaration or follows on same line
|
|
92
|
+
coll << is_comment?(last_line) || has_comment?(this_line) if coll
|
|
93
|
+
last_line = this_line
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Does the line start with a # ?
|
|
99
|
+
def is_comment?(line)
|
|
100
|
+
line =~ /^\s*#/
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Does the line have a # anywhere on it?
|
|
104
|
+
def has_comment?(line)
|
|
105
|
+
line =~ /#[^{]/
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: chrisjpowers-rdoc_metric
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Chris Powers
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-09-10 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: RdocMetric analyzes the Rdoc coverage of Ruby files.
|
|
17
|
+
email: chrisjpowers@gmail.com
|
|
18
|
+
executables:
|
|
19
|
+
- rdoc_metric
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README.rdoc
|
|
24
|
+
files:
|
|
25
|
+
- LICENSE
|
|
26
|
+
- README.rdoc
|
|
27
|
+
- bin/rdoc_metric
|
|
28
|
+
- lib/rdoc_metric.rb
|
|
29
|
+
has_rdoc: true
|
|
30
|
+
homepage: http://github.com/chrisjpowers/rdoc_metric
|
|
31
|
+
licenses:
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options:
|
|
34
|
+
- --quiet
|
|
35
|
+
- --title
|
|
36
|
+
- RdocMetric documentation
|
|
37
|
+
- --opname
|
|
38
|
+
- index.html
|
|
39
|
+
- --line-numbers
|
|
40
|
+
- --main
|
|
41
|
+
- README.rdoc
|
|
42
|
+
- --inline-source
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: "0"
|
|
50
|
+
version:
|
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: "0"
|
|
56
|
+
version:
|
|
57
|
+
requirements: []
|
|
58
|
+
|
|
59
|
+
rubyforge_project:
|
|
60
|
+
rubygems_version: 1.3.5
|
|
61
|
+
signing_key:
|
|
62
|
+
specification_version: 3
|
|
63
|
+
summary: RdocMetric analyzes the Rdoc coverage of Ruby files.
|
|
64
|
+
test_files: []
|
|
65
|
+
|