Sha256: d96b4c095ffc2cae893fedb212a2836391100f21140fef259f2bc278f0b0f585

Contents?: true

Size: 1.52 KB

Versions: 32

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extras #:nodoc:
    extend ActiveSupport::Concern
    included do
      class_inheritable_accessor :cached, :enslaved
      self.cached = false
      self.enslaved = false
      delegate :cached?, :enslaved?, :to => "self.class"
    end

    module ClassMethods #:nodoc
      # 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
      def cache
        self.cached = true
      end

      # Determines if the class is cached or not.
      #
      # Returns:
      #
      # True if cached, false if not.
      def cached?
        !!self.cached
      end

      # Set whether or not this documents read operations should delegate to
      # the slave database by default.
      #
      # Example:
      #
      #   class Person
      #     include Mongoid::Document
      #     enslave
      #   end
      def enslave
        self.enslaved = true
      end

      # Determines if the class is enslaved or not.
      #
      # Returns:
      #
      # True if enslaved, false if not.
      def enslaved?
        !!self.enslaved
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 7 rubygems

Version Path
mongoid-1.9.5 lib/mongoid/extras.rb
mongoid-2.0.0.rc.5 lib/mongoid/extras.rb
mongoid-2.0.0.rc.4 lib/mongoid/extras.rb
mongoid-2.0.0.rc.3 lib/mongoid/extras.rb
mongoid-2.0.0.rc.2 lib/mongoid/extras.rb
mongoid-2.0.0.rc.1 lib/mongoid/extras.rb
mongoid-with-auth-1.9.4 lib/mongoid/extras.rb
mongoid-rails2-1.9.4 lib/mongoid/extras.rb
mongoid-rails2-1.9.3 lib/mongoid/extras.rb
mongoid-2.0.0.beta.20 lib/mongoid/extras.rb
mongoid-2.0.0.beta.19 lib/mongoid/extras.rb
mongoid-1.9.2 lib/mongoid/extras.rb
sskirby-mongoid-1.9.1 lib/mongoid/extras.rb
mongoid-2.0.0.beta.18 lib/mongoid/extras.rb
mongoid-2.0.0.beta.17 lib/mongoid/extras.rb
mongoid-2.0.0.beta.16 lib/mongoid/extras.rb
mongoid-2.0.0.beta.15 lib/mongoid/extras.rb
mongoid-2.0.0.beta.14 lib/mongoid/extras.rb
mongoid-2.0.0.beta.13 lib/mongoid/extras.rb
mongoid-2.0.0.beta.11 lib/mongoid/extras.rb