Class: GitStats::GitData::Commit
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Inspector
#inspect, #pretty_print, #to_s
#initialize
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
12
13
14
|
# File 'lib/git_stats/git_data/commit.rb', line 12
def author
@author
end
|
#date ⇒ Object
Returns the value of attribute date.
12
13
14
|
# File 'lib/git_stats/git_data/commit.rb', line 12
def date
@date
end
|
#repo ⇒ Object
Returns the value of attribute repo.
12
13
14
|
# File 'lib/git_stats/git_data/commit.rb', line 12
def repo
@repo
end
|
#sha ⇒ Object
Returns the value of attribute sha.
12
13
14
|
# File 'lib/git_stats/git_data/commit.rb', line 12
def sha
@sha
end
|
#stamp ⇒ Object
Returns the value of attribute stamp.
12
13
14
|
# File 'lib/git_stats/git_data/commit.rb', line 12
def stamp
@stamp
end
|
Instance Method Details
#==(other) ⇒ Object
66
67
68
69
|
# File 'lib/git_stats/git_data/commit.rb', line 66
def ==(other)
[repo, sha, stamp, date, author] ==
[other.repo, other.sha, other.stamp, other.date, other.author]
end
|
#binary_files ⇒ Object
20
21
22
|
# File 'lib/git_stats/git_data/commit.rb', line 20
def binary_files
@binary_files ||= files.select(&:binary?)
end
|
62
63
64
|
# File 'lib/git_stats/git_data/commit.rb', line 62
def
@comment_stat ||= CommentStat.new(self)
end
|
#files ⇒ Object
14
15
16
17
18
|
# File 'lib/git_stats/git_data/commit.rb', line 14
def files
@files ||= repo.run_and_parse("git ls-tree -r #{sha} -- #{repo.tree_path}").map do |file|
Blob.new(repo: repo, filename: file[:filename], sha: file[:sha])
end
end
|
#files_by_extension ⇒ Object
28
29
30
31
32
33
|
# File 'lib/git_stats/git_data/commit.rb', line 28
def files_by_extension
@files_by_extension ||= files.each_with_object({}) do |f, acc|
acc[f.extension] ||= []
acc[f.extension] << f
end
end
|
#files_by_extension_count ⇒ Object
35
36
37
|
# File 'lib/git_stats/git_data/commit.rb', line 35
def files_by_extension_count
@files_by_extension_count ||= files_by_extension.transform_values(&:count)
end
|
#files_count ⇒ Object
47
48
49
|
# File 'lib/git_stats/git_data/commit.rb', line 47
def files_count
@files_count ||= repo.run("git ls-tree -r --name-only #{sha} -- #{repo.tree_path}| wc -l").to_i
end
|
#lines_by_extension ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/git_stats/git_data/commit.rb', line 39
def lines_by_extension
@lines_by_extension ||= files_by_extension.map do |ext, files|
next if (lines_count = files.sum(&:lines_count)) == 0
[ext, lines_count]
end.compact.to_h
end
|
#lines_count ⇒ Object
51
52
53
54
55
56
|
# File 'lib/git_stats/git_data/commit.rb', line 51
def lines_count
command = "git diff --shortstat --no-renames `git hash-object -t tree /dev/null` #{sha} -- #{repo.tree_path}"
@lines_count ||= repo.run(command).lines.sum do |line|
line[/(\d+) insertions?/, 1].to_i
end
end
|
#short_stat ⇒ Object
58
59
60
|
# File 'lib/git_stats/git_data/commit.rb', line 58
def short_stat
@short_stat ||= ShortStat.new(self)
end
|
#text_files ⇒ Object
24
25
26
|
# File 'lib/git_stats/git_data/commit.rb', line 24
def text_files
@text_files ||= files - binary_files
end
|