module AwesomePrint::MongoMapper
Public Class Methods
included(base)
click to toggle source
# File lib/awesome_print/ext/mongo_mapper.rb, line 9 def self.included(base) base.send :alias_method, :cast_without_mongo_mapper, :cast base.send :alias_method, :cast, :cast_with_mongo_mapper end
Public Instance Methods
awesome_mongo_mapper_class(object)
click to toggle source
Format MongoMapper
class object.
# File lib/awesome_print/ext/mongo_mapper.rb, line 26 def awesome_mongo_mapper_class(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:keys) data = object.keys.sort.inject(::ActiveSupport::OrderedHash.new) do |hash, c| hash[c.first] = (c.last.type || "undefined").to_s.underscore.intern hash end "class #{object} < #{object.superclass} " << awesome_hash(data) end
cast_with_mongo_mapper(object, type)
click to toggle source
Add MongoMapper
class names to the dispatcher pipeline.
# File lib/awesome_print/ext/mongo_mapper.rb, line 16 def cast_with_mongo_mapper(object, type) cast = cast_without_mongo_mapper(object, type) if defined?(::MongoMapper::Document) && object.is_a?(Class) && (object.ancestors & [ ::MongoMapper::Document, ::MongoMapper::EmbeddedDocument ]).size > 0 cast = :mongo_mapper_class end cast end