2008-01-13 22:34:05 -05:00
|
|
|
require 'rdoc'
|
|
|
|
|
|
|
|
##
|
2010-04-01 03:45:16 -04:00
|
|
|
# RDoc stats collector
|
2008-01-13 22:34:05 -05:00
|
|
|
|
|
|
|
class RDoc::Stats
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
attr_reader :nodoc_constants
|
|
|
|
attr_reader :nodoc_methods
|
|
|
|
|
|
|
|
attr_reader :num_constants
|
2008-07-21 14:35:14 -04:00
|
|
|
attr_reader :num_files
|
|
|
|
attr_reader :num_methods
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
attr_reader :total_files
|
|
|
|
|
|
|
|
def initialize(total_files, verbosity = 1)
|
|
|
|
@nodoc_constants = 0
|
|
|
|
@nodoc_methods = 0
|
|
|
|
|
|
|
|
@num_constants = 0
|
|
|
|
@num_files = 0
|
|
|
|
@num_methods = 0
|
|
|
|
|
|
|
|
@total_files = total_files
|
2008-01-13 22:34:05 -05:00
|
|
|
|
|
|
|
@start = Time.now
|
2008-07-21 14:35:14 -04:00
|
|
|
|
|
|
|
@display = case verbosity
|
2010-04-01 03:45:16 -04:00
|
|
|
when 0 then Quiet.new total_files
|
|
|
|
when 1 then Normal.new total_files
|
|
|
|
else Verbose.new total_files
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def begin_adding
|
|
|
|
@display.begin_adding
|
|
|
|
end
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def add_alias(as)
|
|
|
|
@display.print_alias as
|
|
|
|
@num_methods += 1
|
2010-04-01 03:45:16 -04:00
|
|
|
@nodoc_methods += 1 if as.document_self and as.comment.empty?
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_class(klass)
|
|
|
|
@display.print_class klass
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_constant(constant)
|
|
|
|
@display.print_constant constant
|
|
|
|
@num_constants += 1
|
|
|
|
@nodoc_constants += 1 if constant.document_self and constant.comment.empty?
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_file(file)
|
2010-04-01 03:45:16 -04:00
|
|
|
@display.print_file @num_files, file
|
2008-07-21 14:35:14 -04:00
|
|
|
@num_files += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_method(method)
|
|
|
|
@display.print_method method
|
|
|
|
@num_methods += 1
|
2010-04-01 03:45:16 -04:00
|
|
|
@nodoc_methods += 1 if method.document_self and method.comment.empty?
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_module(mod)
|
|
|
|
@display.print_module mod
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def done_adding
|
|
|
|
@display.done_adding
|
2008-01-13 22:34:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def print
|
2010-04-01 03:45:16 -04:00
|
|
|
classes = RDoc::TopLevel.classes
|
|
|
|
num_classes = classes.length
|
|
|
|
nodoc_classes = classes.select do |klass|
|
|
|
|
klass.document_self and klass.comment.empty?
|
|
|
|
end.length
|
|
|
|
|
|
|
|
modules = RDoc::TopLevel.modules
|
|
|
|
num_modules = modules.length
|
|
|
|
nodoc_modules = modules.select do |mod|
|
|
|
|
mod.document_self and mod.comment.empty?
|
|
|
|
end.length
|
|
|
|
|
|
|
|
items = num_classes + @num_constants + num_modules + @num_methods
|
|
|
|
doc_items = items -
|
|
|
|
nodoc_classes - @nodoc_constants - nodoc_modules - @nodoc_methods
|
|
|
|
|
|
|
|
percent_doc = doc_items.to_f / items * 100
|
|
|
|
|
|
|
|
puts "Files: %5d" % @num_files
|
|
|
|
puts "Classes: %5d (%5d undocumented)" % [num_classes, nodoc_classes]
|
|
|
|
puts "Constants: %5d (%5d undocumented)" %
|
|
|
|
[@num_constants, @nodoc_constants]
|
|
|
|
puts "Modules: %5d (%5d undocumented)" % [num_modules, nodoc_modules]
|
|
|
|
puts "Methods: %5d (%5d undocumented)" % [@num_methods, @nodoc_methods]
|
|
|
|
puts "%6.2f%% documented" % percent_doc
|
|
|
|
puts
|
|
|
|
puts "Elapsed: %0.1fs" % (Time.now - @start)
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# Stats printer that prints nothing
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
class Quiet
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def initialize total_files
|
|
|
|
@total_files = total_files
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Prints a message at the beginning of parsing
|
|
|
|
|
|
|
|
def begin_adding(*) end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Prints when an alias is added
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def print_alias(*) end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Prints when a class is added
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def print_class(*) end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Prints when a constant is added
|
|
|
|
|
|
|
|
def print_constant(*) end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Prints when a file is added
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def print_file(*) end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Prints when a method is added
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def print_method(*) end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Prints when a module is added
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def print_module(*) end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Prints when RDoc is done
|
|
|
|
|
|
|
|
def done_adding(*) end
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# Stats printer that prints just the files being documented with a progress
|
|
|
|
# bar
|
|
|
|
|
|
|
|
class Normal < Quiet
|
|
|
|
|
|
|
|
def begin_adding # :nodoc:
|
|
|
|
puts "Parsing sources..."
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# Prints a file with a progress bar
|
|
|
|
|
|
|
|
def print_file(files_so_far, filename)
|
|
|
|
progress_bar = sprintf("%3d%% [%2d/%2d] ",
|
|
|
|
100 * (files_so_far + 1) / @total_files,
|
|
|
|
files_so_far + 1,
|
|
|
|
@total_files)
|
|
|
|
|
|
|
|
if $stdout.tty?
|
|
|
|
# Print a progress bar, but make sure it fits on a single line. Filename
|
|
|
|
# will be truncated if necessary.
|
|
|
|
terminal_width = (ENV['COLUMNS'] || 80).to_i
|
|
|
|
max_filename_size = terminal_width - progress_bar.size
|
|
|
|
if filename.size > max_filename_size
|
|
|
|
# Turn "some_long_filename.rb" to "...ong_filename.rb"
|
|
|
|
filename = filename[(filename.size - max_filename_size) .. -1]
|
|
|
|
filename[0..2] = "..."
|
|
|
|
end
|
|
|
|
|
|
|
|
# Pad the line with whitespaces so that leftover output from the
|
|
|
|
# previous line doesn't show up.
|
|
|
|
line = "#{progress_bar}#{filename}"
|
|
|
|
padding = terminal_width - line.size
|
|
|
|
line << (" " * padding) if padding > 0
|
|
|
|
|
|
|
|
$stdout.print("#{line}\r")
|
|
|
|
$stdout.flush
|
|
|
|
else
|
|
|
|
puts "#{progress_bar} #{filename}"
|
|
|
|
end
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def done_adding # :nodoc:
|
|
|
|
puts
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Stats printer that prints everything documented, including the documented
|
|
|
|
# status
|
|
|
|
|
|
|
|
class Verbose < Normal
|
|
|
|
|
|
|
|
##
|
|
|
|
# Returns a marker for RDoc::CodeObject +co+ being undocumented
|
|
|
|
|
|
|
|
def nodoc co
|
|
|
|
" (undocumented)" unless co.documented?
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def print_alias as # :nodoc:
|
|
|
|
puts "\t\talias #{as.new_name} #{as.old_name}#{nodoc as}"
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def print_class(klass) # :nodoc:
|
|
|
|
puts "\tclass #{klass.full_name}#{nodoc klass}"
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def print_constant(constant) # :nodoc:
|
|
|
|
puts "\t\t#{constant.name}#{nodoc constant}"
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def print_file(files_so_far, file) # :nodoc:
|
|
|
|
super
|
|
|
|
puts
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def print_method(method) # :nodoc:
|
|
|
|
puts "\t\t#{method.singleton ? '::' : '#'}#{method.name}#{nodoc method}"
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def print_module(mod) # :nodoc:
|
|
|
|
puts "\tmodule #{mod.full_name}#{nodoc mod}"
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|