Module: MongoModel::DocumentExtensions::Indexes::ClassMethods

Defined in:
lib/mongomodel/document/indexes.rb

Instance Method Summary collapse

Instance Method Details

#ensure_indexes!Object


38
39
40
41
42
43
44
# File 'lib/mongomodel/document/indexes.rb', line 38

def ensure_indexes!
  indexes.each do |index|
    collection.create_index(*index.to_args)
  end

  @_indexes_initialized = true
end

#index(*args) ⇒ Object


27
28
29
30
31
32
# File 'lib/mongomodel/document/indexes.rb', line 27

def index(*args)
  index = Index.new(*args)
  self.indexes << index
  @_indexes_initialized = false
  index
end

#indexesObject


19
20
21
# File 'lib/mongomodel/document/indexes.rb', line 19

def indexes
  @_indexes ||= []
end

#indexes=(indexes) ⇒ Object


23
24
25
# File 'lib/mongomodel/document/indexes.rb', line 23

def indexes=(indexes)
  @_indexes = indexes
end

#indexes_initialized?Boolean


34
35
36
# File 'lib/mongomodel/document/indexes.rb', line 34

def indexes_initialized?
  @_indexes_initialized == true
end

#inherited(subclass) ⇒ Object


46
47
48
49
# File 'lib/mongomodel/document/indexes.rb', line 46

def inherited(subclass)
  super
  subclass.indexes = indexes.dup
end

#property(name, *args, &block) ⇒ Object

:nodoc:


13
14
15
16
17
# File 'lib/mongomodel/document/indexes.rb', line 13

def property(name, *args, &block) #:nodoc:
  property = super
  index(name) if property.options[:index]
  property
end