Sha256: b4e39819780bb6ebc63039ed2d8a2df9bf27eff141276c0dfc044d32954947c3

Contents?: true

Size: 867 Bytes

Versions: 60

Compression:

Stored size: 867 Bytes

Contents

# encoding: UTF-8
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 = proxy_owner }
          end
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 7 rubygems

Version Path
jonbell-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/associations/embedded_collection.rb
ign-mongo_mapper-0.8.6.2 lib/mongo_mapper/plugins/associations/embedded_collection.rb
ign-mongo_mapper-0.8.6.1 lib/mongo_mapper/plugins/associations/embedded_collection.rb
ssherman-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.8.6 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.8.5 lib/mongo_mapper/plugins/associations/embedded_collection.rb
honkster-mongo_mapper-0.8.4 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.8.4 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.19 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.18 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.17 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.16 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.15 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.14 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.13 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.12 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.11 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.10 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-unstable-2010.08.09 lib/mongo_mapper/plugins/associations/embedded_collection.rb
mongo_mapper-0.8.3 lib/mongo_mapper/plugins/associations/embedded_collection.rb