Module: Humanoid::Extensions::Hash::Assimilation
- Included in:
- Hash
- Defined in:
- lib/humanoid/extensions/hash/assimilation.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#assimilate(parent, options, type = nil) ⇒ Object
Introduces a child object into the
Document
object graph.
Instance Method Details
#assimilate(parent, options, type = nil) ⇒ Object
Introduces a child object into the Document
object graph. This will set up the relationships between the parent and child and update the attributes of the parent Document
.
Options:
parent: The Document
to assimilate into. options: The association Options
for the child.
Example:
{:first_name => "Hank", :last_name => "Moody"}.assimilate(name, options)
Returns: The child Document
.
20 21 22 23 24 25 26 |
# File 'lib/humanoid/extensions/hash/assimilation.rb', line 20 def assimilate(parent, , type = nil) klass = type ? type : .klass child = klass.instantiate(:_parent => parent) child.write_attributes(self.merge("_type" => klass.name)) child.identify child.assimilate(parent, ) end |