Class: GitStats::GitData::Commit
- Inherits:
-
Object
- Object
- GitStats::GitData::Commit
- Includes:
- HashInitializable
- Defined in:
- lib/git_stats/git_data/commit.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
-
#stamp ⇒ Object
readonly
Returns the value of attribute stamp.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #binary_files ⇒ Object
- #comment_stat ⇒ Object
- #files ⇒ Object
- #files_by_extension ⇒ Object
- #files_by_extension_count ⇒ Object
- #files_count ⇒ Object
- #lines_by_extension ⇒ Object
- #lines_count ⇒ Object
- #short_stat ⇒ Object
- #text_files ⇒ Object
- #to_s ⇒ Object
Methods included from HashInitializable
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
9 10 11 |
# File 'lib/git_stats/git_data/commit.rb', line 9 def @author end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
9 10 11 |
# File 'lib/git_stats/git_data/commit.rb', line 9 def date @date end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
9 10 11 |
# File 'lib/git_stats/git_data/commit.rb', line 9 def repo @repo end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
9 10 11 |
# File 'lib/git_stats/git_data/commit.rb', line 9 def sha @sha end |
#stamp ⇒ Object (readonly)
Returns the value of attribute stamp.
9 10 11 |
# File 'lib/git_stats/git_data/commit.rb', line 9 def stamp @stamp end |
Instance Method Details
#==(other) ⇒ Object
61 62 63 64 |
# File 'lib/git_stats/git_data/commit.rb', line 61 def ==(other) [self.repo, self.sha, self.stamp, self.date, self.] == [other.repo, other.sha, other.stamp, other.date, other.] end |
#binary_files ⇒ Object
17 18 19 |
# File 'lib/git_stats/git_data/commit.rb', line 17 def binary_files @binary_files ||= files.select { |f| f.binary? } end |
#comment_stat ⇒ Object
53 54 55 |
# File 'lib/git_stats/git_data/commit.rb', line 53 def comment_stat @comment_stat ||= CommentStat.new(self) end |
#files ⇒ Object
11 12 13 14 15 |
# File 'lib/git_stats/git_data/commit.rb', line 11 def files @files ||= repo.run_and_parse("git ls-tree -r #{self.sha} -- #{repo.tree_path}").map do |file| Blob.new(repo: repo, filename: file[:filename], sha: file[:sha]) end end |
#files_by_extension ⇒ Object
25 26 27 |
# File 'lib/git_stats/git_data/commit.rb', line 25 def files_by_extension @files_by_extension ||= files.inject({}) { |acc, f| acc[f.extension] ||= []; acc[f.extension] << f; acc } end |
#files_by_extension_count ⇒ Object
29 30 31 |
# File 'lib/git_stats/git_data/commit.rb', line 29 def files_by_extension_count @files_by_extension_count ||= Hash[files_by_extension.map { |ext, files| [ext, files.count] }] end |
#files_count ⇒ Object
39 40 41 |
# File 'lib/git_stats/git_data/commit.rb', line 39 def files_count @files_count ||= repo.run("git ls-tree -r --name-only #{self.sha} -- #{repo.tree_path}| wc -l").to_i end |
#lines_by_extension ⇒ Object
33 34 35 36 37 |
# File 'lib/git_stats/git_data/commit.rb', line 33 def lines_by_extension @lines_by_extension ||= Hash[files_by_extension.map { |ext, files| [ext, files.map(&:lines_count).sum] }.delete_if { |ext, lines_count| lines_count == 0 }] end |
#lines_count ⇒ Object
43 44 45 46 47 |
# File 'lib/git_stats/git_data/commit.rb', line 43 def lines_count @lines_count ||= repo.run("git diff --shortstat `git hash-object -t tree /dev/null` #{self.sha} -- #{repo.tree_path}").lines.map do |line| line[/(\d+) insertions?/, 1].to_i end.sum end |
#short_stat ⇒ Object
49 50 51 |
# File 'lib/git_stats/git_data/commit.rb', line 49 def short_stat @short_stat ||= ShortStat.new(self) end |
#text_files ⇒ Object
21 22 23 |
# File 'lib/git_stats/git_data/commit.rb', line 21 def text_files @text_files ||= files - binary_files end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/git_stats/git_data/commit.rb', line 57 def to_s "#{self.class} #@sha" end |