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.

[View source]

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

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.


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

def from
  @from
end

#to (readonly)

Returns the value of attribute to.


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

def to
  @to
end

Instance Method Details

#[](key)

enumerable methods

[View source]

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

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

#deletions

[View source]

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

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

#each(&block)

:yields: each Git::DiffFile in turn

[View source]

69
70
71
72
# File 'lib/git/diff.rb', line 69

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

#insertions

[View source]

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

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

#lines

[View source]

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

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

#name_status

[View source]

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

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

[View source]

56
57
58
59
# File 'lib/git/diff.rb', line 56

def patch(file = nil)
  cache_full
  @full_diff
end

#path(path)

[View source]

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

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

#size

[View source]

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

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

#stats

[View source]

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

def stats
  cache_stats
  @stats
end