class Git::DiffStats
Provides access to the statistics of a diff between two commits, including insertions, deletions, and file-level details.
Public Class Methods
Source
# File lib/git/diff_stats.rb, line 8 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
@private
Public Instance Methods
Source
# File lib/git/diff_stats.rb, line 22 def deletions fetch_stats[:total][:deletions] end
Returns the total number of lines deleted.
Source
# File lib/git/diff_stats.rb, line 39 def files fetch_stats[:files] end
Returns a hash of statistics for each file in the diff.
@return [Hash<String, {insertions: Integer, deletions: Integer}>]
Source
# File lib/git/diff_stats.rb, line 27 def insertions fetch_stats[:total][:insertions] end
Returns the total number of lines inserted.
Source
# File lib/git/diff_stats.rb, line 32 def lines fetch_stats[:total][:lines] end
Returns the total number of lines changed (insertions + deletions).
Source
# File lib/git/diff_stats.rb, line 46 def total fetch_stats[:total] end
Returns a hash of the total statistics for the diff.
@return [{insertions: Integer, deletions: Integer, lines: Integer, files: Integer}]
Private Instance Methods
Source
# File lib/git/diff_stats.rb, line 53 def fetch_stats @fetch_stats ||= @base.lib.diff_stats( @from, @to, { path_limiter: @path_limiter } ) end
Lazily fetches and caches the stats from the git lib.