Class: YARD::CLI::Stats
- Inherits:
-
Yardoc
- Object
- Command
- YardoptsCommand
- Yardoc
- YARD::CLI::Stats
- Includes:
- Templates::Helpers::BaseHelper
- Defined in:
- lib/yard/cli/stats.rb
Overview
Constant Summary
- STATS_ORDER =
Maintains the order in which stats_for_ statistics methods should be printed.
[:files, :modules, :classes, :constants, :methods]
Instance Attribute Summary (collapse)
-
- (Array<String>) apis
inherited
from Yardoc
Keep track of which APIs are to be shown.
-
- (Array<String>) assets
inherited
from Yardoc
A list of assets to copy after generation.
-
- (Array<String>) excluded
inherited
from Yardoc
List of excluded paths (regexp matches).
-
- (Array<String>) files
inherited
from Yardoc
List of Ruby source files to process.
-
- (Boolean) generate
inherited
from Yardoc
Whether to generate output.
-
- (Boolean) has_markup
inherited
from Yardoc
Whether markup option was specified.
-
- (Array<String>) hidden_apis
inherited
from Yardoc
Keep track of which APIs are to be hidden.
-
- (Array<Symbol>) hidden_tags
inherited
from Yardoc
A list of tags to hide from templates.
-
- (Boolean) list
inherited
from Yardoc
Whether to print a list of objects.
-
- (Hash) options
inherited
from Yardoc
readonly
The hash of options passed to the template.
-
- (String) options_file
inherited
from YardoptsCommand
The options file name (defaults to YardoptsCommand::DEFAULT_YARDOPTS_FILE).
-
- (Boolean) parse
Whether to parse and load registry.
-
- (Boolean) save_yardoc
inherited
from Yardoc
Whether objects should be serialized to .yardoc db.
-
- (Boolean) statistics
inherited
from Yardoc
Whether to print statistics after parsing.
-
- (Boolean) use_cache
inherited
from Yardoc
Whether to use the existing yardoc db if the .yardoc already exists.
-
- (Boolean) use_document_file
inherited
from YardoptsCommand
Whether to parse options from .document.
-
- (Boolean) use_yardopts_file
inherited
from YardoptsCommand
Whether to parse options from .yardopts.
-
- (Array<Symbol>) visibilities
inherited
from Yardoc
Keep track of which visibilities are to be shown.
Attributes included from Templates::Helpers::BaseHelper
Instance Method Summary (collapse)
-
- (Array<CodeObjects::Base>) all_objects
All the parsed objects in the registry, removing any objects that are not visible (private, protected) depending on the arguments passed to the command.
- - (Object) description
-
- (Stats) initialize(parse = true)
constructor
A new instance of Stats.
-
- (void) output(name, data, undoc = nil)
Prints a statistic to standard out.
-
- (Object) print_statistics
Prints statistics for different object types.
-
- (Object) print_undocumented_objects
Prints list of undocumented objects.
-
- (void) run(*args)
Runs the commandline utility, parsing arguments and generating output if set.
-
- (Object) stats_for_classes
Statistics for classes.
-
- (Object) stats_for_constants
Statistics for constants.
-
- (Object) stats_for_files
Statistics for files.
-
- (Object) stats_for_methods
Statistics for methods.
-
- (Object) stats_for_modules
Statistics for modules.
Methods included from Templates::Helpers::BaseHelper
#format_object_title, #format_object_type, #format_source, #format_types, #globals, #h, #link_file, #link_include_file, #link_include_object, #link_object, #link_url, #linkify, #run_verifier
Constructor Details
- (Stats) initialize(parse = true)
Returns a new instance of Stats
17 18 19 20 21 22 |
# File 'lib/yard/cli/stats.rb', line 17 def initialize(parse = true) super() @parse = parse @undoc_list = nil @compact = false end |
Instance Attribute Details
- (Array<String>) assets Originally defined in class Yardoc
Returns a list of assets to copy after generation
- (Array<String>) excluded Originally defined in class Yardoc
Returns list of excluded paths (regexp matches)
- (Array<String>) files Originally defined in class Yardoc
Returns list of Ruby source files to process
- (Boolean) generate Originally defined in class Yardoc
Returns whether to generate output
- (Boolean) has_markup Originally defined in class Yardoc
Returns whether markup option was specified
- (Array<String>) hidden_apis Originally defined in class Yardoc
Keep track of which APIs are to be hidden
- (Array<Symbol>) hidden_tags Originally defined in class Yardoc
Returns a list of tags to hide from templates
- (Boolean) list Originally defined in class Yardoc
Returns whether to print a list of objects
- (Hash) options (readonly) Originally defined in class Yardoc
Returns the hash of options passed to the template.
- (String) options_file Originally defined in class YardoptsCommand
The options file name (defaults to DEFAULT_YARDOPTS_FILE)
- (Boolean) parse
Returns whether to parse and load registry
14 15 16 |
# File 'lib/yard/cli/stats.rb', line 14 def parse @parse end |
- (Boolean) save_yardoc Originally defined in class Yardoc
Returns whether objects should be serialized to .yardoc db
- (Boolean) statistics Originally defined in class Yardoc
Returns whether to print statistics after parsing
- (Boolean) use_cache Originally defined in class Yardoc
Returns whether to use the existing yardoc db if the .yardoc already exists. Also makes use of file checksums to parse only changed files.
- (Boolean) use_document_file Originally defined in class YardoptsCommand
Returns whether to parse options from .document
- (Boolean) use_yardopts_file Originally defined in class YardoptsCommand
Returns whether to parse options from .yardopts
Instance Method Details
- (Array<CodeObjects::Base>) all_objects
Returns all the parsed objects in the registry, removing any objects that are not visible (private, protected) depending on the arguments passed to the command.
99 100 101 |
# File 'lib/yard/cli/stats.rb', line 99 def all_objects @all_objects ||= run_verifier Registry.all end |
- (Object) description
24 25 26 |
# File 'lib/yard/cli/stats.rb', line 24 def description "Prints documentation statistics on a set of files" end |
- (void) output(name, data, undoc = nil)
This method returns an undefined value.
Prints a statistic to standard out. This method is optimized for getting Integer values, though it allows any data to be printed.
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/yard/cli/stats.rb', line 143 def output(name, data, undoc = nil) @total += data if data.is_a?(Integer) && undoc @undocumented += undoc if undoc.is_a?(Integer) if undoc data = ("%5s (% 5d undocumented)" % [data, undoc]) else data = "%5s" % data end log.puts("%-12s %s" % [name + ":", data]) end |
- (Object) print_statistics
Prints statistics for different object types
To add statistics for a specific type, add a method #stats_for_TYPE to this class that calls #output.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yard/cli/stats.rb', line 51 def print_statistics @total, @undocumented = 0, 0 meths = methods.map {|m| m.to_s }.grep(/^stats_for_/) STATS_ORDER.each do |meth| mname = "stats_for_#{meth}" if meths.include?(mname) send(mname) meths.delete(mname) end end meths.each {|m| send(m) } if @total == 0 total = 0 else total = (@total - @undocumented).to_f / @total.to_f * 100 end log.puts("% 3.2f%% documented" % total) end |
- (Object) print_undocumented_objects
Prints list of undocumented objects
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/yard/cli/stats.rb', line 71 def print_undocumented_objects return if !@undoc_list || @undoc_list.empty? log.puts log.puts "Undocumented Objects:" objects = @undoc_list.sort_by {|o| o.file } max = objects.sort_by {|o| o.path.length }.last.path.length if @compact objects.each do |object| log.puts("%-#{max}s (%s)" % [object.path, [object.file, object.line].compact.join(":")]) end else last_file = nil objects.each do |object| if object.file != last_file log.puts log.puts "(in file: #{object.file})" end log.puts object.path last_file = object.file end end end |
- (void) run(*args)
This method returns an undefined value.
Runs the commandline utility, parsing arguments and generating output if set.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/yard/cli/stats.rb', line 33 def run(*args) parse_arguments(*args) if use_cache Registry.load! elsif parse YARD.parse(files, excluded) Registry.save(use_cache) if save_yardoc end print_statistics print_undocumented_objects end |
- (Object) stats_for_classes
Statistics for classes
116 117 118 |
# File 'lib/yard/cli/stats.rb', line 116 def stats_for_classes output "Classes", *type_statistics(:class) end |
- (Object) stats_for_constants
Statistics for constants
121 122 123 |
# File 'lib/yard/cli/stats.rb', line 121 def stats_for_constants output "Constants", *type_statistics(:constant) end |
- (Object) stats_for_files
Statistics for files
104 105 106 107 108 |
# File 'lib/yard/cli/stats.rb', line 104 def stats_for_files files = [] all_objects.each {|o| files |= [o.file] } output "Files", files.size end |
- (Object) stats_for_methods
Statistics for methods
126 127 128 129 130 131 132 |
# File 'lib/yard/cli/stats.rb', line 126 def stats_for_methods objs = all_objects.select {|m| m.type == :method } objs.reject! {|m| m.is_alias? || !m.is_explicit? } undoc = objs.select {|m| m.docstring.blank? && !m.overridden_method } @undoc_list |= undoc if @undoc_list output "Methods", objs.size, undoc.size end |
- (Object) stats_for_modules
Statistics for modules
111 112 113 |
# File 'lib/yard/cli/stats.rb', line 111 def stats_for_modules output "Modules", *type_statistics(:module) end |