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, **opts) ⇒ Diff

Returns a new instance of Diff.



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

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

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

Instance Attribute Details

#from (readonly)

Returns the value of attribute from.



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

def from
  @from
end

#to (readonly)

Returns the value of attribute to.



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

def to
  @to
end

Instance Method Details

#[](key)

enumerable methods



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

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

#deletions



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

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

#each(&block)

:yields: each Git::DiffFile in turn



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

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

#insertions



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

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

#lines



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

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

#name_status



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

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



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

def patch(file = nil)
  cache_full
  @full_diff
end

#path(path)



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

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

#size



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

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

#stats



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

def stats
  cache_stats
  @stats
end