Class: Git::DiffFileRawInfo

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

Overview

Immutable value object representing status info for a single file from git raw diff output

Contains the source and destination file references, change status, similarity percentage (for renames/copies), and line change statistics.

Examples:

A modified file

info = Git::DiffFileRawInfo.new(
  src: Git::FileRef.new(mode: '100644', sha: 'abc1234', path: 'lib/foo.rb'),
  dst: Git::FileRef.new(mode: '100644', sha: 'def5678', path: 'lib/foo.rb'),
  status: :modified,
  similarity: nil,
  insertions: 5,
  deletions: 2,
  binary: false
)

A new file (src is nil)

info = Git::DiffFileRawInfo.new(
  src: nil,
  dst: Git::FileRef.new(mode: '100644', sha: 'abc1234', path: 'lib/new.rb'),
  status: :added,
  similarity: nil,
  insertions: 10,
  deletions: 0,
  binary: false
)

A renamed file

info = Git::DiffFileRawInfo.new(
  src: Git::FileRef.new(mode: '100644', sha: 'abc1234', path: 'lib/old.rb'),
  dst: Git::FileRef.new(mode: '100644', sha: 'def5678', path: 'lib/new.rb'),
  status: :renamed,
  similarity: 95,
  insertions: 2,
  deletions: 1,
  binary: false
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#binaryObject (readonly)

Returns the value of attribute binary

Returns:

  • (Object)

    the current value of binary



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/git/diff_file_raw_info.rb', line 67

DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source path (for renames/copies)
  #
  # @return [String, nil] the source path, or nil if file was added
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#deletionsObject (readonly)

Returns the value of attribute deletions

Returns:

  • (Object)

    the current value of deletions



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/git/diff_file_raw_info.rb', line 67

DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source path (for renames/copies)
  #
  # @return [String, nil] the source path, or nil if file was added
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#dstObject (readonly)

Returns the value of attribute dst

Returns:

  • (Object)

    the current value of dst



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/git/diff_file_raw_info.rb', line 67

DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source path (for renames/copies)
  #
  # @return [String, nil] the source path, or nil if file was added
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#insertionsObject (readonly)

Returns the value of attribute insertions

Returns:

  • (Object)

    the current value of insertions



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/git/diff_file_raw_info.rb', line 67

DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source path (for renames/copies)
  #
  # @return [String, nil] the source path, or nil if file was added
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#similarityObject (readonly)

Returns the value of attribute similarity

Returns:

  • (Object)

    the current value of similarity



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/git/diff_file_raw_info.rb', line 67

DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source path (for renames/copies)
  #
  # @return [String, nil] the source path, or nil if file was added
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#srcObject (readonly)

Returns the value of attribute src

Returns:

  • (Object)

    the current value of src



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/git/diff_file_raw_info.rb', line 67

DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source path (for renames/copies)
  #
  # @return [String, nil] the source path, or nil if file was added
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/git/diff_file_raw_info.rb', line 67

DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do
  # Get the primary file path
  #
  # Returns the destination path if it exists, otherwise the source path.
  # This is the "current" or "canonical" path for the file.
  #
  # @return [String] the file path
  #
  def path
    dst&.path || src&.path
  end

  # Get the source path (for renames/copies)
  #
  # @return [String, nil] the source path, or nil if file was added
  #
  def src_path
    src&.path
  end

  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end

  # Check if this file was renamed
  #
  # @return [Boolean]
  #
  def renamed?
    status == :renamed
  end

  # Check if this file was copied
  #
  # @return [Boolean]
  #
  def copied?
    status == :copied
  end

  # Check if this file was added
  #
  # @return [Boolean]
  #
  def added?
    status == :added
  end

  # Check if this file was deleted
  #
  # @return [Boolean]
  #
  def deleted?
    status == :deleted
  end
end

Instance Method Details

#added?Boolean

Check if this file was added

Returns:

  • (Boolean)


115
116
117
# File 'lib/git/diff_file_raw_info.rb', line 115

def added?
  status == :added
end

#binary?Boolean

Check if this is a binary file

Returns:

  • (Boolean)

    true if the file is binary



91
92
93
# File 'lib/git/diff_file_raw_info.rb', line 91

def binary?
  binary
end

#copied?Boolean

Check if this file was copied

Returns:

  • (Boolean)


107
108
109
# File 'lib/git/diff_file_raw_info.rb', line 107

def copied?
  status == :copied
end

#deleted?Boolean

Check if this file was deleted

Returns:

  • (Boolean)


123
124
125
# File 'lib/git/diff_file_raw_info.rb', line 123

def deleted?
  status == :deleted
end

#pathString

Get the primary file path

Returns the destination path if it exists, otherwise the source path. This is the "current" or "canonical" path for the file.

Returns:

  • (String)

    the file path



75
76
77
# File 'lib/git/diff_file_raw_info.rb', line 75

def path
  dst&.path || src&.path
end

#renamed?Boolean

Check if this file was renamed

Returns:

  • (Boolean)


99
100
101
# File 'lib/git/diff_file_raw_info.rb', line 99

def renamed?
  status == :renamed
end

#src_pathString?

Get the source path (for renames/copies)

Returns:

  • (String, nil)

    the source path, or nil if file was added



83
84
85
# File 'lib/git/diff_file_raw_info.rb', line 83

def src_path
  src&.path
end