Module: Mongoid::Threaded
- Extended by:
- Threaded
- Included in:
- Threaded
- Defined in:
- lib/mongoid/threaded.rb,
lib/mongoid/threaded/lifecycle.rb
Overview
This module contains logic for easy access to objects that have a lifecycle on the current thread.
Defined Under Namespace
Modules: Lifecycle
Instance Method Summary (collapse)
-
- (true, false) autosaved?(document)
Is the document autosaved on the current thread?.
-
- (Hash) autosaves
Get all autosaves on the current thread.
-
- (Array) autosaves_for(klass)
Get all autosaves on the current thread for the class.
-
- (true) begin(name)
Begin entry into a named thread local stack.
-
- (Object) begin_autosave(document)
Begin autosaving a document on the current thread.
-
- (Object) begin_validate(document)
Begin validating a document on the current thread.
-
- (Object) clear_options!
Clear out all options set on a one-time basis.
-
- (true) clear_persistence_options(klass)
Clear out all the persistence options.
-
- (Object) disable_identity_map(option)
Disable the identity map on either the current thread or all threads.
-
- (Object) enable_identity_map(option)
Enable the identity map on either the current thread or all threads.
-
- (true) executing?(name)
Are in the middle of executing the named stack.
-
- (true) exit(name)
Exit from a named thread local stack.
-
- (Object) exit_autosave(document)
Exit autosaving a document on the current thread.
-
- (Object) exit_validate(document)
Exit validating a document on the current thread.
-
- (IdentityMap) identity_map
Get the identity map off the current thread.
-
- (true, false) identity_map_enabled?
Is the identity map enabled on the current thread?.
-
- (Object) insert(name)
Get the insert consumer from the current thread.
-
- (Hash) persistence_options(klass)
Get the persistence options for the current thread.
-
- (Hash) scope_stack
Get the mongoid scope stack for chained criteria.
-
- (Hash) selection
Get the field selection options from the current thread.
-
- (Hash) selection=(value)
Set the field selection on the current thread.
-
- (Hash) sessions
Get the database sessions from the current thread.
-
- (Object) set_insert(name, consumer)
Set the insert consumer on the current thread.
-
- (Hash) set_persistence_options(klass, options)
Set the persistence options on the current thread.
-
- (Array) stack(name)
Get the named stack.
-
- (true, false) timeless
Get the value of the one-off timeless call.
-
- (Object) timeless=(value)
Set the value of the one-off timeless call.
-
- (true, false) timestamping?
Is the current thread setting timestamps?.
-
- (true, false) validated?(document)
Is the document validated on the current thread?.
-
- (Hash) validations
Get all validations on the current thread.
-
- (Array) validations_for(klass)
Get all validations on the current thread for the class.
Instance Method Details
- (true, false) autosaved?(document)
Is the document autosaved on the current thread?
357 358 359 |
# File 'lib/mongoid/threaded.rb', line 357 def autosaved?(document) autosaves_for(document.class).include?(document.id) end |
- (Hash) autosaves
Get all autosaves on the current thread.
383 384 385 |
# File 'lib/mongoid/threaded.rb', line 383 def autosaves Thread.current["[mongoid]:autosaves"] ||= {} end |
- (Array) autosaves_for(klass)
Get all autosaves on the current thread for the class.
409 410 411 |
# File 'lib/mongoid/threaded.rb', line 409 def autosaves_for(klass) autosaves[klass] ||= [] end |
- (true) begin(name)
Begin entry into a named thread local stack.
21 22 23 |
# File 'lib/mongoid/threaded.rb', line 21 def begin(name) stack(name).push(true) end |
- (Object) begin_autosave(document)
Begin autosaving a document on the current thread.
87 88 89 |
# File 'lib/mongoid/threaded.rb', line 87 def begin_autosave(document) autosaves_for(document.class).push(document.id) end |
- (Object) begin_validate(document)
Begin validating a document on the current thread.
99 100 101 |
# File 'lib/mongoid/threaded.rb', line 99 def begin_validate(document) validations_for(document.class).push(document.id) end |
- (Object) clear_options!
Clear out all options set on a one-time basis.
124 125 126 |
# File 'lib/mongoid/threaded.rb', line 124 def self.timeless = false end |
- (true) clear_persistence_options(klass)
Clear out all the persistence options.
113 114 115 116 |
# File 'lib/mongoid/threaded.rb', line 113 def (klass) Thread.current["[mongoid][#{klass}]:persistence-options"] = nil true end |
- (Object) disable_identity_map(option)
Disable the identity map on either the current thread or all threads.
187 188 189 190 191 192 193 194 195 |
# File 'lib/mongoid/threaded.rb', line 187 def disable_identity_map(option) if option == :all Thread.list.each do |thread| thread["[mongoid]:identity-map-enabled"] = false end else Thread.current["[mongoid]:identity-map-enabled"] = false end end |
- (Object) enable_identity_map(option)
Enable the identity map on either the current thread or all threads.
208 209 210 211 212 213 214 215 216 |
# File 'lib/mongoid/threaded.rb', line 208 def enable_identity_map(option) if option == :all Thread.list.each do |thread| thread["[mongoid]:identity-map-enabled"] = true end else Thread.current["[mongoid]:identity-map-enabled"] = true end end |
- (true) executing?(name)
Are in the middle of executing the named stack
47 48 49 |
# File 'lib/mongoid/threaded.rb', line 47 def executing?(name) !stack(name).empty? end |
- (true) exit(name)
Exit from a named thread local stack.
61 62 63 |
# File 'lib/mongoid/threaded.rb', line 61 def exit(name) stack(name).pop end |
- (Object) exit_autosave(document)
Exit autosaving a document on the current thread.
136 137 138 |
# File 'lib/mongoid/threaded.rb', line 136 def exit_autosave(document) autosaves_for(document.class).delete_one(document.id) end |
- (Object) exit_validate(document)
Exit validating a document on the current thread.
148 149 150 |
# File 'lib/mongoid/threaded.rb', line 148 def exit_validate(document) validations_for(document.class).delete_one(document.id) end |
- (IdentityMap) identity_map
Get the identity map off the current thread.
160 161 162 |
# File 'lib/mongoid/threaded.rb', line 160 def identity_map Thread.current["[mongoid]:identity-map"] ||= IdentityMap.new end |
- (true, false) identity_map_enabled?
Is the identity map enabled on the current thread?
172 173 174 |
# File 'lib/mongoid/threaded.rb', line 172 def identity_map_enabled? Thread.current["[mongoid]:identity-map-enabled"] != false end |
- (Object) insert(name)
Get the insert consumer from the current thread.
226 227 228 |
# File 'lib/mongoid/threaded.rb', line 226 def insert(name) Thread.current["[mongoid][#{name}]:insert-consumer"] end |
- (Hash) persistence_options(klass)
Get the persistence options for the current thread.
254 255 256 |
# File 'lib/mongoid/threaded.rb', line 254 def (klass) Thread.current["[mongoid][#{klass}]:persistence-options"] end |
- (Hash) scope_stack
Get the mongoid scope stack for chained criteria.
307 308 309 |
# File 'lib/mongoid/threaded.rb', line 307 def scope_stack Thread.current["[mongoid]:scope-stack"] ||= {} end |
- (Hash) selection
Get the field selection options from the current thread.
281 282 283 |
# File 'lib/mongoid/threaded.rb', line 281 def selection Thread.current["[mongoid]:selection"] end |
- (Hash) selection=(value)
Set the field selection on the current thread.
295 296 297 |
# File 'lib/mongoid/threaded.rb', line 295 def selection=(value) Thread.current["[mongoid]:selection"] = value end |
- (Hash) sessions
Get the database sessions from the current thread.
33 34 35 |
# File 'lib/mongoid/threaded.rb', line 33 def sessions Thread.current["[mongoid]:sessions"] ||= {} end |
- (Object) set_insert(name, consumer)
Set the insert consumer on the current thread.
240 241 242 |
# File 'lib/mongoid/threaded.rb', line 240 def set_insert(name, consumer) Thread.current["[mongoid][#{name}]:insert-consumer"] = consumer end |
- (Hash) set_persistence_options(klass, options)
Set the persistence options on the current thread.
269 270 271 |
# File 'lib/mongoid/threaded.rb', line 269 def (klass, ) Thread.current["[mongoid][#{klass}]:persistence-options"] = end |
- (Array) stack(name)
Get the named stack.
75 76 77 |
# File 'lib/mongoid/threaded.rb', line 75 def stack(name) Thread.current["[mongoid]:#{name}-stack"] ||= [] end |
- (true, false) timeless
Get the value of the one-off timeless call.
319 320 321 |
# File 'lib/mongoid/threaded.rb', line 319 def timeless !!Thread.current["[mongoid]:timeless"] end |
- (Object) timeless=(value)
Set the value of the one-off timeless call.
331 332 333 |
# File 'lib/mongoid/threaded.rb', line 331 def timeless=(value) Thread.current["[mongoid]:timeless"] = value end |
- (true, false) timestamping?
Is the current thread setting timestamps?
343 344 345 |
# File 'lib/mongoid/threaded.rb', line 343 def !timeless end |
- (true, false) validated?(document)
Is the document validated on the current thread?
371 372 373 |
# File 'lib/mongoid/threaded.rb', line 371 def validated?(document) validations_for(document.class).include?(document.id) end |
- (Hash) validations
Get all validations on the current thread.
395 396 397 |
# File 'lib/mongoid/threaded.rb', line 395 def validations Thread.current["[mongoid]:validations"] ||= {} end |
- (Array) validations_for(klass)
Get all validations on the current thread for the class.
422 423 424 |
# File 'lib/mongoid/threaded.rb', line 422 def validations_for(klass) validations[klass] ||= [] end |