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
Constant Summary
-
STATS_ORDER =
Maintains the order in which
stats_for_
statistics methods should be printed.[:files, :modules, :classes, :constants, :attributes, :methods]
YardoptsCommand
- Inherited
Class Method Summary
- .new(parse = true) ⇒ Stats constructor
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 |
#use_document_file, #use_yardopts_file |
Instance Method Summary
- #all_objects ⇒ Array<CodeObjects::Base>
- #description
-
#output(name, data, undoc = nil) ⇒ void
Prints a statistic to standard out.
-
#print_statistics
Prints statistics for different object types.
-
#print_undocumented_objects
Prints list of undocumented objects.
-
#run(*args) ⇒ void
Runs the commandline utility, parsing arguments and generating output if set.
-
#stats_for_attributes
Statistics for attributes.
-
#stats_for_classes
Statistics for classes.
-
#stats_for_constants
Statistics for constants.
-
#stats_for_files
Statistics for files.
-
#stats_for_methods
Statistics for methods.
-
#stats_for_modules
Statistics for modules.
- #general_options(opts) private
-
#optparse(*args)
private
Parses commandline options.
- #type_statistics(type) private
::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 |
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 |
#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
Instance Attribute Details
#parse ⇒ Boolean
(rw)
# File 'lib/yard/cli/stats.rb', line 15
attr_accessor :parse
Instance Method Details
#all_objects ⇒ Array<CodeObjects::Base>
#description
# File 'lib/yard/cli/stats.rb', line 25
def description "Prints documentation statistics on a set of files" end
#general_options(opts) (private)
# File 'lib/yard/cli/stats.rb', line 199
def (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 [: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) [:verifier].add_expressions(query) end end
#optparse(*args) (private)
Parses commandline options.
# File 'lib/yard/cli/stats.rb', line 185
def optparse(*args) opts = OptionParser.new opts. = "Usage: yard stats [options] [source_files]" opts.separator "(if a list of source files is omitted, lib/**/*.rb ext/**/*.{c,rb} is used.)" (opts) (opts) (opts) (opts) (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.
#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.
# File 'lib/yard/cli/stats.rb', line 54
def print_statistics @total = 0 @undocumented = 0 meths = methods.map(&: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) } total = if @undocumented == 0 100 elsif @total == 0 0 else (@total - @undocumented).to_f / @total.to_f * 100 end log.puts("% 3.2f%% documented" % total) end
#print_undocumented_objects
Prints list of undocumented objects
# File 'lib/yard/cli/stats.rb', line 79
def print_undocumented_objects return if !@undoc_list || @undoc_list.empty? log.puts log.puts "Undocumented Objects:" # array needed for sort due to unstable sort objects = @undoc_list.sort_by {|o| [o.file.to_s, o.path] } max = objects.max {|a, b| a.path.length <=> b.path.length }.path.length if @compact objects.each do |object| log.puts("%-#{max}s (%s)" % [object.path, [object.file || "-unknown-", 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 || "-unknown-"})" end log.puts object.path last_file = object.file end end end
#run(*args) ⇒ void
This method returns an undefined value.
Runs the commandline utility, parsing arguments and generating output if set.
#stats_for_attributes
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
Statistics for classes
# File 'lib/yard/cli/stats.rb', line 125
def stats_for_classes output "Classes", *type_statistics(:class) end
#stats_for_constants
Statistics for constants
# File 'lib/yard/cli/stats.rb', line 130
def stats_for_constants output "Constants", *type_statistics(:constant) end
#stats_for_files
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
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
Statistics for modules
# File 'lib/yard/cli/stats.rb', line 120
def stats_for_modules output "Modules", *type_statistics(:module) end
#type_statistics(type) (private)
# 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