Class: Git::Diff
Overview
object that holds the last X commits on given branch
Defined Under Namespace
Classes: DiffFile
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#[](key) ⇒ Object
enumerable methods.
- #deletions ⇒ Object
-
#each(&block) ⇒ Object
:yields: each Git::DiffFile in turn.
-
#initialize(base, from = nil, to = nil) ⇒ Diff
constructor
A new instance of Diff.
- #insertions ⇒ Object
- #lines ⇒ Object
-
#patch(file = nil) ⇒ Object
(also: #to_s)
if file is provided and is writable, it will write the patch into the file.
- #path(path) ⇒ Object
- #size ⇒ Object
- #stats ⇒ Object
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 ⇒ Object (readonly)
Returns the value of attribute from.
17 18 19 |
# File 'lib/git/diff.rb', line 17 def from @from end |
#to ⇒ Object (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 |
#deletions ⇒ Object
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 |
#insertions ⇒ Object
39 40 41 42 |
# File 'lib/git/diff.rb', line 39 def insertions cache_stats @stats[:total][:insertions] end |
#lines ⇒ Object
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 |
#size ⇒ Object
24 25 26 27 |
# File 'lib/git/diff.rb', line 24 def size cache_stats @stats[:total][:files] end |
#stats ⇒ Object
44 45 46 47 |
# File 'lib/git/diff.rb', line 44 def stats cache_stats @stats end |