Class: Mongoid::Relations::Proxy

Inherits:
Object
  • Object
show all
Includes:
Threaded::Lifecycle
Defined in:
lib/mongoid/relations/proxy.rb

Overview

This class is the superclass for all relation proxy objects, and contains common behaviour for all of them.

Direct Known Subclasses

Many, One

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)

Default behavior of method missing should be to delegate all calls to the target of the proxy. This can be overridden in special cases.

Parameters:

  • name (String, Symbol)

    The name of the method.

  • *args (Array)

    The arguments passed to the method.



100
101
102
# File 'lib/mongoid/relations/proxy.rb', line 100

def method_missing(name, *args, &block)
  target.send(name, *args, &block)
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



16
17
18
# File 'lib/mongoid/relations/proxy.rb', line 16

def base
  @base
end

#loadedObject

Returns the value of attribute loaded.



16
17
18
# File 'lib/mongoid/relations/proxy.rb', line 16

def loaded
  @loaded
end

#metadataObject

Returns the value of attribute metadata.



16
17
18
# File 'lib/mongoid/relations/proxy.rb', line 16

def 
  @metadata
end

#targetObject

Returns the value of attribute target.



16
17
18
# File 'lib/mongoid/relations/proxy.rb', line 16

def target
  @target
end

Instance Method Details

#init(base, target, metadata) {|_self| ... } ⇒ Object

Convenience for setting the target and the metadata properties since all proxies will need to do this.

Examples:

Initialize the proxy.

proxy.init(person, name, )

Parameters:

Yields:

  • (_self)

Yield Parameters:

Since:

  • 2.0.0.rc.1



33
34
35
36
37
# File 'lib/mongoid/relations/proxy.rb', line 33

def init(base, target, )
  @base, @target, @metadata = base, target, 
  yield(self) if block_given?
  extend .extension if .extension?
end

#substitutableObject

The default substitutable object for a relation proxy is the clone of the target.

Examples:

Get the substitutable.

proxy.substitutable

Returns:

  • (Object)

    A clone of the target.

Since:

  • 2.1.6



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

def substitutable
  target
end