Module: RailsMetricsHelper::PayloadInspect

Included in:
RailsMetricsHelper
Defined in:
app/helpers/rails_metrics_helper.rb

Instance Method Summary collapse

Instance Method Details

#payload_inspect(hash) ⇒ Object

Inspect payload to show more human readable information.



39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/rails_metrics_helper.rb', line 39

def payload_inspect(hash)
  hash = hash.sort {|a,b| a[0].to_s <=> b[0].to_s }
  content = []

  hash.each do |key, value|
    content << ((:b, key.to_s.humanize).safe_concat("<br />") << pretty_inspect(value))
  end

  content.map!{ |c| (:p, c) }
  content.join("\n").html_safe
end

#pretty_inspect(object) ⇒ Object

Inspect a value using a more readable format.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/rails_metrics_helper.rb', line 52

def pretty_inspect(object)
  case object
    when String
      object
    when Array
      "[#{object.map(&:inspect).join(", ")}]"
    when Hash
      hash = object.map { |k,v| "  #{k.inspect} => #{pretty_inspect(v)}" }.join(",\n")
      if object.size == 1
        "{ #{hash[2..-1]} }"
      else
        "{\n#{hash}\n}"
      end
    else
      object.inspect
  end
end