Sha256: 17acaef1d0b3de3127952b3b70d49e2d3ec238218d1d30bb6de8b71424ab5469

Contents?: true

Size: 843 Bytes

Versions: 8

Compression:

Stored size: 843 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc
  module Indexes #:nodoc
    def self.included(base)
      base.class_eval do
        extend ClassMethods

        cattr_accessor :indexed
        self.indexed = false
      end
    end

    module ClassMethods #:nodoc
      # Add the default indexes to the root document if they do not already
      # exist. Currently this is only _type.
      def add_indexes
        if hereditary && !indexed
          self._collection.create_index(:_type, :unique => false, :background => true)
          self.indexed = true
        end
      end

      # Adds an index on the field specified. Options can be :unique => true or
      # :unique => false. It will default to the latter.
      def index(name, options = { :unique => false })
        collection.create_index(name, options)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 4 rubygems

Version Path
mongoid-1.9.5 lib/mongoid/indexes.rb
mongoid-with-auth-1.9.4 lib/mongoid/indexes.rb
mongoid-rails2-1.9.4 lib/mongoid/indexes.rb
mongoid-rails2-1.9.3 lib/mongoid/indexes.rb
mongoid-1.9.2 lib/mongoid/indexes.rb
sskirby-mongoid-1.9.1 lib/mongoid/indexes.rb
mongoid-1.9.1 lib/mongoid/indexes.rb
mongoid-1.9.0 lib/mongoid/indexes.rb