Class: MetricFu::RailsBestPractices
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
Instance Method Details
#analyze ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/generators/rails_best_practices.rb', line 8
def analyze
@matches = @output.chomp.split("\n").map{|m| m.split(" - ") }
total = @matches.pop
cleanup_color_switches(total.first)
2.times { @matches.pop } @matches.reject! {|array| array.empty? }
@matches.map! do |match|
file, line = match[0].split(':')
problem = match[1]
cleanup_color_switches(file)
cleanup_color_switches(problem)
file.gsub!(/^\.\//, '')
{:file => file, :line => line, :problem => problem}
end
@rails_best_practices_results = {:total => total, :problems => @matches}
end
|
#cleanup_color_switches(str) ⇒ Object
29
30
31
32
33
|
# File 'lib/generators/rails_best_practices.rb', line 29
def cleanup_color_switches(str)
return if str.nil?
str.gsub!(%r{^\e\[3[1|2]m}, '')
str.gsub!(%r{\e\[0m$}, '')
end
|
#emit ⇒ Object
4
5
6
|
# File 'lib/generators/rails_best_practices.rb', line 4
def emit
@output = `rails_best_practices --without-color .`
end
|
#per_file_info(out) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/generators/rails_best_practices.rb', line 39
def per_file_info(out)
@rails_best_practices_results[:problems].each do |problem|
next if problem[:file] == '' || problem[:problem].nil?
out[problem[:file]] ||= {}
lines = problem[:line].split(/\s*,\s*/)
lines.each do |line|
out[problem[:file]][line] ||= []
out[problem[:file]][line] << {:type => :rails_best_practices, :description => problem[:problem]}
end
end
end
|
#to_h ⇒ Object
35
36
37
|
# File 'lib/generators/rails_best_practices.rb', line 35
def to_h
{:rails_best_practices => @rails_best_practices_results}
end
|