Namespace

Class/Module Index [+]

Quicksearch

Mongoid::Threaded

This module contains logic for easy access to objects that have a lifecycle on the current thread.

Public Instance Methods

assign_stack() click to toggle source

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

@example Get the assign stack.

Threaded.assign_stack

@return [ Array ] The array of assign calls.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 151
def assign_stack
  Thread.current[:"[mongoid]:assign-stack"] ||= []
end
assigning?() click to toggle source

Is the current thread in assigning mode?

@example Is the thread in assigning mode?

Threaded.assigning?

@return [ true, false ] If the thread is in assigning mode?

@since 2.1.0

# File lib/mongoid/threaded.rb, line 90
def assigning?
  !assign_stack.empty?
end
begin_assign() click to toggle source

Begins a assigning block.

@example Begin the assign.

Threaded.begin_assign

@return [ true ] Always true.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 18
def begin_assign
  assign_stack.push(true)
end
begin_bind() click to toggle source

Begins a binding block.

@example Begin the bind.

Threaded.begin_bind

@return [ true ] Always true.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 30
def begin_bind
  bind_stack.push(true)
end
begin_build() click to toggle source

Begins a building block.

@example Begin the build.

Threaded.begin_build

@return [ true ] Always true.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 42
def begin_build
  build_stack.push(true)
end
begin_create() click to toggle source

Begins a creating block.

@example Begin the create.

Threaded.begin_create

@return [ true ] Always true.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 54
def begin_create
  create_stack.push(true)
end
begin_load() click to toggle source

Begins a creating block.

@example Begin the load.

Threaded.begin_load

@return [ true ] Always true.

@since 2.3.2

# File lib/mongoid/threaded.rb, line 66
def begin_load
  load_stack.push(true)
end
begin_validate(document) click to toggle source

Begin validating a document on the current thread.

@example Begin validation.

Threaded.begin_validate(doc)

@param [ Document ] document The document to validate.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 78
def begin_validate(document)
  validations_for(document.class).push(document.id)
end
bind_stack() click to toggle source

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

@example Get the bind stack.

Threaded.bind_stack

@return [ Array ] The array of bind calls.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 164
def bind_stack
  Thread.current[:"[mongoid]:bind-stack"] ||= []
end
binding?() click to toggle source

Is the current thread in binding mode?

@example Is the thread in binding mode?

Threaded.binding?

@return [ true, false ] If the thread is in binding mode?

@since 2.1.0

# File lib/mongoid/threaded.rb, line 102
def binding?
  !bind_stack.empty?
end
build_stack() click to toggle source

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

@example Get the build stack.

Threaded.build_stack

@return [ Array ] The array of build calls.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 177
def build_stack
  Thread.current[:"[mongoid]:build-stack"] ||= []
end
building?() click to toggle source

Is the current thread in building mode?

@example Is the thread in building mode?

Threaded.building?

@return [ true, false ] If the thread is in building mode?

@since 2.1.0

# File lib/mongoid/threaded.rb, line 114
def building?
  !build_stack.empty?
end
clear_options!() click to toggle source

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

@example Clear out the options.

Threaded.clear_options!

@since 2.3.0

# File lib/mongoid/threaded.rb, line 225
def clear_options!
  clear_safety_options!
  self.timeless = false
end
clear_safety_options!() click to toggle source

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

@example Clear out the options.

Threaded.clear_safety_options!

@return [ nil ] nil

@since 2.1.0

# File lib/mongoid/threaded.rb, line 215
def clear_safety_options!
  Thread.current[:"[mongoid]:safety-options"] = nil
end
create_stack() click to toggle source

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

@example Get the create stack.

Threaded.create_stack

@return [ Array ] The array of create calls.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 190
def create_stack
  Thread.current[:"[mongoid]:create-stack"] ||= []
end
creating?() click to toggle source

Is the current thread in creating mode?

@example Is the thread in creating mode?

Threaded.creating?

@return [ true, false ] If the thread is in creating mode?

@since 2.1.0

# File lib/mongoid/threaded.rb, line 126
def creating?
  !create_stack.empty?
end
exit_assign() click to toggle source

Exit the assigning block.

@example Exit the assigning block.

Threaded.exit_assign

@return [ true ] The last element in the stack.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 238
def exit_assign
  assign_stack.pop
end
exit_bind() click to toggle source

Exit the binding block.

@example Exit the binding block.

Threaded.exit_bind

@return [ true ] The last element in the stack.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 250
def exit_bind
  bind_stack.pop
end
exit_build() click to toggle source

Exit the building block.

@example Exit the building block.

Threaded.exit_build

@return [ true ] The last element in the stack.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 262
def exit_build
  build_stack.pop
end
exit_create() click to toggle source

Exit the creating block.

@example Exit the creating block.

Threaded.exit_create

@return [ true ] The last element in the stack.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 274
def exit_create
  create_stack.pop
end
exit_load() click to toggle source

Exit the loading block.

@example Exit the loading block.

Threaded.exit_load

@return [ true ] The last element in the stack.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 286
def exit_load
  load_stack.pop
end
exit_validate(document) click to toggle source

Exit validating a document on the current thread.

@example Exit validation.

Threaded.exit_validate(doc)

@param [ Document ] document The document to validate.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 298
def exit_validate(document)
  validations_for(document.class).delete_one(document.id)
end
identity_map() click to toggle source

Get the identity map off the current thread.

@example Get the identity map.

Threaded.identity_map

@return [ IdentityMap ] The identity map.

@since 2.1.0

# File lib/mongoid/threaded.rb, line 310
def identity_map
  Thread.current[:"[mongoid]:identity-map"] ||= IdentityMap.new
end
insert() click to toggle source

Get the insert consumer from the current thread.

@example Get the insert consumer.

Threaded.insert

@return [ Object ] The batch insert consumer.

@since 2.1.0

# File lib/mongoid/threaded.rb, line 322
def insert
  Thread.current[:"[mongoid]:insert-consumer"]
end
insert=(consumer) click to toggle source

Set the insert consumer on the current thread.

@example Set the insert consumer.

Threaded.insert = consumer

@param [ Object ] consumer The insert consumer.

@return [ Object ] The insert consumer.

@since 2.1.0

# File lib/mongoid/threaded.rb, line 336
def insert=(consumer)
  Thread.current[:"[mongoid]:insert-consumer"] = consumer
end
load_stack() click to toggle source

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

@example Get the load stack.

Threaded.load_stack

@return [ Array ] The array of load calls.

@since 2.3.2

# File lib/mongoid/threaded.rb, line 203
def load_stack
  Thread.current[:"[mongoid]:load-stack"] ||= []
end
loading?() click to toggle source

Is the current thread in creating mode?

@example Is the thread in creating mode?

Threaded.creating?

@return [ true, false ] If the thread is in creating mode?

@since 2.3.2

# File lib/mongoid/threaded.rb, line 138
def loading?
  !load_stack.empty?
end
safety_options() click to toggle source

Get the safety options for the current thread.

@example Get the safety options.

Threaded.safety_options

@return [ Hash ] The current safety options.

@since 2.1.0

# File lib/mongoid/threaded.rb, line 348
def safety_options
  Thread.current[:"[mongoid]:safety-options"]
end
safety_options=(options) click to toggle source

Set the safety options on the current thread.

@example Set the safety options.

Threaded.safety_options = { :fsync => true }

@param [ Hash ] options The safety options.

@return [ Hash ] The safety options.

@since 2.1.0

# File lib/mongoid/threaded.rb, line 362
def safety_options=(options)
  Thread.current[:"[mongoid]:safety-options"] = options
end
scope_stack() click to toggle source

Get the mongoid scope stack for chained criteria.

@example Get the scope stack.

Threaded.scope_stack

@return [ Hash ] The scope stack.

@since 2.1.0

# File lib/mongoid/threaded.rb, line 374
def scope_stack
  Thread.current[:"[mongoid]:scope-stack"] ||= {}
end
set_update_consumer(klass, consumer) click to toggle source

Set the update consumer on the current thread.

@example Set the update consumer.

Threaded.update = consumer

@param [ Object ] consumer The update consumer.

@return [ Object ] The update consumer.

@since 2.1.0

# File lib/mongoid/threaded.rb, line 424
def set_update_consumer(klass, consumer)
  Thread.current[:"[mongoid][#{klass}]:update-consumer"] = consumer
end
timeless() click to toggle source

Get the value of the one-off timeless call.

@example Get the timeless value.

Threaded.timeless

@return [ true, false ] The timeless setting.

@since 2.3.0

# File lib/mongoid/threaded.rb, line 386
def timeless
  !!Thread.current[:"[mongoid]:timeless"]
end
timeless=(value) click to toggle source

Set the value of the one-off timeless call.

@example Set the timeless value.

Threaded.timeless = true

@param [ true, false ] value The value.

@since 2.3.0

# File lib/mongoid/threaded.rb, line 398
def timeless=(value)
  Thread.current[:"[mongoid]:timeless"] = value
end
timestamping?() click to toggle source

Is the current thread setting timestamps?

@example Is the current thread timestamping?

Threaded.timestamping?

@return [ true, false ] If timestamps can be applied.

@since 2.3.0

# File lib/mongoid/threaded.rb, line 436
def timestamping?
  !timeless
end
update_consumer(klass) click to toggle source

Get the update consumer from the current thread.

@example Get the update consumer.

Threaded.update

@return [ Object ] The atomic update consumer.

@since 2.1.0

# File lib/mongoid/threaded.rb, line 410
def update_consumer(klass)
  Thread.current[:"[mongoid][#{klass}]:update-consumer"]
end
validated?(document) click to toggle source

Is the document validated on the current thread?

@example Is the document validated?

Threaded.validated?(doc)

@param [ Document ] document The document to check.

@return [ true, false ] If the document is validated.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 450
def validated?(document)
  validations_for(document.class).include?(document.id)
end
validations() click to toggle source

Get all validations on the current thread.

@example Get all validations.

Threaded.validations

@return [ Hash ] The current validations.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 462
def validations
  Thread.current[:"[mongoid]:validations"] ||= {}
end
validations_for(klass) click to toggle source

Get all validations on the current thread for the class.

@example Get all validations.

Threaded.validations_for(Person)

@param [ Class ] The class to check.

@return [ Array ] The current validations.

@since 2.1.9

# File lib/mongoid/threaded.rb, line 476
def validations_for(klass)
  validations[klass] ||= []
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.