Sha256: 5a76571ed3ec81d37fb607c2e9f5a5e5a075cd5fc35007c392c598206af115ac

Contents?: true

Size: 1001 Bytes

Versions: 3

Compression:

Stored size: 1001 Bytes

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 = type ? type : options.klass
          child = klass.instantiate(:_parent => parent)
          child.write_attributes(self.merge(:_type => klass.name))
          child.identify
          child.assimilate(parent, options)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-1.1.1 lib/mongoid/extensions/hash/assimilation.rb
mongoid-1.1.0 lib/mongoid/extensions/hash/assimilation.rb
mongoid-1.0.6 lib/mongoid/extensions/hash/assimilation.rb