module RailsIdle module WebHelpers def root_path "#{env['SCRIPT_NAME']}/" end def row_class(obj) end 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 private def renderings(obj) obj[RailsIdle::Report::CALCULATED_KEY] || obj[RailsIdle::Report::COUNTER_KEY] || 0 end end end