Module: Ripple::EmbeddedDocument::Finders::ClassMethods

Defined in:
lib/ripple/embedded_document/finders.rb

Instance Method Summary collapse

Instance Method Details

#instantiate(attrs) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ripple/embedded_document/finders.rb', line 11

def instantiate(attrs)
  begin
    klass = attrs['_type'].present? ? attrs.delete('_type').constantize : self
  rescue NameError
    klass = self
  end
  klass.new.tap do |object|
    object.raw_attributes = attrs
    object.changed_attributes.clear
  end
end