Class: GitDiff::File

Inherits:
Object
  • Object
show all
Defined in:
lib/git_diff/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_path: '/dev/null', b_path: '/dev/null') ⇒ File

Returns a new instance of File.



15
16
17
18
19
# File 'lib/git_diff/file.rb', line 15

def initialize(a_path: '/dev/null', b_path: '/dev/null')
  @hunks = []
  @a_path = a_path
  @b_path = b_path
end

Instance Attribute Details

#a_blobObject (readonly)

Returns the value of attribute a_blob.



4
5
6
# File 'lib/git_diff/file.rb', line 4

def a_blob
  @a_blob
end

#a_pathObject (readonly)

Returns the value of attribute a_path.



4
5
6
# File 'lib/git_diff/file.rb', line 4

def a_path
  @a_path
end

#b_blobObject (readonly)

Returns the value of attribute b_blob.



4
5
6
# File 'lib/git_diff/file.rb', line 4

def b_blob
  @b_blob
end

#b_modeObject (readonly)

Returns the value of attribute b_mode.



4
5
6
# File 'lib/git_diff/file.rb', line 4

def b_mode
  @b_mode
end

#b_pathObject (readonly)

Returns the value of attribute b_path.



4
5
6
# File 'lib/git_diff/file.rb', line 4

def b_path
  @b_path
end

#binaryObject (readonly)

Returns the value of attribute binary.



4
5
6
# File 'lib/git_diff/file.rb', line 4

def binary
  @binary
end

#hunksObject (readonly)

Returns the value of attribute hunks.



4
5
6
# File 'lib/git_diff/file.rb', line 4

def hunks
  @hunks
end

Class Method Details

.from_string(string) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/git_diff/file.rb', line 6

def self.from_string(string)
  if path_info = /^diff --git(?: a\/(\S+))?(?: b\/(\S+))?/.match(string)
    File.new(
      a_path: path_info.captures[0] || '/dev/null',
      b_path: path_info.captures[1] || '/dev/null'
    )
  end
end

Instance Method Details

#<<(string) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/git_diff/file.rb', line 21

def <<(string)
  return if (string)

  if(range_info = RangeInfo.from_string(string))
    add_hunk Hunk.new(range_info)
  else
    append_to_current_hunk string
  end
end

#statsObject



31
32
33
# File 'lib/git_diff/file.rb', line 31

def stats
  @stats ||= Stats.total(collector)
end