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 && from.to_s
  @to = to && to.to_s

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

Instance Attribute Details

#from (readonly)

Returns the value of attribute from.



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

def from
  @from
end

#to (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)

enumerable methods



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

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

#deletions



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

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

#each(&block)

:yields: each Git::DiffFile in turn



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

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

#insertions



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

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

#lines



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

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

#name_status



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

def name_status
  cache_name_status
end

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

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



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

def patch(file = nil)
  cache_full
  @full_diff
end

#path(path)



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

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

#size



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

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

#stats



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

def stats
  cache_stats
  @stats
end