class Guard::Yardstick

A guard plugin to run yardstick on every save

Attributes

options[R]

A hash of options for configuring the plugin

@api private @return [Hash]

Public Class Methods

new(args = {}) click to toggle source

Initializes guard-yardstick

@api private @return [Guard::Yardstick]

Calls superclass method
# File lib/guard/yardstick.rb, line 20
def initialize(args = {})
  super

  @options = {
    all_on_start: true,
    config: nil
  }.merge(args)
end

Public Instance Methods

run_all() click to toggle source

Will run all files through yardstick

@api private @return [Void]

# File lib/guard/yardstick.rb, line 41
def run_all
  UI.info 'Inspecting Yarddoc in all files'
  inspect_with_yardstick
end
run_on_additions(paths) click to toggle source

Will run when files are added

@api private @return [Void]

# File lib/guard/yardstick.rb, line 50
def run_on_additions(paths)
  run_partially(paths)
end
run_on_modifications(paths) click to toggle source

Will run when files are changed

@api private @return [Void]

# File lib/guard/yardstick.rb, line 58
def run_on_modifications(paths)
  run_partially(paths)
end
start() click to toggle source

When guard starts will run all files if :all_on_start is set

@api private @return [Void]

# File lib/guard/yardstick.rb, line 33
def start
  run_all if options[:all_on_start]
end

Private Instance Methods

inspect_with_yardstick(yardstick_options = {}) click to toggle source

Runs yardstick and outputs results to STDOUT

@api private @return [Void]

# File lib/guard/yardstick.rb, line 81
def inspect_with_yardstick(yardstick_options = {})
  config = ::Yardstick::Config.coerce(yardstick_config(yardstick_options))
  measurements = ::Yardstick.measure(config)
  measurements.puts
rescue StandardError => error
  UI.error 'The following exception occurred while running ' \
           "guard-yardstick: #{error.backtrace.first} " \
           "#{error.message} (#{error.class.name})"
end
run_partially(paths) click to toggle source

Runs yardstick on a partial set of paths passed in by guard

@api private @return [Void]

# File lib/guard/yardstick.rb, line 68
def run_partially(paths)
  return if paths.empty?

  displayed_paths = paths.map { |path| smart_path(path) }
  UI.info "Inspecting Yarddocs: #{displayed_paths.join(' ')}"

  inspect_with_yardstick(path: paths)
end
smart_path(path) click to toggle source

Returns a path with pwd removed if needed

@api private @return [String]

# File lib/guard/yardstick.rb, line 95
def smart_path(path)
  if path.start_with?(Dir.pwd)
    Pathname.new(path).relative_path_from(Pathname.getwd).to_s
  else
    path
  end
end
yardstick_config(extra_options = {}) click to toggle source

Merge further options with yardstick config file.

@api private @return [Hash] Hash of options for yardstick measurement

# File lib/guard/yardstick.rb, line 107
def yardstick_config(extra_options = {})
  return options unless options[:config]

  yardstick_options = YAML.load_file(options[:config])
  yardstick_options.merge(extra_options)
end