class Git::DiffStats

including insertions, deletions, and file-level details.
Provides access to the statistics of a diff between two commits,

def deletions

Returns the total number of lines deleted.
def deletions
  fetch_stats[:total][:deletions]
end

def fetch_stats

Lazily fetches and caches the stats from the git lib.
def fetch_stats
  @stats ||= @base.lib.diff_stats(
    @from, @to, { path_limiter: @path_limiter }
  )
end

def files

Returns:
  • (Hash) -
def files
  fetch_stats[:files]
end

def initialize(base, from, to, path_limiter = nil)

Other tags:
    Private: -
def initialize(base, from, to, path_limiter = nil)
  # Eagerly check for invalid arguments
  [from, to].compact.each do |arg|
    raise ArgumentError, "Invalid argument: '#{arg}'" if arg.start_with?('-')
  end
  @base = base
  @from = from
  @to = to
  @path_limiter = path_limiter
  @stats = nil
end

def insertions

Returns the total number of lines inserted.
def insertions
  fetch_stats[:total][:insertions]
end

def lines

Returns the total number of lines changed (insertions + deletions).
def lines
  fetch_stats[:total][:lines]
end

def total

Returns:
  • ({insertions: Integer, deletions: Integer, lines: Integer, files: Integer}) -
def total
  fetch_stats[:total]
end