12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/rails-idle/web_helpers.rb', line 12
def iterate(obj, parent = 1, &block)
idx = parent
obj.each do |k, v|
next if k.is_a?(Symbol)
idx += 1
total_renderings = renderings(v)
children_count = v.keys.reject{|k| k.is_a?(Symbol) }.count
notused_childrens = children_count > 0 ? v.reject{ |k, _| k.is_a?(Symbol) }.values.select{ |v| v.empty? || renderings(v) == 0}.count : 0
if children_count == 0
klass = total_renderings > 0 ? 'success' : 'danger'
elsif notused_childrens == 0
klass = 'success'
else
klass = (notused_childrens.to_f / children_count.to_f) > 0.5 ? 'danger' : 'warning'
end
info = {
idx: idx,
parent: parent,
class: klass,
renderings: total_renderings,
execution: v[RailsIdle::Storage::EXECUTION_KEY],
childrens: children_count,
idle: notused_childrens
}
block.call(k, info)
idx = iterate(v, idx, &block)
end
idx
end
|