Sha256: 0092f0ee5d37f1651ff423b40e5a8a49e44469c38ff9320f29f84275d68f7cdc

Contents?: true

Size: 911 Bytes

Versions: 2

Compression:

Stored size: 911 Bytes

Contents

module Merb
  class Inspector
    module Helper
      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 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
    end
  end
end

class Merb::Controller
  include Merb::Inspector::Helper
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
maiha-merb_inspector-0.2.5.1 lib/merb_inspector/helper.rb
maiha-merb_inspector-0.2.6 lib/merb_inspector/helper.rb