4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/merb_inspector/helper.rb', line 4
def inspect(*args)
return h(super()) if args.blank?
object = args.shift
options = args.shift || {}
unless options.is_a?(Hash)
action = options.to_s
options = args.shift || {}
options[:action] = action
end
options[:action] ||= :show
options[:level] ||= 1
options[:max_level] ||= 3
valid_keys = [:action, :level, :max_level, :only, :except, :columns, :lead]
unknown_keys = options.keys - valid_keys
if !unknown_keys.blank?
return h("[INSPECTOR ERROR] Unknown key(s): %s" % unknown_keys.inspect)
end
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
|