Class: YARD::CLI::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-strings/yard.rb

Overview

Monkey patch the stats object to return statistics for our objects. This is the recommended way to add custom stats.

Instance Method Summary collapse

Instance Method Details

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



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/puppet-strings/yard.rb', line 75

def output(name, data, undoc = nil)
  # Monkey patch output to accommodate our larger header widths
  @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('%-21s %s' % [name + ':', data])
end

#stats_for_puppet_classesObject



55
56
57
# File 'lib/puppet-strings/yard.rb', line 55

def stats_for_puppet_classes
  output 'Puppet Classes', *type_statistics_all(:puppet_class)
end

#stats_for_puppet_defined_typesObject



59
60
61
# File 'lib/puppet-strings/yard.rb', line 59

def stats_for_puppet_defined_types
  output 'Puppet Defined Types', *type_statistics_all(:puppet_defined_type)
end

#stats_for_puppet_functionsObject



71
72
73
# File 'lib/puppet-strings/yard.rb', line 71

def stats_for_puppet_functions
  output 'Puppet Functions', *type_statistics_all(:puppet_function)
end

#stats_for_puppet_providersObject



67
68
69
# File 'lib/puppet-strings/yard.rb', line 67

def stats_for_puppet_providers
  output 'Puppet Providers', *type_statistics_all(:puppet_provider)
end

#stats_for_puppet_typesObject



63
64
65
# File 'lib/puppet-strings/yard.rb', line 63

def stats_for_puppet_types
  output 'Puppet Types', *type_statistics_all(:puppet_type)
end

#type_statistics_all(type) ⇒ Object

This differs from the YARD implementation in that it considers a docstring without text but with tags to be undocumented.



90
91
92
93
94
95
# File 'lib/puppet-strings/yard.rb', line 90

def type_statistics_all(type)
  objs = all_objects.select {|m| m.type == type }
  undoc = objs.find_all {|m| m.docstring.all.empty? }
  @undoc_list |= undoc if @undoc_list
  [objs.size, undoc.size]
end