class RubyCritic::SourceControlSystem::Git::Churn

Public Class Methods

new(churn_after: nil) click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 24
def initialize(churn_after: nil)
  @renames = Renames.new
  @date = nil
  @stats = {}
  @churn_after = churn_after

  call
end

Public Instance Methods

date_of_last_commit(path) click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 37
def date_of_last_commit(path)
  stats(path).date
end
revisions_count(path) click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 33
def revisions_count(path)
  stats(path).count
end

Private Instance Methods

call() click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 43
def call
  Git
    .git(git_log_command)
    .split("\n")
    .reject(&:empty?)
    .each { |line| process_line(line) }
end
git_log_command() click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 51
def git_log_command
  after_clause = @churn_after ? "--after='#{@churn_after}' " : ''
  "log --all --date=iso --follow --format='format:date:%x09%ad' --name-status #{after_clause}."
end
process_date(date) click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 69
def process_date(date)
  @date = date
end
process_file(filename) click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 78
def process_file(filename)
  record_commit(@renames.current(filename), @date)
end
process_line(line) click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 56
def process_line(line)
  operation, *rest = line.split("\t")

  case operation
  when /^date:/
    process_date(*rest)
  when /^[RC]/
    process_rename(*rest)
  else
    process_file(*rest)
  end
end
process_rename(from, to) click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 73
def process_rename(from, to)
  @renames.renamed(from, to)
  process_file(to)
end
record_commit(filename, date) click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 82
def record_commit(filename, date)
  stats = @stats[filename] ||= Stats.new(0, date)
  stats.count += 1
end
stats(path) click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 87
def stats(path)
  @stats.fetch(path, Stats.new(0))
end