Class: Detroit::Yardstick

Inherits:
Tool
  • Object
show all
Includes:
Standard
Defined in:
lib/detroit-yardstick.rb

Overview

TODO:

Switch to analyze station if detroit moves it after document.

Yardstick is a documentation coverage metric tool.

Constant Summary collapse

MANPAGE =

Location of the manpage document for this tool.

File.dirname(__FILE__) + '/../man/detroit-yardstick.5'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exactObject

return [Boolean]



60
61
62
# File 'lib/detroit-yardstick.rb', line 60

def exact
  @exact
end

#outputString

The path to the file where the measurements will be written.

Parameters:

  • output (String, Pathname)

    optional output path for measurements

Returns:

  • (String)


51
52
53
# File 'lib/detroit-yardstick.rb', line 51

def output
  @output
end

#pathString+

List of paths to measure.

Parameters:

  • path (Array<#to_s>, #to_s)

    optional list of paths to measure

Returns:

  • (String, Array<String>)


43
44
45
# File 'lib/detroit-yardstick.rb', line 43

def path
  @path
end

#rulesHash

Returns:

  • (Hash)


63
64
65
# File 'lib/detroit-yardstick.rb', line 63

def rules
  @rules
end

#thresholdObject

return [Integer]



54
55
56
# File 'lib/detroit-yardstick.rb', line 54

def threshold
  @threshold
end

#verboseObject

return [Boolean]



57
58
59
# File 'lib/detroit-yardstick.rb', line 57

def verbose
  @verbose
end

Instance Method Details

#assemble?(station, options = {}) ⇒ Boolean, Symbol

This tool ties into the ‘post_document` station of the standard assembly.

Returns:

  • (Boolean, Symbol)


88
89
90
91
# File 'lib/detroit-yardstick.rb', line 88

def assemble?(station, options={})
  return :save if station == :post_document
  return false
end

#prerequisiteundefined

Prerequisite setup.

Returns:

  • (undefined)


28
29
30
31
32
33
34
35
# File 'lib/detroit-yardstick.rb', line 28

def prerequisite
  require 'yardstick'

  @path    = 'lib/**/*.rb'
  @output  = project.log + 'yardstick.txt'
  @verbose = true
  @exact   = true
end

Measure the documentation and write to stdout.

Examples:

tool.print  # (print measurement report to stdout)

Returns:

  • (undefined)


81
82
83
# File 'lib/detroit-yardstick.rb', line 81

def print
  ::Yardstick.measure(yard_config).puts($stdout)
end

#saveundefined

Measure the documentation and write to output.

Examples:

tool.save  # (save measurement report to output)

Returns:

  • (undefined)


71
72
73
# File 'lib/detroit-yardstick.rb', line 71

def save
  write_report { |io| ::Yardstick.measure(yard_config).puts(io) }
end

#write_report {|io| ... } ⇒ void (private)

This method returns an undefined value.

Open up a report for writing

Yields:

  • (io)

    yield to an object that responds to #puts

Yield Parameters:

  • io (#puts)

    the object that responds to #puts



125
126
127
128
129
# File 'lib/detroit-yardstick.rb', line 125

def write_report(&block)
  file = Pathname(output)
  file.dirname.mkpath
  file.open('w', &block)
end

#yard_configObject (private)



96
97
98
# File 'lib/detroit-yardstick.rb', line 96

def yard_config
  Yardstick::Config.coerce(yard_options)
end

#yardstick_optionsObject (private)



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/detroit-yardstick.rb', line 101

def yardstick_options
  opts = {}

  opts[:path]      = path
  opts[:output]    = output
  opts[:verbose]   = verbose

  opts[:require_exact_threshold] = exact

  opts[:threshold] = threshold if threashold
  opts[:rules]     = rules     if rules

  return opts
end