Sha256: 148d0cce748ba926f6f28f38f400f81a2b083b7db64e9fbad2de4486c910a9a8

Contents?: true

Size: 843 Bytes

Versions: 14

Compression:

Stored size: 843 Bytes

Contents

module MongoMapper
  module Plugins
    module Associations
      class EmbeddedCollection < Collection
        def build(attributes={})
          doc = klass.new(attributes)
          assign_references(doc)
          self << doc
          doc
        end

        def find(id)
          load_target
          target.detect { |item| item.id.to_s == id || item.id == id }
        end

        def count
          load_target
          target.size
        end

        def <<(*docs)
          load_target
          docs.each do |doc|
            assign_references(doc)
            target << doc
          end
        end
        alias_method :push, :<<
        alias_method :concat, :<<

        private
          def assign_references(*docs)
            docs.each { |doc| doc._parent_document = owner }
          end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
pwnash-mongo_mapper-0.7.5 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.7.6 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.7.5 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper_ign-0.7.4 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.7.4 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.7.3 lib/mongo_mapper/plugins/associations/embedded_collection.rb
numon-0.0.1 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.7.2 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.7.1 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.3.8 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.3.5 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.3.4 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.3.3 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.2.28 lib/mongo_mapper/plugins/associations/embedded_collection.rb