module Hoe::History

History plugin for Hoe. Allows you to calculate all of the flog & flay scores over the releases of your project in an SCM independent way.

Public Instance Methods

flog_flay() click to toggle source

Calculate the flog and flay score for a Hoe project.

# File lib/hoe/history.rb, line 14
def flog_flay
  flog = %x`flog -s -c $(cat Manifest.txt | grep -v txt$) 2>/dev/null`
  flay = %x`flay -s    $(cat Manifest.txt | grep -v txt$) 2>/dev/null`

  flog_total = flog[/([\d\.]+): flog total/, 1].to_f
  flog_avg   = flog[/([\d\.]+): flog\/method average/, 1].to_f
  flay_total = flay[/Total score .lower is better. = (\d+)/, 1].to_i

  return flog_total, flog_avg, flay_total
end
history(versions) { |version| ... } click to toggle source

Calculate the history across all versions. Uses `versions` from an SCM plugin to figure out how to deal with the SCM.

# File lib/hoe/history.rb, line 47
def history versions
  history = load_history
  history.delete "dev" # FIX: this is p4 specific - make a variable?

  flog_total = flog_avg = flay_total = nil

  puts "version\tflog\tavg\tflay"
  versions.each do |version|
    history[version] = yield(version) unless history[version]

    flog_total, flog_avg, flay_total = history[version]
    puts "%s\t%.1f\t%.1f\t%d" % [version, flog_total, flog_avg, flay_total]
  end
ensure
  save_history history
end
load_history() click to toggle source

Load cached history.

# File lib/hoe/history.rb, line 28
def load_history
  require "yaml"
  YAML.load_file(".history.yaml") rescue {}
end
save_history(data) click to toggle source

Save cached history.

# File lib/hoe/history.rb, line 36
def save_history data
  require "yaml"
  File.open ".history.yaml", "w" do |f|
    YAML.dump data, f
  end
end