Class: Mongoid::Relations::Binding

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/relations/binding.rb

Overview

Superclass for all objects that bind relations together.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, target, metadata) ⇒ Binding

Create the new binding.

Examples:

Initialize a binding.

Binding.new(base, target, )

Parameters:

Since:

  • 2.0.0.rc.1



48
49
50
# File 'lib/mongoid/relations/binding.rb', line 48

def initialize(base, target, )
  @base, @target, @metadata = base, target, 
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



7
8
9
# File 'lib/mongoid/relations/binding.rb', line 7

def base
  @base
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/mongoid/relations/binding.rb', line 7

def 
  @metadata
end

#targetObject (readonly)

Returns the value of attribute target.



7
8
9
# File 'lib/mongoid/relations/binding.rb', line 7

def target
  @target
end

Instance Method Details

#bindingObject

Execute a block in binding mode.

Examples:

Execute in binding mode.

binding do
  relation.push(doc)
end

Returns:

  • (Object)

    The return value of the block.

Since:

  • 2.1.0



19
20
21
22
23
24
# File 'lib/mongoid/relations/binding.rb', line 19

def binding
  Threaded.begin_bind
  yield
ensure
  Threaded.exit_bind
end

#binding?true, false

Is the current thread in binding mode?

Examples:

Is the thread in binding mode?

binding.binding?

Returns:

  • (true, false)

    If the thread is binding.

Since:

  • 2.1.0



34
35
36
# File 'lib/mongoid/relations/binding.rb', line 34

def binding?
  Threaded.binding?
end