2004-11-23 20:04:44 -05:00
|
|
|
module ActionView
|
|
|
|
module Helpers
|
2007-05-06 01:19:02 -04:00
|
|
|
# Provides a set of methods for making it easier to debug Rails objects.
|
2004-11-23 20:04:44 -05:00
|
|
|
module DebugHelper
|
2007-05-06 01:19:02 -04:00
|
|
|
# Returns a <pre>-tag that has +object+ dumped by YAML. This creates a very
|
|
|
|
# readable way to inspect an object.
|
|
|
|
#
|
|
|
|
# ==== Example
|
2007-03-27 10:04:06 -04:00
|
|
|
# my_hash = {'first' => 1, 'second' => 'two', 'third' => [1,2,3]}
|
|
|
|
# debug(my_hash)
|
2007-05-06 01:19:02 -04:00
|
|
|
#
|
2007-03-27 10:04:06 -04:00
|
|
|
# => <pre class='debug_dump'>---
|
|
|
|
# first: 1
|
|
|
|
# second: two
|
|
|
|
# third:
|
|
|
|
# - 1
|
|
|
|
# - 2
|
|
|
|
# - 3
|
|
|
|
# </pre>
|
2004-11-23 20:04:44 -05:00
|
|
|
def debug(object)
|
|
|
|
begin
|
|
|
|
Marshal::dump(object)
|
|
|
|
"<pre class='debug_dump'>#{h(object.to_yaml).gsub(" ", " ")}</pre>"
|
2006-08-30 23:16:28 -04:00
|
|
|
rescue Exception => e # errors from Marshal or YAML
|
2004-11-23 20:04:44 -05:00
|
|
|
# Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
|
|
|
|
"<code class='debug_dump'>#{h(object.inspect)}</code>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|