Class: Turbulence

Inherits:
Object
  • Object
show all
Defined in:
lib/turbulence.rb,
lib/turbulence/version.rb,
lib/turbulence/scatter_plot_generator.rb

Defined Under Namespace

Classes: Reporter, ScatterPlotGenerator

Constant Summary collapse

VERSION =
"0.0.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Turbulence

Returns a new instance of Turbulence.



13
14
15
16
17
18
19
20
# File 'lib/turbulence.rb', line 13

def initialize(dir)
  @dir = dir
  @metrics = {}
  Dir.chdir(dir) do
    churn
    complexity
  end
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



11
12
13
# File 'lib/turbulence.rb', line 11

def dir
  @dir
end

#metricsObject (readonly)

Returns the value of attribute metrics.



12
13
14
# File 'lib/turbulence.rb', line 12

def metrics
  @metrics
end

Instance Method Details

#churnObject



27
28
29
30
31
32
33
# File 'lib/turbulence.rb', line 27

def churn
  files = changes_by_ruby_file.select { |_, filename| ruby_files.include?(filename) }
  files.each do |count, filename|
    print "."
    metrics_for(filename)[:churn] = Integer(count)
  end
end

#complexityObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/turbulence.rb', line 35

def complexity
  flogger = Flog.new
  ruby_files.each do |filename|
    print "."

    begin
      flogger.flog filename
      reporter = Reporter.new
      flogger.report(reporter)
      metrics_for(filename)[:complexity] = reporter.average
    rescue SyntaxError, Racc::ParseError => e
      puts "\nError flogging: #{filename}\n"
    end
  end
end

#metrics_for(filename) ⇒ Object



51
52
53
# File 'lib/turbulence.rb', line 51

def metrics_for(filename)
  @metrics[filename] ||= {}
end

#ruby_filesObject



22
23
24
25
# File 'lib/turbulence.rb', line 22

def ruby_files
  files = ["app/models", "app/controllers", "app/helpers", "lib"].map{|base_dir| "#{base_dir}/**/*\.rb"}
  @ruby_files ||= Dir[*files]
end