Module: AwesomePrint::MongoMapper

Defined in:
lib/awesome_print/ext/mongo_mapper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
# 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

Instance Method Details

#awesome_mongo_mapper_class(object) ⇒ Object

Format MongoMapper class object.




26
27
28
29
30
31
32
33
34
# 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) ⇒ Object

Add MongoMapper class names to the dispatcher pipeline.




16
17
18
19
20
21
22
# 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