Class: GitStats::GitData::Commit

Inherits:
Object
  • Object
show all
Includes:
HashInitializable, Inspector
Defined in:
lib/git_stats/git_data/commit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspector

#inspect, #pretty_print, #to_s

Methods included from HashInitializable

#initialize

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



12
13
14
# File 'lib/git_stats/git_data/commit.rb', line 12

def author
  @author
end

#dateObject (readonly)

Returns the value of attribute date.



12
13
14
# File 'lib/git_stats/git_data/commit.rb', line 12

def date
  @date
end

#repoObject (readonly)

Returns the value of attribute repo.



12
13
14
# File 'lib/git_stats/git_data/commit.rb', line 12

def repo
  @repo
end

#shaObject (readonly)

Returns the value of attribute sha.



12
13
14
# File 'lib/git_stats/git_data/commit.rb', line 12

def sha
  @sha
end

#stampObject (readonly)

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_filesObject



20
21
22
# File 'lib/git_stats/git_data/commit.rb', line 20

def binary_files
  @binary_files ||= files.select(&:binary?)
end

#comment_statObject



62
63
64
# File 'lib/git_stats/git_data/commit.rb', line 62

def comment_stat
  @comment_stat ||= CommentStat.new(self)
end

#filesObject



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_extensionObject



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_countObject



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_countObject



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_extensionObject



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_countObject



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_statObject



58
59
60
# File 'lib/git_stats/git_data/commit.rb', line 58

def short_stat
  @short_stat ||= ShortStat.new(self)
end

#text_filesObject



24
25
26
# File 'lib/git_stats/git_data/commit.rb', line 24

def text_files
  @text_files ||= files - binary_files
end