Sha256: c7a7c078d52cf995c97c71c69dd93697ca66e0ef2b7fbf75252106407120aab0

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc
  # The collections module is used for providing functionality around setting
  # up and updating collections.
  module Collections
    extend ActiveSupport::Concern
    included do
      cattr_accessor :_collection, :collection_name
      self.collection_name = self.name.collectionize
      delegate :collection, :to => "self.class"
    end

    module ClassMethods #:nodoc:
      # Returns the collection associated with this +Document+. If the
      # document is embedded, there will be no collection associated
      # with it.
      #
      # Returns: <tt>Mongo::Collection</tt>
      def collection
        raise Errors::InvalidCollection.new(self) if embedded?
        self._collection || set_collection
        add_indexes; self._collection
      end

      # Macro for setting the collection name to store in.
      #
      # Example:
      #
      # <tt>Person.store_in :populdation</tt>
      def store_in(name)
        self.collection_name = name.to_s
        set_collection
      end

      protected
      def set_collection
        self._collection = Mongoid::Collection.new(self, self.collection_name)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 5 rubygems

Version Path
mongoid-1.9.5 lib/mongoid/collections.rb
mongoid-with-auth-1.9.4 lib/mongoid/collections.rb
mongoid-rails2-1.9.4 lib/mongoid/collections.rb
mongoid-rails2-1.9.3 lib/mongoid/collections.rb
mongoid-1.9.2 lib/mongoid/collections.rb
sskirby-mongoid-1.9.1 lib/mongoid/collections.rb
mongoid-1.9.1 lib/mongoid/collections.rb
chhean-mongoid-2.0.1.beta1 lib/mongoid/collections.rb
mongoid-2.0.0.beta.5 lib/mongoid/collections.rb
mongoid-1.9.0 lib/mongoid/collections.rb