class StandupSummary::DiffAnalyzer

Constants

STATS
TEST

Public Class Methods

new(path, options) click to toggle source
# File lib/standup-summary/diff_analyzer.rb, line 8
def initialize(path, options)
  @path = path
  @limit = options[:limit]
  @use_recursive = options[:recursive]
  @options = options
  @results = { directories: [], changed: 0, insertions: 0, deletions: 0, length: 0 }
  @author_name = `git config user.name`.gsub("\n", '')
end

Public Instance Methods

analyze_dir(path) click to toggle source
# File lib/standup-summary/diff_analyzer.rb, line 54
def analyze_dir(path)
  project = path.gsub(@path, '')
  project = project[1..-1] if project[0] == '/'
  result = { path: project }
  STATS.each { |s| result[s] = 0 }
  Dir.chdir(path) do
    out = `#{cmd}`
    return if out.blank?
    out.split("\n").each do |line|
      regex = TEST.match line
      STATS.each do |stat|
        val = regex[stat].nil? ? 0 : regex[stat].to_i
        result[stat] += val
        @results[stat] += val
      end
    end
  end
  @results[:length] = project.length if @results[:length] < project.length
  @results[:directories] << result
end
cmd() click to toggle source
# File lib/standup-summary/diff_analyzer.rb, line 46
def cmd
  @cmd ||= if @options[:days].present?
             "git log --shortstat --format= --committer=\"#{@author_name}\" --since=\"#{@options[:days]} days ago\""
           else
             "git log --shortstat --format= --committer=\"#{@author_name}\" --after=\"#{@options[:from]} 00:00\" --before=\"#{@options[:to]} 23:59\""
           end
end
level(sub_dir) click to toggle source
# File lib/standup-summary/diff_analyzer.rb, line 75
def level(sub_dir)
  path = sub_dir.gsub @path, ''
  path = path[1..-1] if path[0] == '/'
  path.split('/').count
end
print_header() click to toggle source
print_results() click to toggle source
run!() click to toggle source
# File lib/standup-summary/diff_analyzer.rb, line 17
def run!
  if @use_recursive
    run_recursive
  else
    run_shallow
  end
  print_results
end
run_recursive() click to toggle source
# File lib/standup-summary/diff_analyzer.rb, line 26
def run_recursive
  Find.find(@path) do |path|
    Find.prune if level(path) >= @limit
    Find.prune and next if File.basename(path)[0] == ?.
    next unless File.directory? path
    next unless File.directory? path + '/.git'
    analyze_dir(path)
  end
end
run_shallow() click to toggle source
# File lib/standup-summary/diff_analyzer.rb, line 36
def run_shallow
  Dir.foreach(@path) do |path|
    next if File.basename(path)[0] == ?.
    path = @path + '/' + path
    next unless File.directory?(path)
    next unless File.directory? path + '/.git'
    analyze_dir(path)
  end
end