Class: Mongoid::Association::Embedded::EmbeddedIn::Proxy

Inherits:
One
  • Object
show all
Defined in:
build/mongoid-7.0/lib/mongoid/association/embedded/embedded_in/proxy.rb

Overview

Since:

  • 7.0

Instance Attribute Summary

Attributes inherited from Proxy

#_association, #_base, #_target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from One

#__evolve_object_id__, #clear, #in_memory, #respond_to?

Methods inherited from Proxy

apply_ordering, #extend_proxies, #init, #klass, #reset_unloaded, #substitutable

Methods included from Marshalable

#marshal_dump, #marshal_load

Constructor Details

#initialize(base, target, association) ⇒ In

Instantiate a new embedded_in relation.

Examples:

Create the new relation.

Association::Embedded::EmbeddedIn.new(person, address, association)

Parameters:

  • base (Document)

    The document the relation hangs off of.

  • target (Document)

    The target (parent) of the relation.

  • association (Association)

    The association metadata.

Since:

  • 7.0



18
19
20
21
22
23
# File 'build/mongoid-7.0/lib/mongoid/association/embedded/embedded_in/proxy.rb', line 18

def initialize(base, target, association)
  init(base, target, association) do
    characterize_one(_target)
    bind_one
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mongoid::Association::Proxy

Class Method Details

.embedded?true

Returns true if the relation is an embedded one. In this case always true.

Examples:

Is this relation embedded?

Association::Embedded::EmbeddedIn.embedded?

Returns:

  • (true)

    true.

Since:

  • 2.0.0.rc.1



99
100
101
# File 'build/mongoid-7.0/lib/mongoid/association/embedded/embedded_in/proxy.rb', line 99

def embedded?
  true
end

.path(document) ⇒ Root

Get the path calculator for the supplied document.

Examples:

Get the path calculator.

Proxy.path(document)

Parameters:

  • document (Document)

    The document to calculate on.

Returns:

  • (Root)

    The root atomic path calculator.

Since:

  • 2.1.0



113
114
115
# File 'build/mongoid-7.0/lib/mongoid/association/embedded/embedded_in/proxy.rb', line 113

def path(document)
  Mongoid::Atomic::Paths::Root.new(document)
end

Instance Method Details

#substitute(replacement) ⇒ Document?

Substitutes the supplied target documents for the existing document in the relation.

Examples:

Substitute the new document.

person.name.substitute(new_name)

Parameters:

  • replacement (Document)

    A document to replace the target.

Returns:

  • (Document, nil)

    The relation or nil.

Since:

  • 2.0.0.rc.1



36
37
38
39
40
41
42
43
44
45
46
# File 'build/mongoid-7.0/lib/mongoid/association/embedded/embedded_in/proxy.rb', line 36

def substitute(replacement)
  unbind_one
  unless replacement
    _base.delete if persistable?
    return nil
  end
  _base.new_record = true
  self._target = replacement
  bind_one
  self
end