Module: Merb::Inspector::Helper

Included in:
Controller
Defined in:
lib/merb_inspector/helper.rb

Instance Method Summary collapse

Instance Method Details

#inspect(object = nil, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/merb_inspector/helper.rb', line 4

def inspect(object = nil, options = {})
  return h(super()) unless object

  options = options.is_a?(Hash) ? options : {:action=>options}
  options[:action]    ||= :show
  options[:level]     ||= 1
  options[:max_level] ||= 3

  inspector_class = BasicInspector if object == self
  inspector_class = BasicInspector if options[:level] >= options[:max_level]
  inspector_class ||= Manager.lookup(object) || Merb::Inspector.default

  inspector = inspector_class.new(Merb::Request.new({}))
  if inspector.respond_to?(options[:action])
    inspector.send options[:action], object, options
  else
    message = "%s doesn't recognize '%s' action" % [inspector.class, options[:action]]
    raise Merb::Inspector::ActionNotFound, message
  end
end