class Guard::Yardstick
A guard plugin to run yardstick on every save
Attributes
A hash of options for configuring the plugin
@api private @return [Hash]
Public Class Methods
Initializes guard-yardstick
@api private @return [Guard::Yardstick]
# File lib/guard/yardstick.rb, line 20 def initialize(args = {}) super @options = { all_on_start: true, config: nil }.merge(args) end
Public Instance Methods
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
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
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
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
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
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
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
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