Class: GitStats::GitData::Repo
- Inherits:
-
Object
- Object
- GitStats::GitData::Repo
- Includes:
- HashInitializable
- Defined in:
- lib/git_stats/git_data/repo.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #activity ⇒ Object
- #add_command_observer(proc = nil, &block) ⇒ Object
- #authors ⇒ Object
- #command_parser ⇒ Object
- #command_runner ⇒ Object
- #comment_stats ⇒ Object
- #comment_string ⇒ Object
- #comments_count_by_date ⇒ Object
- #commit_range ⇒ Object
- #commits ⇒ Object
- #commits_count_by_author(limit = 4) ⇒ Object
- #commits_period ⇒ Object
- #files_count_by_date ⇒ Object
- #first_commit_sha ⇒ Object
-
#initialize(params) ⇒ Repo
constructor
A new instance of Repo.
- #last_commit ⇒ Object
- #last_commit_sha ⇒ Object
- #lines_count_by_date ⇒ Object
- #path ⇒ Object
- #project_name ⇒ Object
- #project_version ⇒ Object
- #run(command) ⇒ Object
- #run_and_parse(command) ⇒ Object
- #short_stats ⇒ Object
- #to_s ⇒ Object
- #tree ⇒ Object
- #tree_path ⇒ Object
Constructor Details
#initialize(params) ⇒ Repo
Returns a new instance of Repo.
12 13 14 15 16 |
# File 'lib/git_stats/git_data/repo.rb', line 12 def initialize(params) super(params) @path = File.(@path) @tree_path ||= "." end |
Instance Method Details
#==(other) ⇒ Object
154 155 156 |
# File 'lib/git_stats/git_data/repo.rb', line 154 def ==(other) self.path == other.path end |
#activity ⇒ Object
114 115 116 |
# File 'lib/git_stats/git_data/repo.rb', line 114 def activity @activity ||= Activity.new(commits) end |
#add_command_observer(proc = nil, &block) ⇒ Object
145 146 147 148 |
# File 'lib/git_stats/git_data/repo.rb', line 145 def add_command_observer(proc=nil, &block) command_observers << block if block_given? command_observers << proc if proc end |
#authors ⇒ Object
42 43 44 45 46 |
# File 'lib/git_stats/git_data/repo.rb', line 42 def ||= run_and_parse("git shortlog -se #{commit_range} #{tree_path}").map do || Author.new(repo: self, name: [:name], email: [:email]) end end |
#command_parser ⇒ Object
141 142 143 |
# File 'lib/git_stats/git_data/repo.rb', line 141 def command_parser @command_parser ||= CommandParser.new end |
#command_runner ⇒ Object
137 138 139 |
# File 'lib/git_stats/git_data/repo.rb', line 137 def command_runner @command_runner ||= CommandRunner.new end |
#comment_stats ⇒ Object
110 111 112 |
# File 'lib/git_stats/git_data/repo.rb', line 110 def comment_stats @comment_stats ||= commits.map(&:comment_stat) end |
#comment_string ⇒ Object
34 35 36 |
# File 'lib/git_stats/git_data/repo.rb', line 34 def comment_string @comment_string ||= '//' end |
#comments_count_by_date ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/git_stats/git_data/repo.rb', line 89 def comments_count_by_date sum = 0 @comment_count_each_day ||= Hash[commits.map { |commit| sum += commit.comment_stat.insertions sum -= commit.comment_stat.deletions [commit.date.to_date, sum] }].fill_empty_days!(aggregated: true) end |
#commit_range ⇒ Object
102 103 104 |
# File 'lib/git_stats/git_data/repo.rb', line 102 def commit_range @first_commit_sha.blank? ? last_commit_sha : "#@first_commit_sha..#{last_commit_sha}" end |
#commits ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/git_stats/git_data/repo.rb', line 48 def commits @commits ||= run_and_parse("git rev-list --pretty=format:'%h|%at|%ai|%aE' #{commit_range} #{tree_path} | grep -v commit").map do |commit_line| Commit.new( repo: self, sha: commit_line[:sha], stamp: commit_line[:stamp], date: DateTime.parse(commit_line[:date]), author: .first! { |a| a.email == commit_line[:author_email] } ) end.sort_by! { |e| e.date } end |
#commits_count_by_author(limit = 4) ⇒ Object
64 65 66 |
# File 'lib/git_stats/git_data/repo.rb', line 64 def (limit = 4) Hash[.map { || [, .commits.size] }.sort_by { |, commits| -commits }[0..limit]] end |
#commits_period ⇒ Object
60 61 62 |
# File 'lib/git_stats/git_data/repo.rb', line 60 def commits_period commits.map(&:date).minmax end |
#files_count_by_date ⇒ Object
74 75 76 77 78 |
# File 'lib/git_stats/git_data/repo.rb', line 74 def files_count_by_date @files_count_each_day ||= Hash[commits.map { |commit| [commit.date.to_date, commit.files_count] }] end |
#first_commit_sha ⇒ Object
22 23 24 |
# File 'lib/git_stats/git_data/repo.rb', line 22 def first_commit_sha @first_commit_sha end |
#last_commit ⇒ Object
98 99 100 |
# File 'lib/git_stats/git_data/repo.rb', line 98 def last_commit commits.last end |
#last_commit_sha ⇒ Object
26 27 28 |
# File 'lib/git_stats/git_data/repo.rb', line 26 def last_commit_sha @last_commit_sha ||= 'HEAD' end |
#lines_count_by_date ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/git_stats/git_data/repo.rb', line 80 def lines_count_by_date sum = 0 @lines_count_each_day ||= Hash[commits.map { |commit| sum += commit.short_stat.insertions sum -= commit.short_stat.deletions [commit.date.to_date, sum] }] end |
#path ⇒ Object
18 19 20 |
# File 'lib/git_stats/git_data/repo.rb', line 18 def path @path ||= '.' end |
#project_name ⇒ Object
122 123 124 |
# File 'lib/git_stats/git_data/repo.rb', line 122 def project_name @project_name ||= (File.(File.join(path, tree_path)).sub(File.dirname(File.(path))+File::SEPARATOR,"") || File.basename(path)) end |
#project_version ⇒ Object
118 119 120 |
# File 'lib/git_stats/git_data/repo.rb', line 118 def project_version @project_version ||= run("git rev-parse --short #{commit_range}").strip end |
#run(command) ⇒ Object
126 127 128 129 130 |
# File 'lib/git_stats/git_data/repo.rb', line 126 def run(command) result = command_runner.run(path, command) invoke_command_observers(command, result) result end |
#run_and_parse(command) ⇒ Object
132 133 134 135 |
# File 'lib/git_stats/git_data/repo.rb', line 132 def run_and_parse(command) result = run(command) command_parser.parse(command, result) end |
#short_stats ⇒ Object
106 107 108 |
# File 'lib/git_stats/git_data/repo.rb', line 106 def short_stats @short_stats ||= commits.map(&:short_stat) end |
#to_s ⇒ Object
150 151 152 |
# File 'lib/git_stats/git_data/repo.rb', line 150 def to_s "#{self.class} #@path" end |
#tree ⇒ Object
38 39 40 |
# File 'lib/git_stats/git_data/repo.rb', line 38 def tree @tree ||= Tree.new(repo: self, relative_path: @tree_path) end |
#tree_path ⇒ Object
30 31 32 |
# File 'lib/git_stats/git_data/repo.rb', line 30 def tree_path @tree_path ||= '.' end |