Class: Humanoid::Factory

Inherits:
Object show all
Defined in:
lib/humanoid/factory.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.build(klass, attrs) ⇒ Object

Builds a new Document from the supplied attributes.

Example:

Humanoid::Factory.build(Person, {})

Options:

klass: The class to instantiate from if _type is not present. attributes: The Document attributes.



14
15
16
17
# File 'lib/humanoid/factory.rb', line 14

def self.build(klass, attrs)
  type = attrs["_type"]
  type ? type.constantize.instantiate(attrs) : klass.instantiate(attrs)
end