class RubyCritic::SourceControlSystem::Git::Churn
Public Class Methods
new(churn_after: nil, paths: ['.'])
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 24 def initialize(churn_after: nil, paths: ['.']) @churn_after = churn_after @paths = Array(paths) @date = nil @stats = {} 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
after_clause()
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 63 def after_clause @churn_after ? "--after='#{@churn_after}' " : '' end
call()
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 43 def call git_log_commands.each { |log_command| exec_git_command(log_command) } end
exec_git_command(command)
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 47 def exec_git_command(command) Git .git(command) .split("\n") .reject(&:empty?) .each { |line| process_line(line) } end
filename_for_subdirectory(filename)
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 90 def filename_for_subdirectory(filename) git_path = Git.git('rev-parse --show-toplevel') cd_path = Dir.pwd if cd_path.length > git_path.length filename = filename.sub(/^#{Regexp.escape("#{File.basename(cd_path)}/")}/, '') end [filename] end
git_log_command(path)
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 59 def git_log_command(path) "log --all --date=iso --follow --format='format:date:%x09%ad' --name-status #{after_clause}#{path}" end
git_log_commands()
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 55 def git_log_commands @paths.map { |path| git_log_command(path) } end
process_date(date)
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 81 def process_date(date) @date = date end
process_file(filename)
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 99 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 67 def process_line(line) operation, *rest = line.split("\t") case operation when /^date:/ process_date(*rest) when /^[RC]/ process_rename(*rest) else rest = filename_for_subdirectory(rest[0]) process_file(*rest) end end
process_rename(from, to)
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 85 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 103 def record_commit(filename, date) stats = @stats[filename] ||= Stats.new(0, date) stats.count += 1 end
renames()
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 108 def renames @renames ||= Renames.new end
stats(path)
click to toggle source
# File lib/rubycritic/source_control_systems/git/churn.rb, line 112 def stats(path) @stats.fetch(path, Stats.new(0)) end