class YARD::CLI::Stats

@since 0.6.0

Constants

STATS_ORDER

Maintains the order in which stats_for_ statistics methods should be printed.

@see print_statistics

Attributes

parse[RW]

@return [Boolean] whether to parse and load registry

Public Class Methods

new(parse = true) click to toggle source

@param [Boolean] parse whether to parse and load registry (see {#parse})

Calls superclass method
# File lib/yard/cli/stats.rb, line 18
def initialize(parse = true)
  super()
  @parse = parse
  @undoc_list = nil
  @compact = false
end

Public Instance Methods

all_objects() click to toggle source

@return [Array<CodeObjects::Base>] all the parsed objects in the registry,

removing any objects that are not visible (private, protected) depending
on the arguments passed to the command.
# File lib/yard/cli/stats.rb, line 108
def all_objects
  @all_objects ||= run_verifier Registry.all
end
description() click to toggle source
# File lib/yard/cli/stats.rb, line 25
def description
  "Prints documentation statistics on a set of files"
end
output(name, data, undoc = nil) click to toggle source

Prints a statistic to standard out. This method is optimized for getting Integer values, though it allows any data to be printed.

@param [String] name the statistic name @param [Integer, String] data the numeric (or any) data representing

the statistic. If +data+ is an Integer, it should represent the
total objects of a type.

@param [Integer, nil] undoc number of undocumented objects for the type @return [void]

# File lib/yard/cli/stats.rb, line 162
def output(name, data, undoc = nil)
  @total += data if data.is_a?(Integer) && undoc
  @undocumented += undoc if undoc.is_a?(Integer)
  data =
    if undoc
      ("%5s (% 5d undocumented)" % [data, undoc])
    else
      "%5s" % data
    end
  log.puts("%-12s %s" % [name + ":", data])
end
print_statistics() click to toggle source

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}.

print_undocumented_objects() click to toggle source

Prints list of undocumented objects

run(*args) click to toggle source

Runs the commandline utility, parsing arguments and generating output if set.

@param [Array<String>] args the list of arguments @return [void]

# File lib/yard/cli/stats.rb, line 34
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

  abort if fail_on_warning && log.warned
end
stats_for_attributes() click to toggle source

Statistics for attributes

# File lib/yard/cli/stats.rb, line 135
def stats_for_attributes
  objs = all_objects.select {|m| m.type == :method && m.is_attribute? }
  objs.uniq! {|m| m.name.to_s.gsub(/=$/, '') }
  undoc = objs.select {|m| m.docstring.blank? }
  @undoc_list |= undoc if @undoc_list
  output "Attributes", objs.size, undoc.size
end
stats_for_classes() click to toggle source

Statistics for classes

# File lib/yard/cli/stats.rb, line 125
def stats_for_classes
  output "Classes", *type_statistics(:class)
end
stats_for_constants() click to toggle source

Statistics for constants

# File lib/yard/cli/stats.rb, line 130
def stats_for_constants
  output "Constants", *type_statistics(:constant)
end
stats_for_files() click to toggle source

Statistics for files

# File lib/yard/cli/stats.rb, line 113
def stats_for_files
  files = []
  all_objects.each {|o| files |= [o.file] }
  output "Files", files.size
end
stats_for_methods() click to toggle source

Statistics for methods

# File lib/yard/cli/stats.rb, line 144
def stats_for_methods
  objs = all_objects.select {|m| m.type == :method }
  objs.reject!(&:is_alias?)
  objs.reject!(&:is_attribute?)
  undoc = objs.select {|m| m.docstring.blank? }
  @undoc_list |= undoc if @undoc_list
  output "Methods", objs.size, undoc.size
end
stats_for_modules() click to toggle source

Statistics for modules

# File lib/yard/cli/stats.rb, line 120
def stats_for_modules
  output "Modules", *type_statistics(:module)
end

Private Instance Methods

general_options(opts) click to toggle source
Calls superclass method
# File lib/yard/cli/stats.rb, line 199
def general_options(opts)
  super(opts)

  opts.on('--list-undoc', 'List all undocumented objects') do
    @undoc_list = []
  end

  opts.on('--compact', 'Compact undocumented objects listing') do
    @compact = true
  end

  opts.on('--no-public', "Don't include public methods in statistics.") do
    visibilities.delete(:public)
  end

  opts.on('--protected', "Include protected methods in statistics.") do
    visibilities.push(:protected)
  end

  opts.on('--private', "Include private methods in statistics.") do
    visibilities.push(:private)
  end

  opts.on('--no-private', "Don't include objects with @private tag in statistics.") do
    options[:verifier].add_expressions '!object.tag(:private) &&
      (object.namespace.type == :proxy || !object.namespace.tag(:private))'
  end

  opts.on('--query QUERY', "Only includes objects that match a specific query") do |query|
    query.taint if query.respond_to?(:taint)
    options[:verifier].add_expressions(query)
  end
end
optparse(*args) click to toggle source

Parses commandline options. @param [Array<String>] args each tokenized argument

# File lib/yard/cli/stats.rb, line 185
def optparse(*args)
  opts = OptionParser.new
  opts.banner = "Usage: yard stats [options] [source_files]"

  opts.separator "(if a list of source files is omitted, lib/**/*.rb ext/**/*.{c,rb} is used.)"

  general_options(opts)
  output_options(opts)
  tag_options(opts)
  common_options(opts)
  parse_options(opts, args)
  parse_files(*args) unless args.empty?
end
type_statistics(type) click to toggle source
# File lib/yard/cli/stats.rb, line 176
def type_statistics(type)
  objs = all_objects.select {|m| m.type == type }
  undoc = objs.find_all {|m| m.docstring.blank? }
  @undoc_list |= undoc if @undoc_list
  [objs.size, undoc.size]
end