class Git::Diff

object that holds the diff between two commits

Attributes

from[R]
to[R]

Public Class Methods

new(base, from = nil, to = nil) click to toggle source
# File lib/git/diff.rb, line 11
def initialize(base, from = nil, to = nil)
  @base = base
  @from = from&.to_s
  @to = to&.to_s

  @path = nil
  @full_diff_files = nil
end

Public Instance Methods

[](key) click to toggle source
# File lib/git/diff.rb, line 31
def [](key)
  process_full
  @full_diff_files.assoc(key)[1]
end
deletions() click to toggle source
# File lib/git/diff.rb, line 57
def deletions
  stats_provider.deletions
end
each(&) click to toggle source
# File lib/git/diff.rb, line 36
def each(&)
  process_full
  @full_diff_files.map { |file| file[1] }.each(&)
end
insertions() click to toggle source
# File lib/git/diff.rb, line 61
def insertions
  stats_provider.insertions
end
lines() click to toggle source
# File lib/git/diff.rb, line 53
def lines
  stats_provider.lines
end
name_status() click to toggle source

DEPRECATED METHODS

# File lib/git/diff.rb, line 49
def name_status
  path_status_provider.to_h
end
patch() click to toggle source
# File lib/git/diff.rb, line 26
def patch
  @base.lib.diff_full(@from, @to, { path_limiter: @path })
end
Also aliased as: to_s
path(path) click to toggle source
# File lib/git/diff.rb, line 21
def path(path)
  @path = path
  self
end
size() click to toggle source
# File lib/git/diff.rb, line 41
def size
  stats_provider.total[:files]
end
stats() click to toggle source
# File lib/git/diff.rb, line 65
def stats
  {
    files: stats_provider.files,
    total: stats_provider.total
  }
end
to_s()
Alias for: patch

Private Instance Methods

path_status_provider() click to toggle source
# File lib/git/diff.rb, line 111
def path_status_provider
  @path_status_provider ||= Git::DiffPathStatus.new(@base, @from, @to, @path)
end
process_full() click to toggle source
# File lib/git/diff.rb, line 105
def process_full
  return if @full_diff_files

  @full_diff_files = process_full_diff
end
process_full_diff() click to toggle source
# File lib/git/diff.rb, line 119
def process_full_diff
  FullDiffParser.new(@base, patch).parse
end
stats_provider() click to toggle source
# File lib/git/diff.rb, line 115
def stats_provider
  @stats_provider ||= Git::DiffStats.new(@base, @from, @to, @path)
end