lib/mongoid/factory.rb in mongoid-1.2.3 vs lib/mongoid/factory.rb in mongoid-1.2.4
- old
+ new
@@ -7,11 +7,13 @@
#
# <tt>Mongoid::Factory.build(Person, {})</tt>
#
# Options:
#
+ # klass: The class to instantiate from if _type is not present.
# attributes: The +Document+ attributes.
- def self.build(attributes)
- attributes["_type"].constantize.instantiate(attributes)
+ def self.build(klass, attrs)
+ type = attrs["_type"]
+ type ? type.constantize.instantiate(attrs) : klass.instantiate(attrs)
end
end
end