123456789_123456789_123456789_123456789_123456789_

Class: YARD::CLI::Stats

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: YARD::CLI::Yardoc
Defined in: lib/yard/cli/stats.rb

Overview

Since:

  • 0.6.0

Constant Summary

YardoptsCommand - Inherited

DEFAULT_YARDOPTS_FILE

Class Method Summary

Yardoc - Inherited

.new

Creates a new instance of the commandline utility.

YardoptsCommand - Inherited

.new

Creates a new command that reads .yardopts.

Command - Inherited

.run

Helper method to run the utility on an instance.

Instance Attribute Summary

::YARD::Templates::Helpers::BaseHelper - Included

Yardoc - Inherited

#apis

Keep track of which APIs are to be shown.

#assets, #excluded, #fail_on_warning, #files, #generate, #has_markup,
#hidden_apis

Keep track of which APIs are to be hidden.

#hidden_tags, #list, #options, #save_yardoc, #statistics, #use_cache,
#visibilities

Keep track of which visibilities are to be shown.

YardoptsCommand - Inherited

#options_file

The options file name (defaults to DEFAULT_YARDOPTS_FILE).

#use_document_file, #use_yardopts_file

Instance Method Summary

::YARD::Templates::Helpers::BaseHelper - Included

#format_object_title, #format_object_type,
#format_source

Indents and formats source code.

#format_types

Formats a list of return types for output and links each type.

#globals

An object that keeps track of global state throughout the entire template rendering process (including any sub-templates).

#h

Escapes text.

#link_file

Links to an extra file.

#link_include_file

Include a file as a docstring in output.

#link_include_object

Includes an object's docstring into output.

#link_object

Links to an object with an optional title.

#link_url

Links to a URL.

#linkify

Links objects or URLs.

#run_verifier

Runs a list of objects against the ::YARD::Verifier object passed into the template and returns the subset of verified objects.

Yardoc - Inherited

#all_objects

The list of all objects to process.

#description,
#parse_arguments

Parses commandline arguments.

#run

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

#add_api_verifier

Adds verifier rule for APIs.

#add_extra_files

Adds a set of extra documentation files to be processed.

#add_tag,
#add_visibility_verifier

Adds verifier rule for visibilities.

#apply_locale

Applies the specified locale to collected objects.

#copy_assets

Copies any assets to the output directory.

#extra_file_valid?,
#general_options

Adds general options.

#optparse

Parses commandline options.

#output_options

Adds output options.

#parse_files

Parses the file arguments into Ruby files and extra files, which are separated by a '-' element.

#print_list

Prints a list of all objects.

#run_generate

Generates output for objects.

#run_verifier

Runs a list of objects against the ::YARD::Verifier object passed into the template and returns the subset of verified objects.

#tag_options

Adds tag options.

#verify_markup_options

Verifies that the markup options are valid before parsing any code.

YardoptsCommand - Inherited

#parse_arguments

Parses commandline arguments.

#parse_rdoc_document_file, #parse_yardopts,
#parse_yardopts_options

Parses out the yardopts/document options.

#support_rdoc_document_file!

Reads a .document file in the directory to get source file globs.

#yardopts

Parses the .yardopts file for default yard options.

Command - Inherited

Constructor Details

.new(parse = true) ⇒ Stats

Parameters:

  • parse (Boolean) (defaults to: true)

    whether to parse and load registry (see #parse)

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/stats.rb', line 18

def initialize(parse = true)
  super()
  @parse = parse
  @undoc_list = nil
  @compact = false
end

Instance Attribute Details

#parseBoolean (rw)

Returns:

  • (Boolean)

    whether to parse and load registry

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/stats.rb', line 15

attr_accessor :parse

Instance Method Details

#all_objectsArray<CodeObjects::Base>

Returns:

  • (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.

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/stats.rb', line 108

def all_objects
  @all_objects ||= run_verifier Registry.all
end

#description

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/stats.rb', line 25

def description
  "Prints documentation statistics on a set of files"
end

#general_options(opts) (private)

Since:

  • 0.6.0

[ GitHub ]

  
# 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) (private)

Parses commandline options.

Parameters:

Since:

  • 0.6.0

[ GitHub ]

  
# 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

#output(name, data, undoc = nil) ⇒ void

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.

Parameters:

  • name (String)

    the statistic name

  • data (Integer, String)

    the numeric (or any) data representing the statistic. If data is an Integer, it should represent the total objects of a type.

  • undoc (Integer, nil) (defaults to: nil)

    number of undocumented objects for the type

Since:

  • 0.6.0

[ GitHub ]

  
# 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

#run(*args) ⇒ void

This method returns an undefined value.

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

Parameters:

Since:

  • 0.6.0

[ GitHub ]

  
# 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

Statistics for attributes

Since:

  • 0.6.0

[ GitHub ]

  
# 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

Statistics for classes

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/stats.rb', line 125

def stats_for_classes
  output "Classes", *type_statistics(:class)
end

#stats_for_constants

Statistics for constants

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/stats.rb', line 130

def stats_for_constants
  output "Constants", *type_statistics(:constant)
end

#stats_for_files

Statistics for files

Since:

  • 0.6.0

[ GitHub ]

  
# 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

Statistics for methods

Since:

  • 0.6.0

[ GitHub ]

  
# 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

Statistics for modules

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/stats.rb', line 120

def stats_for_modules
  output "Modules", *type_statistics(:module)
end

#type_statistics(type) (private)

Since:

  • 0.6.0

[ GitHub ]

  
# 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