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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Diff.



7
8
9
10
11
12
13
14
15
16
# File 'lib/git/diff.rb', line 7

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

  @path = nil
  @full_diff = nil
  @full_diff_files = nil
  @stats = nil
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



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

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



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

def to
  @to
end

Instance Method Details

#[](key) ⇒ Object

enumerable methods



58
59
60
61
# File 'lib/git/diff.rb', line 58

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

#deletionsObject



34
35
36
37
# File 'lib/git/diff.rb', line 34

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

#each(&block) ⇒ Object

:yields: each Git::DiffFile in turn



63
64
65
66
# File 'lib/git/diff.rb', line 63

def each(&block) # :yields: each Git::DiffFile in turn
  process_full
  @full_diff_files.map { |file| file[1] }.each(&block)
end

#insertionsObject



39
40
41
42
# File 'lib/git/diff.rb', line 39

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

#linesObject



29
30
31
32
# File 'lib/git/diff.rb', line 29

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



50
51
52
53
# File 'lib/git/diff.rb', line 50

def patch(file = nil)
  cache_full
  @full_diff
end

#path(path) ⇒ Object



19
20
21
22
# File 'lib/git/diff.rb', line 19

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

#sizeObject



24
25
26
27
# File 'lib/git/diff.rb', line 24

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

#statsObject



44
45
46
47
# File 'lib/git/diff.rb', line 44

def stats
  cache_stats
  @stats
end