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, #remove_excluded_files, #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



17
18
19
# File 'lib/generators/flay.rb', line 17

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

#emitObject



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

def emit
  files_to_flay = MetricFu.flay[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
  files = remove_excluded_files(files_to_flay.flatten)
  mimimum_score_parameter = MetricFu.flay[:minimum_score] ? "--mass #{MetricFu.flay[:minimum_score]} " : ""
  @output = `flay #{mimimum_score_parameter}#{files.join(" ")}`
end

#to_hObject



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

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