Module: Mongoid::Threaded

Extended by:
Threaded
Included in:
Threaded
Defined in:
lib/mongoid/threaded.rb,
lib/mongoid/threaded/lifecycle.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Lifecycle

Instance Method Summary collapse

Instance Method Details

#assign_stackArray

Get the assign stack for the current thread. Is simply an array of calls to Mongoid’s assigning method.

Examples:

Get the assign stack.

Threaded.assign_stack

Returns:

  • (Array)

    The array of assign calls.

Since:

  • 2.1.9



176
177
178
# File 'lib/mongoid/threaded.rb', line 176

def assign_stack
  Thread.current[:"[mongoid]:assign-stack"] ||= []
end

#assigning?true, false

Is the current thread in assigning mode?

Examples:

Is the thread in assigning mode?

Threaded.assigning?

Returns:

  • (true, false)

    If the thread is in assigning mode?

Since:

  • 2.1.0



103
104
105
# File 'lib/mongoid/threaded.rb', line 103

def assigning?
  !assign_stack.empty?
end

#begin_assigntrue

Begins a assigning block.

Examples:

Begin the assign.

Threaded.begin_assign

Returns:

  • (true)

    Always true.

Since:

  • 2.1.9



19
20
21
# File 'lib/mongoid/threaded.rb', line 19

def begin_assign
  assign_stack.push(true)
end

#begin_bindtrue

Begins a binding block.

Examples:

Begin the bind.

Threaded.begin_bind

Returns:

  • (true)

    Always true.

Since:

  • 2.1.9



31
32
33
# File 'lib/mongoid/threaded.rb', line 31

def begin_bind
  bind_stack.push(true)
end

#begin_buildtrue

Begins a building block.

Examples:

Begin the build.

Threaded.begin_build

Returns:

  • (true)

    Always true.

Since:

  • 2.1.9



43
44
45
# File 'lib/mongoid/threaded.rb', line 43

def begin_build
  build_stack.push(true)
end

#begin_createtrue

Begins a creating block.

Examples:

Begin the create.

Threaded.begin_create

Returns:

  • (true)

    Always true.

Since:

  • 2.1.9



55
56
57
# File 'lib/mongoid/threaded.rb', line 55

def begin_create
  create_stack.push(true)
end

#begin_loadtrue

Begins a loading block.

Examples:

Begin the load.

Threaded.begin_load

Returns:

  • (true)

    Always true.

Since:

  • 2.3.2



67
68
69
# File 'lib/mongoid/threaded.rb', line 67

def begin_load
  load_stack.push(true)
end

#begin_load_revisiontrue

Begins a loading revision block.

Examples:

Begin the revision load.

Threaded.begin_load_revision

Returns:

  • (true)

    Always true.

Since:

  • 2.3.4



79
80
81
# File 'lib/mongoid/threaded.rb', line 79

def begin_load_revision
  load_revision_stack.push(true)
end

#begin_validate(document) ⇒ Object

Begin validating a document on the current thread.

Examples:

Begin validation.

Threaded.begin_validate(doc)

Parameters:

  • document (Document)

    The document to validate.

Since:

  • 2.1.9



91
92
93
# File 'lib/mongoid/threaded.rb', line 91

def begin_validate(document)
  validations_for(document.class).push(document.id)
end

#bind_stackArray

Get the bind stack for the current thread. Is simply an array of calls to Mongoid’s binding method.

Examples:

Get the bind stack.

Threaded.bind_stack

Returns:

  • (Array)

    The array of bind calls.

Since:

  • 2.1.9



189
190
191
# File 'lib/mongoid/threaded.rb', line 189

def bind_stack
  Thread.current[:"[mongoid]:bind-stack"] ||= []
end

#binding?true, false

Is the current thread in binding mode?

Examples:

Is the thread in binding mode?

Threaded.binding?

Returns:

  • (true, false)

    If the thread is in binding mode?

Since:

  • 2.1.0



115
116
117
# File 'lib/mongoid/threaded.rb', line 115

def binding?
  !bind_stack.empty?
end

#build_stackArray

Get the build stack for the current thread. Is simply an array of calls to Mongoid’s building method.

Examples:

Get the build stack.

Threaded.build_stack

Returns:

  • (Array)

    The array of build calls.

Since:

  • 2.1.9



202
203
204
# File 'lib/mongoid/threaded.rb', line 202

def build_stack
  Thread.current[:"[mongoid]:build-stack"] ||= []
end

#building?true, false

Is the current thread in building mode?

Examples:

Is the thread in building mode?

Threaded.building?

Returns:

  • (true, false)

    If the thread is in building mode?

Since:

  • 2.1.0



127
128
129
# File 'lib/mongoid/threaded.rb', line 127

def building?
  !build_stack.empty?
end

#clear_options!Object

Clear out all options set on a one-time basis.

Examples:

Clear out the options.

Threaded.clear_options!

Since:

  • 2.3.0



263
264
265
266
# File 'lib/mongoid/threaded.rb', line 263

def clear_options!
  clear_safety_options!
  self.timeless = false
end

#clear_safety_options!nil

Clear out all the safety options set using the safely proxy.

Examples:

Clear out the options.

Threaded.clear_safety_options!

Returns:

  • (nil)

    nil

Since:

  • 2.1.0



253
254
255
# File 'lib/mongoid/threaded.rb', line 253

def clear_safety_options!
  Thread.current[:"[mongoid]:safety-options"] = nil
end

#create_stackArray

Get the create stack for the current thread. Is simply an array of calls to Mongoid’s creating method.

Examples:

Get the create stack.

Threaded.create_stack

Returns:

  • (Array)

    The array of create calls.

Since:

  • 2.1.9



215
216
217
# File 'lib/mongoid/threaded.rb', line 215

def create_stack
  Thread.current[:"[mongoid]:create-stack"] ||= []
end

#creating?true, false

Is the current thread in creating mode?

Examples:

Is the thread in creating mode?

Threaded.creating?

Returns:

  • (true, false)

    If the thread is in creating mode?

Since:

  • 2.1.0



139
140
141
# File 'lib/mongoid/threaded.rb', line 139

def creating?
  !create_stack.empty?
end

#exit_assigntrue

Exit the assigning block.

Examples:

Exit the assigning block.

Threaded.exit_assign

Returns:

  • (true)

    The last element in the stack.

Since:

  • 2.1.9



276
277
278
# File 'lib/mongoid/threaded.rb', line 276

def exit_assign
  assign_stack.pop
end

#exit_bindtrue

Exit the binding block.

Examples:

Exit the binding block.

Threaded.exit_bind

Returns:

  • (true)

    The last element in the stack.

Since:

  • 2.1.9



288
289
290
# File 'lib/mongoid/threaded.rb', line 288

def exit_bind
  bind_stack.pop
end

#exit_buildtrue

Exit the building block.

Examples:

Exit the building block.

Threaded.exit_build

Returns:

  • (true)

    The last element in the stack.

Since:

  • 2.1.9



300
301
302
# File 'lib/mongoid/threaded.rb', line 300

def exit_build
  build_stack.pop
end

#exit_createtrue

Exit the creating block.

Examples:

Exit the creating block.

Threaded.exit_create

Returns:

  • (true)

    The last element in the stack.

Since:

  • 2.1.9



312
313
314
# File 'lib/mongoid/threaded.rb', line 312

def exit_create
  create_stack.pop
end

#exit_loadtrue

Exit the loading block.

Examples:

Exit the loading block.

Threaded.exit_load

Returns:

  • (true)

    The last element in the stack.

Since:

  • 2.1.9



324
325
326
# File 'lib/mongoid/threaded.rb', line 324

def exit_load
  load_stack.pop
end

#exit_load_revisiontrue

Exit the revision loading block.

Examples:

Exit the revision loading block.

Threaded.exit_load_revision

Returns:

  • (true)

    The last element in the stack.

Since:

  • 2.3.4



336
337
338
# File 'lib/mongoid/threaded.rb', line 336

def exit_load_revision
  load_revision_stack.pop
end

#exit_validate(document) ⇒ Object

Exit validating a document on the current thread.

Examples:

Exit validation.

Threaded.exit_validate(doc)

Parameters:

  • document (Document)

    The document to validate.

Since:

  • 2.1.9



348
349
350
# File 'lib/mongoid/threaded.rb', line 348

def exit_validate(document)
  validations_for(document.class).delete_one(document.id)
end

#identity_mapIdentityMap

Get the identity map off the current thread.

Examples:

Get the identity map.

Threaded.identity_map

Returns:

Since:

  • 2.1.0



360
361
362
# File 'lib/mongoid/threaded.rb', line 360

def identity_map
  Thread.current[:"[mongoid]:identity-map"] ||= IdentityMap.new
end

#insertObject

Get the insert consumer from the current thread.

Examples:

Get the insert consumer.

Threaded.insert

Returns:

  • (Object)

    The batch insert consumer.

Since:

  • 2.1.0



372
373
374
# File 'lib/mongoid/threaded.rb', line 372

def insert
  Thread.current[:"[mongoid]:insert-consumer"]
end

#insert=(consumer) ⇒ Object

Set the insert consumer on the current thread.

Examples:

Set the insert consumer.

Threaded.insert = consumer

Parameters:

  • consumer (Object)

    The insert consumer.

Returns:

  • (Object)

    The insert consumer.

Since:

  • 2.1.0



386
387
388
# File 'lib/mongoid/threaded.rb', line 386

def insert=(consumer)
  Thread.current[:"[mongoid]:insert-consumer"] = consumer
end

#load_revision_stackArray

Get the revision load stack for the current thread. Is simply an array of calls to Mongoid’s loading_revision method.

Examples:

Get the revision load stack.

Threaded.load_revision_stack

Returns:

  • (Array)

    The array of load revision calls.

Since:

  • 2.3.4



241
242
243
# File 'lib/mongoid/threaded.rb', line 241

def load_revision_stack
  Thread.current[:"[mongoid]:load-revision-stack"] ||= []
end

#load_stackArray

Get the load stack for the current thread. Is simply an array of calls to Mongoid’s loading method.

Examples:

Get the load stack.

Threaded.load_stack

Returns:

  • (Array)

    The array of load calls.

Since:

  • 2.3.2



228
229
230
# File 'lib/mongoid/threaded.rb', line 228

def load_stack
  Thread.current[:"[mongoid]:load-stack"] ||= []
end

#loading?true, false

Is the current thread in loading mode?

Examples:

Is the thread in loading mode?

Threaded.loading?

Returns:

  • (true, false)

    If the thread is in loading mode?

Since:

  • 2.3.2



151
152
153
# File 'lib/mongoid/threaded.rb', line 151

def loading?
  !load_stack.empty?
end

#loading_revision?true, false

Is the current thread in revision load mode?

Examples:

Is the thread in revision load mode?

Threaded.loading_revision?

Returns:

  • (true, false)

    If the thread is in revision load mode?

Since:

  • 2.3.4



163
164
165
# File 'lib/mongoid/threaded.rb', line 163

def loading_revision?
  !load_revision_stack.empty?
end

#safety_optionsHash

Get the safety options for the current thread.

Examples:

Get the safety options.

Threaded.safety_options

Returns:

  • (Hash)

    The current safety options.

Since:

  • 2.1.0



398
399
400
# File 'lib/mongoid/threaded.rb', line 398

def safety_options
  Thread.current[:"[mongoid]:safety-options"]
end

#safety_options=(options) ⇒ Hash

Set the safety options on the current thread.

Examples:

Set the safety options.

Threaded.safety_options = { :fsync => true }

Parameters:

  • options (Hash)

    The safety options.

Returns:

  • (Hash)

    The safety options.

Since:

  • 2.1.0



412
413
414
# File 'lib/mongoid/threaded.rb', line 412

def safety_options=(options)
  Thread.current[:"[mongoid]:safety-options"] = options
end

#scope_stackHash

Get the mongoid scope stack for chained criteria.

Examples:

Get the scope stack.

Threaded.scope_stack

Returns:

  • (Hash)

    The scope stack.

Since:

  • 2.1.0



424
425
426
# File 'lib/mongoid/threaded.rb', line 424

def scope_stack
  Thread.current[:"[mongoid]:scope-stack"] ||= {}
end

#set_update_consumer(klass, consumer) ⇒ Object

Set the update consumer on the current thread.

Examples:

Set the update consumer.

Threaded.update = consumer

Parameters:

  • consumer (Object)

    The update consumer.

Returns:

  • (Object)

    The update consumer.

Since:

  • 2.1.0



474
475
476
# File 'lib/mongoid/threaded.rb', line 474

def set_update_consumer(klass, consumer)
  Thread.current[:"[mongoid][#{klass}]:update-consumer"] = consumer
end

#timelesstrue, false

Get the value of the one-off timeless call.

Examples:

Get the timeless value.

Threaded.timeless

Returns:

  • (true, false)

    The timeless setting.

Since:

  • 2.3.0



436
437
438
# File 'lib/mongoid/threaded.rb', line 436

def timeless
  !!Thread.current[:"[mongoid]:timeless"]
end

#timeless=(value) ⇒ Object

Set the value of the one-off timeless call.

Examples:

Set the timeless value.

Threaded.timeless = true

Parameters:

  • value (true, false)

    The value.

Since:

  • 2.3.0



448
449
450
# File 'lib/mongoid/threaded.rb', line 448

def timeless=(value)
  Thread.current[:"[mongoid]:timeless"] = value
end

#timestamping?true, false

Is the current thread setting timestamps?

Examples:

Is the current thread timestamping?

Threaded.timestamping?

Returns:

  • (true, false)

    If timestamps can be applied.

Since:

  • 2.3.0



486
487
488
# File 'lib/mongoid/threaded.rb', line 486

def timestamping?
  !timeless
end

#update_consumer(klass) ⇒ Object

Get the update consumer from the current thread.

Examples:

Get the update consumer.

Threaded.update

Returns:

  • (Object)

    The atomic update consumer.

Since:

  • 2.1.0



460
461
462
# File 'lib/mongoid/threaded.rb', line 460

def update_consumer(klass)
  Thread.current[:"[mongoid][#{klass}]:update-consumer"]
end

#validated?(document) ⇒ true, false

Is the document validated on the current thread?

Examples:

Is the document validated?

Threaded.validated?(doc)

Parameters:

  • document (Document)

    The document to check.

Returns:

  • (true, false)

    If the document is validated.

Since:

  • 2.1.9



500
501
502
# File 'lib/mongoid/threaded.rb', line 500

def validated?(document)
  validations_for(document.class).include?(document.id)
end

#validationsHash

Get all validations on the current thread.

Examples:

Get all validations.

Threaded.validations

Returns:

  • (Hash)

    The current validations.

Since:

  • 2.1.9



512
513
514
# File 'lib/mongoid/threaded.rb', line 512

def validations
  Thread.current[:"[mongoid]:validations"] ||= {}
end

#validations_for(klass) ⇒ Array

Get all validations on the current thread for the class.

Examples:

Get all validations.

Threaded.validations_for(Person)

Parameters:

  • The (Class)

    class to check.

Returns:

  • (Array)

    The current validations.

Since:

  • 2.1.9



526
527
528
# File 'lib/mongoid/threaded.rb', line 526

def validations_for(klass)
  validations[klass] ||= []
end