Class: GitStatistics::CommitSummary
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- GitStatistics::CommitSummary
- Defined in:
- lib/git_statistics/commit_summary.rb
Defined Under Namespace
Classes: LanguageSummary
Instance Attribute Summary collapse
-
#patches ⇒ Object
readonly
Returns the value of attribute patches.
Instance Method Summary collapse
-
#added_files ⇒ Object
How many files were added in this commit.
-
#additions ⇒ Object
How many total additions in this commit?.
-
#deleted_files ⇒ Object
How many files were removed in this commit.
-
#deletions ⇒ Object
How many total deletions in this commit?.
- #file_stats ⇒ Object
-
#filenames ⇒ Object
Files touched in this commit.
-
#grouped_language_files ⇒ Object
Group file statistics by language.
-
#initialize(repo, commit) ⇒ CommitSummary
constructor
A new instance of CommitSummary.
-
#languages ⇒ Object
Array of LanguageSummary objects (one for each language) for simple calculations.
-
#merge? ⇒ Boolean
A Git commit is a merge if it has more than one parent.
-
#modified_files ⇒ Object
How many files were modified (not added/deleted) in this commit.
-
#net ⇒ Object
What is the net # of lines changes in this commit?.
Constructor Details
#initialize(repo, commit) ⇒ CommitSummary
Returns a new instance of CommitSummary.
5 6 7 8 9 10 |
# File 'lib/git_statistics/commit_summary.rb', line 5 def initialize(repo, commit) super(commit) @repo = repo @diff = diff(commit.parents.first) @patches = @diff.patches end |
Instance Attribute Details
#patches ⇒ Object (readonly)
Returns the value of attribute patches.
3 4 5 |
# File 'lib/git_statistics/commit_summary.rb', line 3 def patches @patches end |
Instance Method Details
#added_files ⇒ Object
How many files were added in this commit
23 24 25 |
# File 'lib/git_statistics/commit_summary.rb', line 23 def added_files file_stats.count { |file| file.status == :added } end |
#additions ⇒ Object
How many total additions in this commit?
33 34 35 |
# File 'lib/git_statistics/commit_summary.rb', line 33 def additions commit_summary(:additions) end |
#deleted_files ⇒ Object
How many files were removed in this commit
18 19 20 |
# File 'lib/git_statistics/commit_summary.rb', line 18 def deleted_files file_stats.count { |file| file.status == :deleted } end |
#deletions ⇒ Object
How many total deletions in this commit?
38 39 40 |
# File 'lib/git_statistics/commit_summary.rb', line 38 def deletions commit_summary(:deletions) end |
#file_stats ⇒ Object
47 48 49 |
# File 'lib/git_statistics/commit_summary.rb', line 47 def file_stats @cached_file_stats ||= @patches.map { |diff| DiffSummary.new(@repo, diff) } end |
#filenames ⇒ Object
Files touched in this commit
69 70 71 |
# File 'lib/git_statistics/commit_summary.rb', line 69 def filenames file_stats.map(&:filename) end |
#grouped_language_files ⇒ Object
Group file statistics by language
64 65 66 |
# File 'lib/git_statistics/commit_summary.rb', line 64 def grouped_language_files file_stats.group_by(&:language) end |
#languages ⇒ Object
Array of LanguageSummary objects (one for each language) for simple calculations
54 55 56 57 58 59 60 61 |
# File 'lib/git_statistics/commit_summary.rb', line 54 def languages grouped_language_files.map do |language, stats| additions = summarize(stats, :additions) deletions = summarize(stats, :deletions) net = summarize(stats, :net) LanguageSummary.new(language, additions, deletions, net, added_files, deleted_files, modified_files) end end |
#merge? ⇒ Boolean
A Git commit is a merge if it has more than one parent
13 14 15 |
# File 'lib/git_statistics/commit_summary.rb', line 13 def merge? parents.size > 1 end |
#modified_files ⇒ Object
How many files were modified (not added/deleted) in this commit
28 29 30 |
# File 'lib/git_statistics/commit_summary.rb', line 28 def modified_files file_stats.count { |file| file.status == :modified } end |
#net ⇒ Object
What is the net # of lines changes in this commit?
43 44 45 |
# File 'lib/git_statistics/commit_summary.rb', line 43 def net commit_summary(:net) end |