Class: Git::Diff::DiffFile

Inherits:
Object
  • Object
show all
Defined in:
lib/git/diff.rb

Constant Summary collapse

NIL_BLOB_REGEXP =
/\A0{4,40}\z/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, hash) ⇒ DiffFile

Returns a new instance of DiffFile.



77
78
79
80
81
82
83
84
85
86
# File 'lib/git/diff.rb', line 77

def initialize(base, hash)
  @base = base
  @patch = hash[:patch]
  @path = hash[:path]
  @mode = hash[:mode]
  @src = hash[:src]
  @dst = hash[:dst]
  @type = hash[:type]
  @binary = hash[:binary]
end

Instance Attribute Details

#dstObject

Returns the value of attribute dst.



73
74
75
# File 'lib/git/diff.rb', line 73

def dst
  @dst
end

#modeObject

Returns the value of attribute mode.



73
74
75
# File 'lib/git/diff.rb', line 73

def mode
  @mode
end

#patchObject

Returns the value of attribute patch.



73
74
75
# File 'lib/git/diff.rb', line 73

def patch
  @patch
end

#pathObject

Returns the value of attribute path.



73
74
75
# File 'lib/git/diff.rb', line 73

def path
  @path
end

#srcObject

Returns the value of attribute src.



73
74
75
# File 'lib/git/diff.rb', line 73

def src
  @src
end

#typeObject

Returns the value of attribute type.



73
74
75
# File 'lib/git/diff.rb', line 73

def type
  @type
end

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/git/diff.rb', line 88

def binary?
  !!@binary
end

#blob(type = :dst) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/git/diff.rb', line 92

def blob(type = :dst)
  if type == :src && !NIL_BLOB_REGEXP.match(@src)
    @base.object(@src)
  elsif !NIL_BLOB_REGEXP.match(@dst)
    @base.object(@dst)
  end
end