Class: Git::DiffInfo
- Inherits:
-
Data
- Object
- Data
- Git::DiffInfo
- Defined in:
- lib/git/diff_info.rb
Overview
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
Instance Attribute Summary collapse
-
#file_patches ⇒ Object
readonly
Returns the value of attribute file_patches.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
-
#deletions ⇒ Integer
Total number of lines deleted.
-
#file_count ⇒ Integer
Number of files changed.
-
#file_stats ⇒ Hash<String, Hash>
Per-file statistics hash.
-
#insertions ⇒ Integer
Total number of lines inserted.
-
#lines ⇒ Integer
Total number of lines changed (insertions + deletions).
-
#patch_for(path) ⇒ FileDiffInfo?
Get patch info for a specific file.
-
#patches? ⇒ Boolean
Check if patch information is available.
Instance Attribute Details
#file_patches ⇒ Object (readonly)
Returns the value of attribute file_patches
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 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 162 163 164 165 166 167 168 |
# File 'lib/git/diff_info.rb', line 99 DiffInfo = Data.define(:stats, :file_patches) do # @!method insertions # @return [Integer] total number of lines inserted # @!method deletions # @return [Integer] total number of lines deleted # @!method lines # @return [Integer] total number of lines changed (insertions + deletions) # @!method file_count # @return [Integer] number of files changed # 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 ⇒ Object (readonly)
Returns the value of attribute stats
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 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 162 163 164 165 166 167 168 |
# File 'lib/git/diff_info.rb', line 99 DiffInfo = Data.define(:stats, :file_patches) do # @!method insertions # @return [Integer] total number of lines inserted # @!method deletions # @return [Integer] total number of lines deleted # @!method lines # @return [Integer] total number of lines changed (insertions + deletions) # @!method file_count # @return [Integer] number of files changed # 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
Total number of lines deleted
|
|
# File 'lib/git/diff_info.rb', line 103
|
#file_count ⇒ Integer
Number of files changed
|
|
# File 'lib/git/diff_info.rb', line 109
|
#file_stats ⇒ Hash<String, Hash>
Per-file statistics hash
148 149 150 |
# File 'lib/git/diff_info.rb', line 148 def file_stats stats[:files] end |
#insertions ⇒ Integer
Total number of lines inserted
|
|
# File 'lib/git/diff_info.rb', line 100
|
#lines ⇒ Integer
Total number of lines changed (insertions + deletions)
|
|
# File 'lib/git/diff_info.rb', line 106
|
#patch_for(path) ⇒ FileDiffInfo?
Get patch info for a specific file
165 166 167 |
# File 'lib/git/diff_info.rb', line 165 def patch_for(path) file_patches.find { |p| p.path == path } end |
#patches? ⇒ Boolean
Check if patch information is available
156 157 158 |
# File 'lib/git/diff_info.rb', line 156 def patches? !file_patches.empty? end |