Class: Turbulence::Calculators::Churn
- Inherits:
-
Object
- Object
- Turbulence::Calculators::Churn
- Defined in:
- lib/turbulence/calculators/churn.rb
Constant Summary collapse
- RUBY_FILE_EXTENSION =
".rb"
Class Attribute Summary collapse
-
.commit_range ⇒ Object
Returns the value of attribute commit_range.
-
.compute_mean ⇒ Object
Returns the value of attribute compute_mean.
-
.scm ⇒ Object
Returns the value of attribute scm.
Class Method Summary collapse
- .calculate_mean_of_churn(churn, sample_size) ⇒ Object
- .changes_by_ruby_file ⇒ Object
- .churn_for_file(filename, stats) ⇒ Object
- .counted_line_changes_by_file_by_commit ⇒ Object
- .for_these_files(files) ⇒ Object
- .ruby_files_changed_in_scm ⇒ Object
- .scm_log_command ⇒ Object
- .scm_log_file_lines ⇒ Object
Class Attribute Details
.commit_range ⇒ Object
Returns the value of attribute commit_range.
7 8 9 |
# File 'lib/turbulence/calculators/churn.rb', line 7 def commit_range @commit_range end |
.compute_mean ⇒ Object
Returns the value of attribute compute_mean.
7 8 9 |
# File 'lib/turbulence/calculators/churn.rb', line 7 def compute_mean @compute_mean end |
.scm ⇒ Object
Returns the value of attribute scm.
7 8 9 |
# File 'lib/turbulence/calculators/churn.rb', line 7 def scm @scm end |
Class Method Details
.calculate_mean_of_churn(churn, sample_size) ⇒ Object
27 28 29 30 |
# File 'lib/turbulence/calculators/churn.rb', line 27 def calculate_mean_of_churn(churn, sample_size) return churn if sample_size < 1 churn /= sample_size end |
.changes_by_ruby_file ⇒ Object
15 16 17 18 19 |
# File 'lib/turbulence/calculators/churn.rb', line 15 def changes_by_ruby_file ruby_files_changed_in_scm.group_by(&:first).map do |filename, stats| churn_for_file(filename,stats) end end |
.churn_for_file(filename, stats) ⇒ Object
21 22 23 24 25 |
# File 'lib/turbulence/calculators/churn.rb', line 21 def churn_for_file(filename,stats) churn = stats[0..-2].map(&:last).inject(0){|running_total, changes| running_total + changes} churn = calculate_mean_of_churn(churn, stats.size - 1) if compute_mean [filename, churn] end |
.counted_line_changes_by_file_by_commit ⇒ Object
38 39 40 41 42 43 |
# File 'lib/turbulence/calculators/churn.rb', line 38 def counted_line_changes_by_file_by_commit scm_log_file_lines.map do |line| adds, deletes, filename = line.split(/\t/) [filename, adds.to_i + deletes.to_i] end end |
.for_these_files(files) ⇒ Object
9 10 11 12 13 |
# File 'lib/turbulence/calculators/churn.rb', line 9 def for_these_files(files) changes_by_ruby_file.each do |filename, count| yield filename, count if files.include?(filename) end end |
.ruby_files_changed_in_scm ⇒ Object
32 33 34 35 36 |
# File 'lib/turbulence/calculators/churn.rb', line 32 def ruby_files_changed_in_scm counted_line_changes_by_file_by_commit.select do |filename, _| filename.end_with?(RUBY_FILE_EXTENSION) && File.exist?(filename) end end |
.scm_log_command ⇒ Object
49 50 51 |
# File 'lib/turbulence/calculators/churn.rb', line 49 def scm_log_command scm.log_command(commit_range) end |
.scm_log_file_lines ⇒ Object
45 46 47 |
# File 'lib/turbulence/calculators/churn.rb', line 45 def scm_log_file_lines scm_log_command.each_line.reject{|line| line == "\n"}.map(&:chomp) end |