Class: MetricFu::Flay

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

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, #initialize, #metric_directory, metric_directory, #round_to_tenths, #to_graph

Constructor Details

This class inherits a constructor from MetricFu::Generator

Class Method Details

.verify_dependencies!Object



5
6
7
8
# File 'lib/generators/flay.rb', line 5

def self.verify_dependencies!
  `flay --help`
  raise 'sudo gem install flay # if you want the flay tasks' unless $?.success?
end

Instance Method Details

#analyzeObject



15
16
17
# File 'lib/generators/flay.rb', line 15

def analyze
  @matches = @output.chomp.split("\n\n").map{|m| m.split("\n  ") }
end

#emitObject



10
11
12
13
# File 'lib/generators/flay.rb', line 10

def emit
  files_to_flay = MetricFu.flay[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
  @output = `flay #{files_to_flay.join(" ")}`
end

#to_hObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/flay.rb', line 19

def to_h
  target = []
  total_score = @matches.shift.first.split('=').last.strip
  @matches.each do |problem|
    reason = problem.shift.strip
    lines_info = problem.map do |full_line|
      name, line = full_line.split(":")
      {:name => name.strip, :line => line.strip}
    end
    target << [:reason => reason, :matches => lines_info]
  end
  {:flay => {:total_score => total_score, :matches => target.flatten}}
end