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.



10
11
12
# File 'lib/git_stats/git_data/commit.rb', line 10

def author
  @author
end

#dateObject (readonly)

Returns the value of attribute date.



10
11
12
# File 'lib/git_stats/git_data/commit.rb', line 10

def date
  @date
end

#repoObject (readonly)

Returns the value of attribute repo.



10
11
12
# File 'lib/git_stats/git_data/commit.rb', line 10

def repo
  @repo
end

#shaObject (readonly)

Returns the value of attribute sha.



10
11
12
# File 'lib/git_stats/git_data/commit.rb', line 10

def sha
  @sha
end

#stampObject (readonly)

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_filesObject



18
19
20
# File 'lib/git_stats/git_data/commit.rb', line 18

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

#comment_statObject



60
61
62
# File 'lib/git_stats/git_data/commit.rb', line 60

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

#filesObject



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_extensionObject



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_countObject



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_countObject



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_extensionObject



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_countObject



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_statObject



56
57
58
# File 'lib/git_stats/git_data/commit.rb', line 56

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

#text_filesObject



22
23
24
# File 'lib/git_stats/git_data/commit.rb', line 22

def text_files
  @text_files ||= files - binary_files
end