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)

Parameters:

  • criteria (Criteria)

    The criteria to apply.

Returns:

Since:

  • 1.0.0



224
225
226
227
228
229
230
231
# File 'lib/mongoid/scopable.rb', line 224

def with_scope(criteria)
  Threaded.set_current_scope(criteria, self)
  begin
    yield criteria
  ensure
    Threaded.set_current_scope(nil, self)
  end
end