Froze rails gems
[depot.git] / vendor / rails / actionpack / lib / action_view / helpers / debug_helper.rb
1 module ActionView
2 module Helpers
3 # Provides a set of methods for making it easier to debug Rails objects.
4 module DebugHelper
5 # Returns a YAML representation of +object+ wrapped with <pre> and </pre>.
6 # If the object cannot be converted to YAML using +to_yaml+, +inspect+ will be called instead.
7 # Useful for inspecting an object at the time of rendering.
8 #
9 # ==== Example
10 #
11 # @user = User.new({ :username => 'testing', :password => 'xyz', :age => 42}) %>
12 # debug(@user)
13 # # =>
14 # <pre class='debug_dump'>--- !ruby/object:User
15 # attributes:
16 # &nbsp; updated_at:
17 # &nbsp; username: testing
18 #
19 # &nbsp; age: 42
20 # &nbsp; password: xyz
21 # &nbsp; created_at:
22 # attributes_cache: {}
23 #
24 # new_record: true
25 # </pre>
26
27 def debug(object)
28 begin
29 Marshal::dump(object)
30 "<pre class='debug_dump'>#{h(object.to_yaml).gsub(" ", "&nbsp; ")}</pre>"
31 rescue Exception => e # errors from Marshal or YAML
32 # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
33 "<code class='debug_dump'>#{h(object.inspect)}</code>"
34 end
35 end
36 end
37 end
38 end