Class: MetricFu::Flog
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/generators/flog.rb', line 28
def analyze
@method_containers = {}
@flogger.calls.each do |full_method_name, operators|
container_name = full_method_name.split('#').first
path = @flogger.method_locations[full_method_name]
if @method_containers[container_name]
@method_containers[container_name].add_method(full_method_name, operators, @flogger.totals[full_method_name], path)
@method_containers[container_name].add_path(path)
else
mc = MethodContainer.new(container_name, path)
mc.add_method(full_method_name, operators, @flogger.totals[full_method_name], path)
@method_containers[container_name] = mc
end
end
end
|
#emit ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/generators/flog.rb', line 9
def emit
files = []
MetricFu.flog[:dirs_to_flog].each do |directory|
directory = "." if directory=='./'
dir_files = Dir.glob("#{directory}/**/*.rb")
dir_files = remove_excluded_files(dir_files)
files += dir_files
end
options = ::Flog.parse_options ["--all", "--details"]
@flogger = ::Flog.new options
@flogger.flog files
rescue LoadError
if RUBY_PLATFORM =~ /java/
puts 'running in jruby - flog tasks not available'
end
end
|
#per_file_info(out) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/generators/flog.rb', line 51
def per_file_info(out)
@method_containers.each_pair do |klass, container|
container.methods.each_pair do |method_name, data|
next if data[:path].nil?
file, line = data[:path].split(':')
out[file] ||= {}
out[file][line] ||= []
out[file][line] << {:type => :flog, :description => "Score of %.2f" % data[:score]}
end
end
end
|
#to_h ⇒ Object
44
45
46
47
48
49
|
# File 'lib/generators/flog.rb', line 44
def to_h
sorted_containers = @method_containers.values.sort_by {|c| c.highest_score}.reverse
{:flog => { :total => @flogger.total,
:average => @flogger.average,
:method_containers => sorted_containers.map {|method_container| method_container.to_h}}}
end
|