Module: Mongoid::Threaded
Overview
This module contains logic for easy access to objects that have a lifecycle on the current thread.
Instance Method Summary collapse
-
#assign_stack ⇒ Array
Get the assign stack for the current thread.
-
#assigning? ⇒ true, false
Is the current thread in assigning mode?.
-
#begin_assign ⇒ true
Begins a assigning block.
-
#begin_bind ⇒ true
Begins a binding block.
-
#begin_build ⇒ true
Begins a building block.
-
#begin_create ⇒ true
Begins a creating block.
-
#begin_validate(document) ⇒ Object
Begin validating a document on the current thread.
-
#bind_stack ⇒ Array
Get the bind stack for the current thread.
-
#binding? ⇒ true, false
Is the current thread in binding mode?.
-
#build_stack ⇒ Array
Get the build stack for the current thread.
-
#building? ⇒ true, false
Is the current thread in building mode?.
-
#clear_safety_options! ⇒ nil
Clear out all the safety options set using the safely proxy.
-
#create_stack ⇒ Array
Get the create stack for the current thread.
-
#creating? ⇒ true, false
Is the current thread in creating mode?.
-
#exit_assign ⇒ true
Exit the assigning block.
-
#exit_bind ⇒ true
Exit the binding block.
-
#exit_build ⇒ true
Exit the building block.
-
#exit_create ⇒ true
Exit the creating block.
-
#exit_validate(document) ⇒ Object
Exit validating a document on the current thread.
-
#identity_map ⇒ IdentityMap
Get the identity map off the current thread.
-
#insert ⇒ Object
Get the insert consumer from the current thread.
-
#insert=(consumer) ⇒ Object
Set the insert consumer on the current thread.
-
#safety_options ⇒ Hash
Get the safety options for the current thread.
-
#safety_options=(options) ⇒ Hash
Set the safety options on the current thread.
-
#scope_stack ⇒ Hash
Get the mongoid scope stack for chained criteria.
-
#set_update_consumer(klass, consumer) ⇒ Object
Set the update consumer on the current thread.
-
#update_consumer(klass) ⇒ Object
Get the update consumer from the current thread.
-
#validated?(document) ⇒ true, false
Is the document validated on the current thread?.
-
#validations ⇒ Hash
Get all validations on the current thread.
-
#validations_for(klass) ⇒ Array
Get all validations on the current thread for the class.
Instance Method Details
#assign_stack ⇒ Array
Get the assign stack for the current thread. Is simply an array of calls to Mongoid’s assigning method.
126 127 128 |
# File 'lib/mongoid/threaded.rb', line 126 def assign_stack Thread.current[:"[mongoid]:assign-stack"] ||= [] end |
#assigning? ⇒ true, false
Is the current thread in assigning mode?
77 78 79 |
# File 'lib/mongoid/threaded.rb', line 77 def assigning? !assign_stack.empty? end |
#begin_assign ⇒ true
Begins a assigning block.
17 18 19 |
# File 'lib/mongoid/threaded.rb', line 17 def begin_assign assign_stack.push(true) end |
#begin_bind ⇒ true
Begins a binding block.
29 30 31 |
# File 'lib/mongoid/threaded.rb', line 29 def begin_bind bind_stack.push(true) end |
#begin_build ⇒ true
Begins a building block.
41 42 43 |
# File 'lib/mongoid/threaded.rb', line 41 def begin_build build_stack.push(true) end |
#begin_create ⇒ true
Begins a creating block.
53 54 55 |
# File 'lib/mongoid/threaded.rb', line 53 def begin_create create_stack.push(true) end |
#begin_validate(document) ⇒ Object
Begin validating a document on the current thread.
65 66 67 |
# File 'lib/mongoid/threaded.rb', line 65 def begin_validate(document) validations_for(document.class).push(document.id) end |
#bind_stack ⇒ Array
Get the bind stack for the current thread. Is simply an array of calls to Mongoid’s binding method.
139 140 141 |
# File 'lib/mongoid/threaded.rb', line 139 def bind_stack Thread.current[:"[mongoid]:bind-stack"] ||= [] end |
#binding? ⇒ true, false
Is the current thread in binding mode?
89 90 91 |
# File 'lib/mongoid/threaded.rb', line 89 def binding? !bind_stack.empty? end |
#build_stack ⇒ Array
Get the build stack for the current thread. Is simply an array of calls to Mongoid’s building method.
152 153 154 |
# File 'lib/mongoid/threaded.rb', line 152 def build_stack Thread.current[:"[mongoid]:build-stack"] ||= [] end |
#building? ⇒ true, false
Is the current thread in building mode?
101 102 103 |
# File 'lib/mongoid/threaded.rb', line 101 def building? !build_stack.empty? end |
#clear_safety_options! ⇒ nil
Clear out all the safety options set using the safely proxy.
177 178 179 |
# File 'lib/mongoid/threaded.rb', line 177 def Thread.current[:"[mongoid]:safety-options"] = nil end |
#create_stack ⇒ Array
Get the create stack for the current thread. Is simply an array of calls to Mongoid’s creating method.
165 166 167 |
# File 'lib/mongoid/threaded.rb', line 165 def create_stack Thread.current[:"[mongoid]:create-stack"] ||= [] end |
#creating? ⇒ true, false
Is the current thread in creating mode?
113 114 115 |
# File 'lib/mongoid/threaded.rb', line 113 def creating? !create_stack.empty? end |
#exit_assign ⇒ true
Exit the assigning block.
189 190 191 |
# File 'lib/mongoid/threaded.rb', line 189 def exit_assign assign_stack.pop end |
#exit_bind ⇒ true
Exit the binding block.
201 202 203 |
# File 'lib/mongoid/threaded.rb', line 201 def exit_bind bind_stack.pop end |
#exit_build ⇒ true
Exit the building block.
213 214 215 |
# File 'lib/mongoid/threaded.rb', line 213 def exit_build build_stack.pop end |
#exit_create ⇒ true
Exit the creating block.
225 226 227 |
# File 'lib/mongoid/threaded.rb', line 225 def exit_create create_stack.pop end |
#exit_validate(document) ⇒ Object
Exit validating a document on the current thread.
237 238 239 |
# File 'lib/mongoid/threaded.rb', line 237 def exit_validate(document) validations_for(document.class).delete_one(document.id) end |
#identity_map ⇒ IdentityMap
Get the identity map off the current thread.
249 250 251 |
# File 'lib/mongoid/threaded.rb', line 249 def identity_map Thread.current[:"[mongoid]:identity-map"] ||= IdentityMap.new end |
#insert ⇒ Object
Get the insert consumer from the current thread.
261 262 263 |
# File 'lib/mongoid/threaded.rb', line 261 def insert Thread.current[:"[mongoid]:insert-consumer"] end |
#insert=(consumer) ⇒ Object
Set the insert consumer on the current thread.
275 276 277 |
# File 'lib/mongoid/threaded.rb', line 275 def insert=(consumer) Thread.current[:"[mongoid]:insert-consumer"] = consumer end |
#safety_options ⇒ Hash
Get the safety options for the current thread.
287 288 289 |
# File 'lib/mongoid/threaded.rb', line 287 def Thread.current[:"[mongoid]:safety-options"] end |
#safety_options=(options) ⇒ Hash
Set the safety options on the current thread.
301 302 303 |
# File 'lib/mongoid/threaded.rb', line 301 def () Thread.current[:"[mongoid]:safety-options"] = end |
#scope_stack ⇒ Hash
Get the mongoid scope stack for chained criteria.
313 314 315 |
# File 'lib/mongoid/threaded.rb', line 313 def scope_stack Thread.current[:"[mongoid]:scope-stack"] ||= {} end |
#set_update_consumer(klass, consumer) ⇒ Object
Set the update consumer on the current thread.
339 340 341 |
# File 'lib/mongoid/threaded.rb', line 339 def set_update_consumer(klass, consumer) Thread.current[:"[mongoid][#{klass}]:update-consumer"] = consumer end |
#update_consumer(klass) ⇒ Object
Get the update consumer from the current thread.
325 326 327 |
# File 'lib/mongoid/threaded.rb', line 325 def update_consumer(klass) Thread.current[:"[mongoid][#{klass}]:update-consumer"] end |
#validated?(document) ⇒ true, false
Is the document validated on the current thread?
353 354 355 |
# File 'lib/mongoid/threaded.rb', line 353 def validated?(document) validations_for(document.class).include?(document.id) end |
#validations ⇒ Hash
Get all validations on the current thread.
365 366 367 |
# File 'lib/mongoid/threaded.rb', line 365 def validations Thread.current[:"[mongoid]:validations"] ||= {} end |
#validations_for(klass) ⇒ Array
Get all validations on the current thread for the class.
379 380 381 |
# File 'lib/mongoid/threaded.rb', line 379 def validations_for(klass) validations[klass] ||= [] end |