Class: Mongoid::Factory
Overview
:nodoc:
Class Method Summary collapse
-
.build(klass, attributes) ⇒ Object
Builds a new
Document
from the supplied attributes.
Class Method Details
.build(klass, attributes) ⇒ Object
Builds a new Document
from the supplied attributes.
Example:
Mongoid::Factory.build(Person, {})
Options:
klass: The class to instantiate from if _type is not present. attributes: The Document
attributes.
14 15 16 17 18 |
# File 'lib/mongoid/factory.rb', line 14 def self.build(klass, attributes) attrs = {}.merge(attributes) type = attrs["_type"] type ? type.constantize.instantiate(attrs) : klass.instantiate(attrs) end |