Class: Git::DiffInfo Private
- Inherits:
-
Data
- Object
- Data
- Git::DiffInfo
- Defined in:
- lib/git/diff_info.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Immutable value object representing diff statistics and optional file patches
DiffInfo encapsulates the parsed output from various git commands that produce
diff statistics (like git stash show --stat). When patches are requested,
it also includes the full patch information for each file.
The stats hash structure:
:total- Hash with:insertions,:deletions,:lines,:fileskeys:files- Hash mapping file paths to{ insertions:, deletions: }hashes
Work in progress; this class is internal for now and may be made public in a future release.
Instance Attribute Summary collapse
-
#file_patches ⇒ Array<FileDiffInfo>
readonly
Array of file diff info objects (empty if patch not requested).
-
#stats ⇒ Hash
readonly
The statistics hash with :total and :files keys.
Instance Method Summary collapse
-
#deletions ⇒ Integer
private
Total number of lines deleted.
-
#file_count ⇒ Integer
private
Number of files changed.
-
#file_stats ⇒ Hash<String, Hash>
private
Per-file statistics hash.
-
#insertions ⇒ Integer
private
Total number of lines inserted.
-
#lines ⇒ Integer
private
Total number of lines changed (insertions + deletions).
-
#patch_for(path) ⇒ FileDiffInfo?
private
Get patch info for a specific file.
-
#patches? ⇒ Boolean
private
Check if patch information is available.
Instance Attribute Details
#file_patches ⇒ Array<FileDiffInfo> (readonly)
Returns array of file diff info objects (empty if patch not requested).
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/git/diff_info.rb', line 103 DiffInfo = Data.define(:stats, :file_patches) do # Total number of lines inserted # # @return [Integer] # def insertions stats[:total][:insertions] end # Total number of lines deleted # # @return [Integer] # def deletions stats[:total][:deletions] end # Total number of lines changed (insertions + deletions) # # @return [Integer] # def lines stats[:total][:lines] end # Number of files changed # # @return [Integer] # def file_count stats[:total][:files] end # Per-file statistics hash # # @return [Hash<String, Hash>] mapping file paths to `{ insertions:, deletions: }` hashes # def file_stats stats[:files] end # Check if patch information is available # # @return [Boolean] true if file_patches were loaded # def patches? !file_patches.empty? end # Get patch info for a specific file # # @param path [String] the file path # # @return [FileDiffInfo, nil] the diff info or nil if not found # def patch_for(path) file_patches.find { |p| p.path == path } end end |
#stats ⇒ Hash (readonly)
Returns the statistics hash with :total and :files keys.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/git/diff_info.rb', line 103 DiffInfo = Data.define(:stats, :file_patches) do # Total number of lines inserted # # @return [Integer] # def insertions stats[:total][:insertions] end # Total number of lines deleted # # @return [Integer] # def deletions stats[:total][:deletions] end # Total number of lines changed (insertions + deletions) # # @return [Integer] # def lines stats[:total][:lines] end # Number of files changed # # @return [Integer] # def file_count stats[:total][:files] end # Per-file statistics hash # # @return [Hash<String, Hash>] mapping file paths to `{ insertions:, deletions: }` hashes # def file_stats stats[:files] end # Check if patch information is available # # @return [Boolean] true if file_patches were loaded # def patches? !file_patches.empty? end # Get patch info for a specific file # # @param path [String] the file path # # @return [FileDiffInfo, nil] the diff info or nil if not found # def patch_for(path) file_patches.find { |p| p.path == path } end end |
Instance Method Details
#deletions ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Total number of lines deleted
116 117 118 |
# File 'lib/git/diff_info.rb', line 116 def deletions stats[:total][:deletions] end |
#file_count ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Number of files changed
132 133 134 |
# File 'lib/git/diff_info.rb', line 132 def file_count stats[:total][:files] end |
#file_stats ⇒ Hash<String, Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Per-file statistics hash
140 141 142 |
# File 'lib/git/diff_info.rb', line 140 def file_stats stats[:files] end |
#insertions ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Total number of lines inserted
108 109 110 |
# File 'lib/git/diff_info.rb', line 108 def insertions stats[:total][:insertions] end |
#lines ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Total number of lines changed (insertions + deletions)
124 125 126 |
# File 'lib/git/diff_info.rb', line 124 def lines stats[:total][:lines] end |
#patch_for(path) ⇒ FileDiffInfo?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get patch info for a specific file
158 159 160 |
# File 'lib/git/diff_info.rb', line 158 def patch_for(path) file_patches.find { |p| p.path == path } end |
#patches? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if patch information is available
148 149 150 |
# File 'lib/git/diff_info.rb', line 148 def patches? !file_patches.empty? end |