module Mongoid::Threaded
def autosaved?(document)
-
(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
-
(Hash)- The current autosaves.
Other tags:
- Example: Get all autosaves. -
def autosaves Thread.current[AUTOSAVES_KEY] ||= {} end
def autosaves_for(klass)
-
(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)
-
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)
-
(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)
-
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)
- 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
-
(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
-
(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)
-
(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)
-
(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)
-
(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
-
(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)
-
(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)
-
flag(true | false) -- Whether or not document callbacks should be
def execute_callbacks=(flag) Thread.current[EXECUTE_CALLBACKS] = flag end
def execute_callbacks?
-
(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)
-
(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)
-
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)
-
(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)
-
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)
- 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
-
(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)
-
(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)
-
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)
-
(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)
-
(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
-
(Hash)- The current validations.
Other tags:
- Example: Get all validations. -
def validations Thread.current[VALIDATIONS_KEY] ||= {} end
def validations_for(klass)
-
(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)
- 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