Module: Mongoid::Extras::ClassMethods

Defined in:
lib/mongoid/extras.rb

Overview

:nodoc

Instance Method Summary collapse

Instance Method Details

#cacheObject

Sets caching on for this class. This class level configuration will default all queries to cache the results of the first iteration over the cursor into an internal array. This should only be used for queries that return a small number of results or have small documents, as after the first iteration the entire results will be stored in memory.

Example:

class Person
  include Mongoid::Document
  cache
end


25
26
27
# File 'lib/mongoid/extras.rb', line 25

def cache
  self.cached = true
end

#cached?Boolean

Determines if the class is cached or not.

Returns:

True if cached, false if not.

Returns:



34
35
36
# File 'lib/mongoid/extras.rb', line 34

def cached?
  !!self.cached
end

#enslaveObject

Set whether or not this documents read operations should delegate to the slave database by default.

Example:

class Person
  include Mongoid::Document
  enslave
end


47
48
49
# File 'lib/mongoid/extras.rb', line 47

def enslave
  self.enslaved = true
end

#enslaved?Boolean

Determines if the class is enslaved or not.

Returns:

True if enslaved, false if not.

Returns:



56
57
58
# File 'lib/mongoid/extras.rb', line 56

def enslaved?
  !!self.enslaved
end