Class: Git::DiffStats
- Inherits:
-
Object
- Object
- Git::DiffStats
- Defined in:
- lib/git/diff_stats.rb
Overview
Provides access to the statistics of a diff between two commits, including insertions, deletions, and file-level details.
Instance Method Summary collapse
-
#deletions
Returns the total number of lines deleted.
-
#files ⇒ Hash<String, {insertions: Integer, deletions: Integer}>
Returns a hash of statistics for each file in the diff.
-
#initialize(base, from, to, path_limiter = nil) ⇒ DiffStats
constructor
A new instance of DiffStats.
-
#insertions
Returns the total number of lines inserted.
-
#lines
Returns the total number of lines changed (insertions + deletions).
-
#total ⇒ {insertions: Integer, deletions: Integer, lines: Integer, files: Integer}
Returns a hash of the total statistics for the diff.
Constructor Details
#initialize(base, from, to, path_limiter = nil) ⇒ DiffStats
Returns a new instance of DiffStats.
8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Method Details
#deletions
Returns the total number of lines deleted.
22 23 24 |
# File 'lib/git/diff_stats.rb', line 22 def deletions fetch_stats[:total][:deletions] end |
#files ⇒ Hash<String, {insertions: Integer, deletions: Integer}>
Returns a hash of statistics for each file in the diff.
39 40 41 |
# File 'lib/git/diff_stats.rb', line 39 def files fetch_stats[:files] end |
#insertions
Returns the total number of lines inserted.
27 28 29 |
# File 'lib/git/diff_stats.rb', line 27 def insertions fetch_stats[:total][:insertions] end |
#lines
Returns the total number of lines changed (insertions + deletions).
32 33 34 |
# File 'lib/git/diff_stats.rb', line 32 def lines fetch_stats[:total][:lines] end |
#total ⇒ {insertions: Integer, deletions: Integer, lines: Integer, files: Integer}
Returns a hash of the total statistics for the diff.
46 47 48 |
# File 'lib/git/diff_stats.rb', line 46 def total fetch_stats[:total] end |