Sha256: 90eb20b1d58612de799f6c56f60b6307b28e003992f319344af0d097bf60e4b3

Contents?: true

Size: 809 Bytes

Versions: 27

Compression:

Stored size: 809 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
        unless indexed
          self._collection.create_index(:_type, false)
          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[:unique])
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
mongoid-1.2.14 lib/mongoid/indexes.rb
mongoid-1.2.13 lib/mongoid/indexes.rb
mongoid-1.2.12 lib/mongoid/indexes.rb
mongoid-1.2.11 lib/mongoid/indexes.rb
mongoid-1.2.10 lib/mongoid/indexes.rb
mongoid-1.2.9 lib/mongoid/indexes.rb
mongoid-1.2.8 lib/mongoid/indexes.rb
mongoid-1.2.7 lib/mongoid/indexes.rb
mongoid-1.2.6 lib/mongoid/indexes.rb
mongoid-1.2.5 lib/mongoid/indexes.rb
mongoid-1.2.4 lib/mongoid/indexes.rb
mongoid-1.2.3 lib/mongoid/indexes.rb
mongoid-1.2.2 lib/mongoid/indexes.rb
mongoid-1.2.1 lib/mongoid/indexes.rb
mongoid-1.2.0 lib/mongoid/indexes.rb
mongoid-1.1.4 lib/mongoid/indexes.rb
mongoid-1.1.3 lib/mongoid/indexes.rb
mongoid-1.1.2 lib/mongoid/indexes.rb
mongoid-1.1.1 lib/mongoid/indexes.rb
mongoid-1.1.0 lib/mongoid/indexes.rb