mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
refactor
This commit is contained in:
parent
7ac6dcb6c4
commit
ff62823dd2
5 changed files with 21 additions and 39 deletions
|
@ -29,7 +29,7 @@ module GitStats
|
|||
@files_by_extension_count ||= Hash[files_by_extension.map { |ext, files| [ext, files.count] }]
|
||||
end
|
||||
|
||||
def lines_by_extension
|
||||
def lines_by_extension_count
|
||||
@lines_by_extension ||= Hash[files_by_extension.map { |ext, files|
|
||||
[ext, files.map(&:lines_count).sum]
|
||||
}.delete_if { |ext, lines_count| lines_count == 0 }]
|
||||
|
|
|
@ -7,7 +7,7 @@ module GitStats
|
|||
|
||||
attr_reader :path
|
||||
|
||||
delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension,
|
||||
delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension_count,
|
||||
:files_count, :binary_files, :text_files, :lines_count, to: :last_commit
|
||||
|
||||
def initialize(params)
|
||||
|
|
|
@ -6,44 +6,26 @@ module GitStats
|
|||
@repo = repo
|
||||
end
|
||||
|
||||
def files_by_extension
|
||||
[:lines, :files].each do |type|
|
||||
define_method "#{type}_by_extension" do
|
||||
Chart.new do |f|
|
||||
f.column_hash_chart(
|
||||
data: @repo.files_by_extension_count,
|
||||
title: :files_by_extension.t,
|
||||
y_text: :files.t
|
||||
data: @repo.send("#{type}_by_extension_count"),
|
||||
title: "#{type}_extension".to_sym.t,
|
||||
y_text: type.to_sym.t
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def lines_by_extension
|
||||
Chart.new do |f|
|
||||
f.column_hash_chart(
|
||||
data: @repo.lines_by_extension,
|
||||
title: :lines_by_extension.t,
|
||||
y_text: :lines.t
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def files_by_date
|
||||
define_method "#{type}_by_date" do
|
||||
Chart.new do |f|
|
||||
f.date_chart(
|
||||
data: @repo.files_count_by_date,
|
||||
title: :files_by_date.t,
|
||||
y_text: :files.t
|
||||
data: @repo.send("#{type}_count_by_date"),
|
||||
title: "#{type}_by_date".to_sym.t,
|
||||
y_text: type.to_sym.t
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def lines_by_date
|
||||
Chart.new do |f|
|
||||
f.date_chart(
|
||||
data: @repo.lines_count_by_date,
|
||||
title: :lines_by_date.t,
|
||||
y_text: :lines.t
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
[:commits_count_by_author, :insertions_by_author, :deletions_by_author].each do |method|
|
||||
|
|
|
@ -40,7 +40,7 @@ describe GitStats::GitData::Commit do
|
|||
double(lines_count: 0, extension: '.haml'),
|
||||
double(lines_count: 20, extension: '.css'),
|
||||
)
|
||||
commit.lines_by_extension.should == {'.rb' => 100, '.css' => 20}
|
||||
commit.lines_by_extension_count.should == {'.rb' => 100, '.css' => 20}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,7 +46,7 @@ describe GitStats::GitData::Repo do
|
|||
end
|
||||
|
||||
it 'should count lines by extension in repo' do
|
||||
repo.lines_by_extension.should == {'.haml' => 100, '.txt' => 1008, '.rb' => 6}
|
||||
repo.lines_by_extension_count.should == {'.haml' => 100, '.txt' => 1008, '.rb' => 6}
|
||||
end
|
||||
|
||||
it 'should count commits_count_by_author' do
|
||||
|
|
Loading…
Reference in a new issue