Class: MetricFu::Saikuro

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

Defined Under Namespace

Classes: ParsingElement, SFile

Instance Attribute Summary

Attributes inherited from Generator

#report, #template

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

Instance Method Details

#analyzeObject



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

def analyze
  @files = sort_files(assemble_files)
  @classes = sort_classes(assemble_classes(@files))
  @meths = sort_methods(assemble_methods(@files))
end

#emitObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/generators/saikuro.rb', line 5

def emit
  options_string = MetricFu.saikuro.inject("") do |options, option|
    option[0] == :input_directory ? options : options + "--#{option.join(' ')} "
  end

  MetricFu.saikuro[:input_directory].each do |input_dir|
    options_string += "--input_directory #{input_dir} "
  end
  sh %{saikuro #{options_string}} do |ok, response|
    unless ok
      puts "Saikuro failed with exit status: #{response.exitstatus}"
      exit 1
    end
  end
end

#format_directoriesObject



21
22
23
24
# File 'lib/generators/saikuro.rb', line 21

def format_directories
  dirs = MetricFu.saikuro[:input_directory].join(" | ")
  "\"#{dirs}\""
end

#per_file_info(out) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/saikuro.rb', line 50

def per_file_info(out)
  @saikuro_data[:files].each do |file_data|
    next if File.extname(file_data[:filename]) == '.erb' || !File.exists?(file_data[:filename])
    begin
      line_numbers = MetricFu::LineNumbers.new(File.open(file_data[:filename], 'r').read)
    rescue StandardError => e
      raise e unless e.message =~ /you shouldn't be able to get here/
      puts "ruby_parser blew up while trying to parse #{file_path}. You won't have method level Saikuro information for this file."
      next
    end

    out[file_data[:filename]] ||= {}
    file_data[:classes].each do |class_data|
      class_data[:methods].each do |method_data|
        line = line_numbers.start_line_for_method(method_data[:name])
        out[file_data[:filename]][line.to_s] ||= []
        out[file_data[:filename]][line.to_s] << {:type => :saikuro,
                                                  :description => "Complexity #{method_data[:complexity]}"}
      end
    end
  end
end

#to_hObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/saikuro.rb', line 32

def to_h
  files = @files.map do |file|
    my_file = file.to_h

    f = file.filepath
    f.gsub!(%r{^#{metric_directory}/}, '')
    f << "/#{file.filename}"

    my_file[:filename] = f
    my_file
  end
  @saikuro_data = {:files => files,
                   :classes => @classes.map {|c| c.to_h},
                   :methods => @meths.map {|m| m.to_h}
                  }
  {:saikuro => @saikuro_data}
end