Method: Mongoid::Scopable::ClassMethods#with_scope

Defined in:
lib/mongoid/scopable.rb

#with_scope(criteria) ⇒ Criteria

Pushes the provided criteria onto the scope stack, and removes it after the provided block is yielded.

Examples:

Yield to the criteria.

Person.with_scope(criteria)


209
210
211
212
213
214
215
216
217
# File 'lib/mongoid/scopable.rb', line 209

def with_scope(criteria)
  previous = Threaded.current_scope(self)
  Threaded.set_current_scope(criteria, self)
  begin
    yield criteria
  ensure
    Threaded.set_current_scope(previous, self)
  end
end