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.
10
11
12
|
# File 'lib/git_stats/git_data/commit.rb', line 10
def author
@author
end
|
#date ⇒ Object
Returns the value of attribute date.
10
11
12
|
# File 'lib/git_stats/git_data/commit.rb', line 10
def date
@date
end
|
#repo ⇒ Object
Returns the value of attribute repo.
10
11
12
|
# File 'lib/git_stats/git_data/commit.rb', line 10
def repo
@repo
end
|
#sha ⇒ Object
Returns the value of attribute sha.
10
11
12
|
# File 'lib/git_stats/git_data/commit.rb', line 10
def sha
@sha
end
|
#stamp ⇒ Object
Returns the value of attribute stamp.
10
11
12
|
# File 'lib/git_stats/git_data/commit.rb', line 10
def stamp
@stamp
end
|
Instance Method Details
#==(other) ⇒ Object
64
65
66
67
|
# File 'lib/git_stats/git_data/commit.rb', line 64
def ==(other)
[repo, sha, stamp, date, author] ==
[other.repo, other.sha, other.stamp, other.date, other.author]
end
|
#binary_files ⇒ Object
18
19
20
|
# File 'lib/git_stats/git_data/commit.rb', line 18
def binary_files
@binary_files ||= files.select(&:binary?)
end
|
60
61
62
|
# File 'lib/git_stats/git_data/commit.rb', line 60
def
||= .new(self)
end
|
#files ⇒ Object
12
13
14
15
16
|
# File 'lib/git_stats/git_data/commit.rb', line 12
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
26
27
28
29
30
31
|
# File 'lib/git_stats/git_data/commit.rb', line 26
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
33
34
35
|
# File 'lib/git_stats/git_data/commit.rb', line 33
def files_by_extension_count
@files_by_extension_count ||= files_by_extension.transform_values(&:count)
end
|
#files_count ⇒ Object
45
46
47
|
# File 'lib/git_stats/git_data/commit.rb', line 45
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
37
38
39
40
41
42
43
|
# File 'lib/git_stats/git_data/commit.rb', line 37
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
49
50
51
52
53
54
|
# File 'lib/git_stats/git_data/commit.rb', line 49
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
56
57
58
|
# File 'lib/git_stats/git_data/commit.rb', line 56
def short_stat
@short_stat ||= ShortStat.new(self)
end
|
#text_files ⇒ Object
22
23
24
|
# File 'lib/git_stats/git_data/commit.rb', line 22
def text_files
@text_files ||= files - binary_files
end
|