Module: AppReporter

Defined in:
lib/app_reporter.rb,
lib/app_reporter/railtie.rb,
lib/app_reporter/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
"1.0.0"

Instance Method Summary collapse

Instance Method Details

#brakeman_reportObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/app_reporter.rb', line 5

def brakeman_report
 	# Breakman source file
	file = File.read("#{Rails.root}/report.json")
	data_hash = JSON.parse(file)

	# collect information related to the application
	@breakman_info = {}
	@breakman_info['security_warnings'] = data_hash['scan_info']['security_warnings']
  @breakman_info['errors'] = data_hash['errors']

  # Create an array of all warnings
  @brakeman_warnings = []
  data_hash['warnings'].each do |warning|
  	hash = {}
  	hash['warning_type'] = warning['warning_type']
  	hash['warning_code'] = warning['warning_code']
  	hash['fingerprint'] = warning['fingerprint']
  	hash['message'] = warning['message']
  	hash['file'] = warning['file']
  	hash['line'] = warning['line']
  	hash['code'] = warning['code']
  	hash['render_path'] = warning['render_path']
  	hash['location'] = warning['location']
  	hash['user_input'] = warning['user_input']
  	hash['confidence'] = warning['confidence']
  	@brakeman_warnings.push(hash)
  end
end

#generate_final_reportObject


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/app_reporter.rb', line 94

def generate_final_report
 	spec = Gem::Specification.find_by_name 'app_reporter'
	erb_file = "/#{spec.gem_dir}/lib/app_reporter/templates/summary_report.html.erb"
	html_file = File.basename(erb_file, '.erb') 
	erb_str = File.read(erb_file)

 	@flog_info = @matric_fu_info.select{|d| d.keys.first == 'flog'}
 	@stats_info = @matric_fu_info.select{|d| d.keys.first == 'stats'}
 	@rails_best_practices_info = @matric_fu_info.select{|d| d.keys.first == 'rails_best_practices'}
 	@app_root = Rails.root

  begin
		renderer = ERB.new(erb_str)
		result = renderer.result()

		File.open(html_file, 'w') do |f|
		  f.write(result)
		end
	rescue StandardError => e
  	p e.message
  	p e.backtrace
  end
end

#metric_fu_reportObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/app_reporter.rb', line 34

def metric_fu_report
  # parsing metric_fu report from .yml file
  @surveys = YAML.load(ERB.new(File.read("#{Rails.root}/tmp/metric_fu/report.yml")).result)
   @matric_fu_info = []

   @surveys.each do |survey|
   	unless survey.blank?
   		p "===== From #{survey[0]} ====="
      case survey[0]
			when :flog
      	hash = {}
				# hash['flog'] = "Flog measures code complexity. Total Flog score for all methods: #{survey[1][:total].round(1)}. Average Flog score for all methods: #{survey[1][:average].round(1)}"
				hash['flog'] = survey[1][:average].round(1)
				@matric_fu_info.push(hash)
			when :stats
				hash = {}
				# hash['stats'] = "Lines of Code/Tests Metric Results. Lines of Code: #{survey[1][:codeLOC]}. Lines of Test: #{survey[1][:testLOC]}. Code to test ratio: #{survey[1][:code_to_test_ratio]}."
				hash['stats'] = survey[1][:code_to_test_ratio]
				hash['codeLOC'] = survey[1][:codeLOC]
				hash['testLOC'] = survey[1][:testLOC]
				@matric_fu_info.push(hash) 
			when :roodi
				hash = {}
				hash['roodi'] = "Roodi parses Ruby code and warns about design issues. #{survey[1][:total].first} and found #{survey[1][:problems].count} problems."
				@matric_fu_info.push(hash)
			when :reek
				hash = {}
				hash['reek'] = "Reek detects common code smells in ruby code. Found #{survey[1][:matches].count} matches."
				@matric_fu_info.push(hash)
			when :cane
				hash = {}
				hash['cane'] = "Cane reports code quality threshold violations. Found total #{survey[1][:violations].count} types of #{survey[1][:total_violations]} violations."
				@matric_fu_info.push(hash)
		  when :flay
		  	hash = {}
		  	hash['flay'] = "Flay analyzes ruby code for structural similarities. Total Score (lower is better): #{survey[1][:total_score]}."
		  	@matric_fu_info.push(hash)
		  when :churn
		  	hash = {}
		  	hash['churn'] = "Source Control Churn Results. Files that change a lot in your project may be bad a sign. Count: #{survey[1][:changes].count}."
		  	@matric_fu_info.push(hash)
		  when :saikuro
		  	hash = {}
		  	hash['saikuro'] = "Saikuro analyzes ruby code for cyclomatic complexity. Analyzed #{survey[1][:files].count} Classes."
		  	@matric_fu_info.push(hash)
		  when :rails_best_practices
		  	hash = {}
		  	hash['rails_best_practices'] = survey[1][:total].first.gsub(/[^\d]/, '').to_i
		  	@matric_fu_info.push(hash)
			when :hotspots
				hash = {}
				hash['hotspots'] = "Meta analysis of metrics to find hotspots in code. Hotspot Results: #{survey[1]['files'].count}."
				@matric_fu_info.push(hash)
			else
			  puts "No Report"
			end
		end
   end
end