Class: MetricFu::Churn

Inherits:
Generator show all
Defined in:
lib/generators/churn.rb

Defined Under Namespace

Classes: Git, SourceControl, Svn

Instance Attribute Summary

Attributes inherited from Generator

#report, #template

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generator

class_name, #create_data_dir_if_missing, #create_metric_dir_if_missing, #create_output_dir_if_missing, generate_report, #generate_report, metric_directory, #metric_directory, #round_to_tenths, #to_graph, verify_dependencies!

Constructor Details

#initialize(options = {}) ⇒ Churn

Returns a new instance of Churn.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/generators/churn.rb', line 7

def initialize(options={})
  super
  if self.class.git?
    @source_control = Git.new(MetricFu.churn[:start_date])
  elsif File.exist?(".svn")
    @source_control = Svn.new(MetricFu.churn[:start_date])
  else
    raise "Churning requires a subversion or git repo"
  end
  @minimum_churn_count = MetricFu.churn[:minimum_churn_count] || 5
end

Class Method Details

.git?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/generators/churn.rb', line 19

def self.git?
  system("git branch")
end

Instance Method Details

#analyzeObject



27
28
29
30
# File 'lib/generators/churn.rb', line 27

def analyze
  @changes = @changes.to_a.sort {|x,y| y[1] <=> x[1]}
  @changes = @changes.map {|change| {:file_path => change[0], :times_changed => change[1] }}
end

#emitObject



23
24
25
# File 'lib/generators/churn.rb', line 23

def emit
  @changes = parse_log_for_changes.reject {|file, change_count| change_count < @minimum_churn_count}
end

#to_hObject



32
33
34
# File 'lib/generators/churn.rb', line 32

def to_h
  {:churn => {:changes => @changes}}
end