Sha256: a60cd393ba8eb5281f96d01083d636c3dfe77f535bbab83a7ac2db4e1520d1b3

Contents?: true

Size: 1.04 KB

Versions: 11

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8
module Mongoid # :nodoc:
  module Relations #:nodoc:
    module Builders #:nodoc:
      module Embedded #:nodoc:
        class Many < Builder #:nodoc:

          # Builds the document out of the attributes using the provided
          # metadata on the relation. Instantiates through the factory in order
          # to make sure subclasses and allocation are used if fitting. This
          # case will return many documents.
          #
          # @example Build the documents.
          #   Builder.new(meta, attrs).build
          #
          # @param [ String ] type Not used in this context.
          #
          # @return [ Array<Document ] The documents.
          def build(type = nil)
            return [] if object.blank?
            return object if object.first.is_a?(Document)
            object.inject([]) do |documents, attrs|
              documents.tap do |docs|
                docs << Mongoid::Factory.build(metadata.klass, attrs)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
mongoid-2.0.1 lib/mongoid/relations/builders/embedded/many.rb
mongoid-2.0.0 lib/mongoid/relations/builders/embedded/many.rb
mongoid-2.0.0.rc.8 lib/mongoid/relations/builders/embedded/many.rb
mongoid-2.0.0.rc.7 lib/mongoid/relations/builders/embedded/many.rb
stonegao-mongoid-2.0.0.rc.6 lib/mongoid/relations/builders/embedded/many.rb
mongoid-2.0.0.rc.6 lib/mongoid/relations/builders/embedded/many.rb
mongoid-2.0.0.rc.5 lib/mongoid/relations/builders/embedded/many.rb
mongoid-2.0.0.rc.4 lib/mongoid/relations/builders/embedded/many.rb
mongoid-2.0.0.rc.3 lib/mongoid/relations/builders/embedded/many.rb
mongoid-2.0.0.rc.2 lib/mongoid/relations/builders/embedded/many.rb
mongoid-2.0.0.rc.1 lib/mongoid/relations/builders/embedded/many.rb