Class: Turbulence::Calculators::Churn
- Inherits:
-
Object
- Object
- Turbulence::Calculators::Churn
- Extended by:
- Forwardable
- Defined in:
- lib/turbulence/calculators/churn.rb
Constant Summary collapse
- RUBY_FILE_EXTENSION =
".rb"
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance 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
-
#initialize(config = nil) ⇒ Churn
constructor
A new instance of Churn.
- #ruby_files_changed_in_scm ⇒ Object
- #scm_log_command ⇒ Object
- #scm_log_file_lines ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Churn
Returns a new instance of Churn.
9 10 11 |
# File 'lib/turbulence/calculators/churn.rb', line 9 def initialize(config = nil) @config = config || Turbulence.config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/turbulence/calculators/churn.rb', line 8 def config @config end |
Instance Method Details
#calculate_mean_of_churn(churn, sample_size) ⇒ Object
38 39 40 41 |
# File 'lib/turbulence/calculators/churn.rb', line 38 def calculate_mean_of_churn(churn, sample_size) return churn if sample_size < 1 churn /= sample_size end |
#changes_by_ruby_file ⇒ Object
26 27 28 29 30 |
# File 'lib/turbulence/calculators/churn.rb', line 26 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
32 33 34 35 36 |
# File 'lib/turbulence/calculators/churn.rb', line 32 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
49 50 51 52 53 54 |
# File 'lib/turbulence/calculators/churn.rb', line 49 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
20 21 22 23 24 |
# File 'lib/turbulence/calculators/churn.rb', line 20 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
43 44 45 46 47 |
# File 'lib/turbulence/calculators/churn.rb', line 43 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
60 61 62 |
# File 'lib/turbulence/calculators/churn.rb', line 60 def scm_log_command scm.log_command(commit_range) end |
#scm_log_file_lines ⇒ Object
56 57 58 |
# File 'lib/turbulence/calculators/churn.rb', line 56 def scm_log_file_lines scm_log_command.each_line.reject{|line| line == "\n"}.map(&:chomp) end |