def set_current_scope(scope, klass)
      if scope.nil?
        if Thread.current[CURRENT_SCOPE_KEY]
          Thread.current[CURRENT_SCOPE_KEY].delete(klass)
          Thread.current[CURRENT_SCOPE_KEY] = nil if Thread.current[CURRENT_SCOPE_KEY].empty?
        end
      else
        Thread.current[CURRENT_SCOPE_KEY] ||= {}
        Thread.current[CURRENT_SCOPE_KEY][klass] = scope
      end
    end
def set_current_scope(scope, klass)
      if scope.nil?
        if Thread.current[CURRENT_SCOPE_KEY]
          Thread.current[CURRENT_SCOPE_KEY].delete(klass)
          Thread.current[CURRENT_SCOPE_KEY] = nil if Thread.current[CURRENT_SCOPE_KEY].empty?
        end
      else
        Thread.current[CURRENT_SCOPE_KEY] ||= {}
        Thread.current[CURRENT_SCOPE_KEY][klass] = scope
      end
    end
Set the current Mongoid scope. Safe for multi-model scope chaining.

 @example Set the scope.
   Threaded.current_scope(scope, klass)

 @param [ Criteria ] scope The current scope.
 @param [ Class ] klass The current model class.

 @return [ Criteria ] The scope.

 @since 5.0.1