Sha256: 614a7226f1d1b190da240aa2c94a051b79356c0db6ef4933eac2d5b71f9aca0d

Contents?: true

Size: 858 Bytes

Versions: 8

Compression:

Stored size: 858 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:

  # This module handles functionality for creating default scopes.
  module DefaultScope

    # Creates a default_scope for the +Document+, similar to ActiveRecord's
    # default_scope. +DefaultScopes+ are proxied +Criteria+ objects that are
    # applied by default to all queries for the class.
    #
    # @example Create a default scope.
    #
    #   class Person
    #     include Mongoid::Document
    #     field :active, :type => Boolean
    #     field :count, :type => Integer
    #
    #     default_scope :where => { :active => true }
    #   end
    #
    # @param [ Hash ] conditions The conditions to create with.
    #
    # @since 2.0.0.rc.1
    def default_scope(conditions = {}, &block)
      self.scope_stack << criteria.fuse(Scope.new(conditions, &block).conditions.scoped)
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
mongoid-2.0.0.rc.7 lib/mongoid/default_scope.rb
stonegao-mongoid-2.0.0.rc.6 lib/mongoid/default_scope.rb
mongoid-2.0.0.rc.6 lib/mongoid/default_scope.rb
mongoid-2.0.0.rc.5 lib/mongoid/default_scope.rb
mongoid-2.0.0.rc.4 lib/mongoid/default_scope.rb
mongoid-2.0.0.rc.3 lib/mongoid/default_scope.rb
mongoid-2.0.0.rc.2 lib/mongoid/default_scope.rb
mongoid-2.0.0.rc.1 lib/mongoid/default_scope.rb