Class: Mongoid::Relations::Binding

Inherits:
Object
  • Object
show all
Includes:
Threaded::Lifecycle
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:

  • base (Document)

    The base of the binding.

  • target (Document, Array<Document>)

    The target of the binding.

  • metadata (Metadata)

    The relation’s metadata.

Since:

  • 2.0.0.rc.1



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

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

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



9
10
11
# File 'lib/mongoid/relations/binding.rb', line 9

def base
  @base
end

#metadataObject (readonly)

Returns the value of attribute metadata.



9
10
11
# File 'lib/mongoid/relations/binding.rb', line 9

def 
  @metadata
end

#targetObject (readonly)

Returns the value of attribute target.



9
10
11
# File 'lib/mongoid/relations/binding.rb', line 9

def target
  @target
end

Instance Method Details

#bindingObject

Execute the provided block inside a binding.

Examples:

Execute the binding block.

binding.binding do
  base.foreign_key = 1
end

Returns:

  • (Object)

    The result of the yield.

Since:

  • 3.0.0



35
36
37
38
39
40
41
# File 'lib/mongoid/relations/binding.rb', line 35

def binding
  unless _binding?
    _binding do
      yield(self) if block_given?
    end
  end
end