Sha256: 146e217f7f2427558075277d897f8ec0e15234adccb8cc9463bd976b44c2bd8e

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Hash #:nodoc:
      module Assimilation #:nodoc:
        # 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:
        #
        # <tt>{:first_name => "Hank", :last_name => "Moody"}.assimilate(name, options)</tt>
        #
        # Returns: The child +Document+.
        def assimilate(parent, options, type = nil)
          klass = self.klass || (type ? type : options.klass)
          child = klass.instantiate("_id" => self["_id"])
          self.merge("_type" => klass.name) if klass.hereditary
          init(parent, child, options)
        end

        protected

        def init(parent, child, options)
          child.parentize(parent, options.name)
          child.write_attributes(self)
          child.identify
          child.reset_modifications
          child.notify
          child
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
mongoid-2.0.0.beta.15 lib/mongoid/extensions/hash/assimilation.rb
mongoid-2.0.0.beta.14 lib/mongoid/extensions/hash/assimilation.rb
mongoid-2.0.0.beta.13 lib/mongoid/extensions/hash/assimilation.rb
mongoid-2.0.0.beta.11 lib/mongoid/extensions/hash/assimilation.rb
mongoid-2.0.0.beta.10 lib/mongoid/extensions/hash/assimilation.rb
mongoid-2.0.0.beta.8 lib/mongoid/extensions/hash/assimilation.rb
mongoid-2.0.0.beta.9 lib/mongoid/extensions/hash/assimilation.rb
mongoid-2.0.0.beta.12 lib/mongoid/extensions/hash/assimilation.rb
mongoid-locomotive-2.0.0.beta9 lib/mongoid/extensions/hash/assimilation.rb