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.



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

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.



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

def a_blob
  @a_blob
end

#a_pathObject (readonly)

Returns the value of attribute a_path.



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

def a_path
  @a_path
end

#b_blobObject (readonly)

Returns the value of attribute b_blob.



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

def b_blob
  @b_blob
end

#b_modeObject (readonly)

Returns the value of attribute b_mode.



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

def b_mode
  @b_mode
end

#b_pathObject (readonly)

Returns the value of attribute b_path.



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

def b_path
  @b_path
end

#binaryObject (readonly)

Returns the value of attribute binary.



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

def binary
  @binary
end

#hunksObject (readonly)

Returns the value of attribute hunks.



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

def hunks
  @hunks
end

Class Method Details

.from_string(string) ⇒ Object



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

def self.from_string(string)
  if path_info = %r{^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



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

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



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

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