mirror of
https://github.com/tomgi/git_stats.git
synced 2025-01-03 11:12:11 +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] }]
|
@files_by_extension_count ||= Hash[files_by_extension.map { |ext, files| [ext, files.count] }]
|
||||||
end
|
end
|
||||||
|
|
||||||
def lines_by_extension
|
def lines_by_extension_count
|
||||||
@lines_by_extension ||= Hash[files_by_extension.map { |ext, files|
|
@lines_by_extension ||= Hash[files_by_extension.map { |ext, files|
|
||||||
[ext, files.map(&:lines_count).sum]
|
[ext, files.map(&:lines_count).sum]
|
||||||
}.delete_if { |ext, lines_count| lines_count == 0 }]
|
}.delete_if { |ext, lines_count| lines_count == 0 }]
|
||||||
|
|
|
@ -7,7 +7,7 @@ module GitStats
|
||||||
|
|
||||||
attr_reader :path
|
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
|
:files_count, :binary_files, :text_files, :lines_count, to: :last_commit
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
|
|
|
@ -6,44 +6,26 @@ module GitStats
|
||||||
@repo = repo
|
@repo = repo
|
||||||
end
|
end
|
||||||
|
|
||||||
def files_by_extension
|
[:lines, :files].each do |type|
|
||||||
|
define_method "#{type}_by_extension" do
|
||||||
Chart.new do |f|
|
Chart.new do |f|
|
||||||
f.column_hash_chart(
|
f.column_hash_chart(
|
||||||
data: @repo.files_by_extension_count,
|
data: @repo.send("#{type}_by_extension_count"),
|
||||||
title: :files_by_extension.t,
|
title: "#{type}_extension".to_sym.t,
|
||||||
y_text: :files.t
|
y_text: type.to_sym.t
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def lines_by_extension
|
define_method "#{type}_by_date" do
|
||||||
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
|
|
||||||
Chart.new do |f|
|
Chart.new do |f|
|
||||||
f.date_chart(
|
f.date_chart(
|
||||||
data: @repo.files_count_by_date,
|
data: @repo.send("#{type}_count_by_date"),
|
||||||
title: :files_by_date.t,
|
title: "#{type}_by_date".to_sym.t,
|
||||||
y_text: :files.t
|
y_text: type.to_sym.t
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
[:commits_count_by_author, :insertions_by_author, :deletions_by_author].each do |method|
|
[: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: 0, extension: '.haml'),
|
||||||
double(lines_count: 20, extension: '.css'),
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,7 +46,7 @@ describe GitStats::GitData::Repo do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should count lines by extension in repo' do
|
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
|
end
|
||||||
|
|
||||||
it 'should count commits_count_by_author' do
|
it 'should count commits_count_by_author' do
|
||||||
|
|
Loading…
Reference in a new issue