module Mongoid::Threaded

def autosaved?(document)

Returns:
  • (true | false) - If the document is autosaved.

Parameters:
  • document (Document) -- The document to check.

Other tags:
    Example: Is the document autosaved? -
def autosaved?(document)
  autosaves_for(document.class).include?(document._id)
end

def autosaves

Returns:
  • (Hash) - The current autosaves.

Other tags:
    Example: Get all autosaves. -
def autosaves
  Thread.current[AUTOSAVES_KEY] ||= {}
end

def autosaves_for(klass)

Returns:
  • (Array) - The current autosaves.

Parameters:
  • klass (Class) -- The class to check.

Other tags:
    Example: Get all autosaves. -
def autosaves_for(klass)
  autosaves[klass] ||= []
end

def begin_autosave(document)

Parameters:
  • document (Document) -- The document to autosave.

Other tags:
    Example: Begin autosave. -
def begin_autosave(document)
  autosaves_for(document.class).push(document._id)
end

def begin_execution(name)

Returns:
  • (true) - True.

Parameters:
  • name (String) -- The name of the stack

Other tags:
    Example: Begin entry into the stack. -
def begin_execution(name)
  stack(name).push(true)
end

def begin_validate(document)

Parameters:
  • document (Document) -- The document to validate.

Other tags:
    Example: Begin validation. -
def begin_validate(document)
  validations_for(document.class).push(document._id)
end

def begin_without_default_scope(klass)

Other tags:
    Api: - private

Parameters:
  • klass (Class) -- The model to suppress default scoping on.

Other tags:
    Example: Begin without default scope stack. -
def begin_without_default_scope(klass)
  stack(:without_default_scope).push(klass)
end

def clear_session

Returns:
  • (nil) -

Other tags:
    Example: Clear this thread's session. -
def clear_session
  session = get_session
  session.end_session if session
  Thread.current["[mongoid]:session"] = nil
end

def client_override

Returns:
  • (String | Symbol) - The override.

Other tags:
    Example: Get the global client override. -
def client_override
  Thread.current[CLIENT_OVERRIDE_KEY]
end

def client_override=(name)

Returns:
  • (String | Symbol) - The override.

Parameters:
  • name (String | Symbol) -- The global override name.

Other tags:
    Example: Set the global client override. -
def client_override=(name)
  Thread.current[CLIENT_OVERRIDE_KEY] = name
end

def current_scope(klass = nil)

Returns:
  • (Criteria) - The scope.

Parameters:
  • klass (Klass) -- The class type of the scope.

Other tags:
    Example: Get the scope. -
def current_scope(klass = nil)
  if klass && Thread.current[CURRENT_SCOPE_KEY].respond_to?(:keys)
    Thread.current[CURRENT_SCOPE_KEY][
        Thread.current[CURRENT_SCOPE_KEY].keys.find { |k| k <= klass }
    ]
  else
    Thread.current[CURRENT_SCOPE_KEY]
  end
end

def current_scope=(scope)

Returns:
  • (Criteria) - The scope.

Parameters:
  • scope (Criteria) -- The current scope.

Other tags:
    Example: Set the scope. -
def current_scope=(scope)
  Thread.current[CURRENT_SCOPE_KEY] = scope
end

def database_override

Returns:
  • (String | Symbol) - The override.

Other tags:
    Example: Get the global database override. -
def database_override
  Thread.current[DATABASE_OVERRIDE_KEY]
end

def database_override=(name)

Returns:
  • (String | Symbol) - The override.

Parameters:
  • name (String | Symbol) -- The global override name.

Other tags:
    Example: Set the global database override. -
def database_override=(name)
  Thread.current[DATABASE_OVERRIDE_KEY] = name
end

def execute_callbacks=(flag)

Parameters:
  • flag (true | false) -- Whether or not document callbacks should be
def execute_callbacks=(flag)
  Thread.current[EXECUTE_CALLBACKS] = flag
end

def execute_callbacks?

Returns:
  • (true | false) - Whether or not document callbacks should be
def execute_callbacks?
  if Thread.current.key?(EXECUTE_CALLBACKS)
    Thread.current[EXECUTE_CALLBACKS]
  else
    true
  end
end

def executing?(name)

Returns:
  • (true) - If the stack is being executed.

Parameters:
  • name (Symbol) -- The name of the stack

Other tags:
    Example: Are we in the stack execution? -
def executing?(name)
  !stack(name).empty?
end

def exit_autosave(document)

Parameters:
  • document (Document) -- The document to autosave.

Other tags:
    Example: Exit autosave. -
def exit_autosave(document)
  autosaves_for(document.class).delete_one(document._id)
end

def exit_execution(name)

Returns:
  • (true) - True.

Parameters:
  • name (Symbol) -- The name of the stack

Other tags:
    Example: Exit from the stack. -
def exit_execution(name)
  stack(name).pop
end

def exit_validate(document)

Parameters:
  • document (Document) -- The document to validate.

Other tags:
    Example: Exit validation. -
def exit_validate(document)
  validations_for(document.class).delete_one(document._id)
end

def exit_without_default_scope(klass)

Other tags:
    Api: - private

Parameters:
  • klass (Class) -- The model to unsuppress default scoping on.

Other tags:
    Example: Exit without default scope stack. -
def exit_without_default_scope(klass)
  stack(:without_default_scope).delete(klass)
end

def get_session

Returns:
  • (Mongo::Session | nil) - The session cached on this thread or nil.

Other tags:
    Example: Get the session for this thread. -
def get_session
  Thread.current["[mongoid]:session"]
end

def set_current_scope(scope, klass)

Returns:
  • (Criteria) - The scope.

Parameters:
  • klass (Class) -- The current model class.
  • scope (Criteria) -- The current scope.

Other tags:
    Example: Set the scope. -
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_session(session)

Parameters:
  • session (Mongo::Session) -- The session to save.

Other tags:
    Example: Save a session for this thread. -
def set_session(session)
  Thread.current["[mongoid]:session"] = session
end

def stack(name)

Returns:
  • (Array) - The stack.

Parameters:
  • name (Symbol) -- The name of the stack

Other tags:
    Example: Get a stack by name -
def stack(name)
  Thread.current[STACK_KEYS[name]] ||= []
end

def validated?(document)

Returns:
  • (true | false) - If the document is validated.

Parameters:
  • document (Document) -- The document to check.

Other tags:
    Example: Is the document validated? -
def validated?(document)
  validations_for(document.class).include?(document._id)
end

def validations

Returns:
  • (Hash) - The current validations.

Other tags:
    Example: Get all validations. -
def validations
  Thread.current[VALIDATIONS_KEY] ||= {}
end

def validations_for(klass)

Returns:
  • (Array) - The current validations.

Parameters:
  • klass (Class) -- The class to check.

Other tags:
    Example: Get all validations. -
def validations_for(klass)
  validations[klass] ||= []
end

def without_default_scope?(klass)

Other tags:
    Api: - private

Parameters:
  • klass (Class) -- The model to check for default scope suppression.

Other tags:
    Example: Is the given klass' default scope suppressed? -
def without_default_scope?(klass)
  stack(:without_default_scope).include?(klass)
end