Class: MetricFu::Reek

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

Constant Summary collapse

REEK_REGEX =
/^(\S+) (.*) \((.*)\)$/

Instance Attribute Summary

Attributes inherited from Generator

#report, #template

Instance Method Summary collapse

Methods inherited from Generator

class_name, #create_metric_dir_if_missing, #create_output_dir_if_missing, generate_report, #generate_report, #initialize, metric_directory, #metric_directory, #round_to_tenths

Constructor Details

This class inherits a constructor from MetricFu::Generator

Instance Method Details

#analyzeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/reek.rb', line 11

def analyze
  @matches = @output.chomp.split("\n\n").map{|m| m.split("\n") }
  @matches = @matches.map do |match|
    file_path = match.shift.split('--').first
    file_path = file_path.gsub('"', ' ').strip
    code_smells = match.map do |smell|
      match_object = smell.match(REEK_REGEX)
      {:method => match_object[1].strip,
       :message => match_object[2].strip,
       :type => match_object[3].strip}
    end
    {:file_path => file_path, :code_smells => code_smells}
  end
end

#emitObject



6
7
8
9
# File 'lib/generators/reek.rb', line 6

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

#to_hObject



26
27
28
# File 'lib/generators/reek.rb', line 26

def to_h
  {:reek => {:matches => @matches}}
end