Class: Git::Diff

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/git/diff.rb

Overview

object that holds the last X commits on given branch

Defined Under Namespace

Classes: DiffFile

Instance Method Summary collapse

Constructor Details

#initialize(base, from = nil, to = nil) ⇒ Diff

Returns a new instance of Diff.



16
17
18
19
20
# File 'lib/git/diff.rb', line 16

def initialize(base, from = nil, to = nil)
  @base = base
  @from = from.to_s
  @to = to.to_s
end

Instance Method Details

#[](key) ⇒ Object

enumerable methods



61
62
63
64
# File 'lib/git/diff.rb', line 61

def [](key)
  process_full
  @full_diff_files.assoc(key)[1]
end

#deletionsObject



37
38
39
40
# File 'lib/git/diff.rb', line 37

def deletions
  cache_stats
  @stats[:total][:deletions]
end

#eachObject



66
67
68
69
70
71
# File 'lib/git/diff.rb', line 66

def each
  process_full
  @full_diff_files.each do |file|
    yield file[1]
  end
end

#insertionsObject



42
43
44
45
# File 'lib/git/diff.rb', line 42

def insertions
  cache_stats
  @stats[:total][:insertions]
end

#linesObject



32
33
34
35
# File 'lib/git/diff.rb', line 32

def lines
  cache_stats
  @stats[:total][:lines]
end

#patch(file = nil) ⇒ Object Also known as: to_s

if file is provided and is writable, it will write the patch into the file



53
54
55
56
# File 'lib/git/diff.rb', line 53

def patch(file = nil)
  cache_full
  @full_diff
end

#path(path) ⇒ Object



22
23
24
25
# File 'lib/git/diff.rb', line 22

def path(path)
  @path = path
  return self
end

#sizeObject



27
28
29
30
# File 'lib/git/diff.rb', line 27

def size
  cache_stats
  @stats[:total][:files]
end

#statsObject



47
48
49
50
# File 'lib/git/diff.rb', line 47

def stats
  cache_stats
  @stats
end