Class: Mongoid::Relations::Proxy
- Inherits:
-
Object
- Object
- Mongoid::Relations::Proxy
- Includes:
- Marshalable, 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.
Instance Attribute Summary collapse
-
#__metadata ⇒ Object
(also: #relation_metadata)
Returns the value of attribute __metadata.
-
#base ⇒ Object
Returns the value of attribute base.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
-
.apply_ordering(criteria, metadata) ⇒ Criteria
Apply ordering to the criteria if it was defined on the relation.
Instance Method Summary collapse
-
#extend_proxies(*extension) ⇒ Object
Allow extension to be an array and extend each module.
-
#init(base, target, metadata) {|_self| ... } ⇒ Object
Convenience for setting the target and the metadata properties since all proxies will need to do this.
-
#klass ⇒ Class
Get the class from the metadata, or return nil if no metadata present.
-
#reset_unloaded ⇒ Object
Resets the criteria inside the relation proxy.
-
#substitutable ⇒ Object
The default substitutable object for a relation proxy is the clone of the target.
-
#with(options) ⇒ Document
Tell the next persistance operation to store in a specific collection, database or session.
Methods included from Marshalable
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.
149 150 151 |
# File 'lib/mongoid/relations/proxy.rb', line 149 def method_missing(name, *args, &block) target.send(name, *args, &block) end |
Instance Attribute Details
#__metadata ⇒ Object Also known as: relation_metadata
Returns the value of attribute __metadata.
21 22 23 |
# File 'lib/mongoid/relations/proxy.rb', line 21 def @__metadata end |
#base ⇒ Object
Returns the value of attribute base.
21 22 23 |
# File 'lib/mongoid/relations/proxy.rb', line 21 def base @base end |
#target ⇒ Object
Returns the value of attribute target.
21 22 23 |
# File 'lib/mongoid/relations/proxy.rb', line 21 def target @target end |
Class Method Details
.apply_ordering(criteria, metadata) ⇒ Criteria
Apply ordering to the criteria if it was defined on the relation.
238 239 240 |
# File 'lib/mongoid/relations/proxy.rb', line 238 def apply_ordering(criteria, ) .order ? criteria.order_by(.order) : criteria end |
Instance Method Details
#extend_proxies(*extension) ⇒ Object
Allow extension to be an array and extend each module
47 48 49 |
# File 'lib/mongoid/relations/proxy.rb', line 47 def extend_proxies(*extension) extension.flatten.each {|ext| extend_proxy(ext) } end |
#init(base, target, metadata) {|_self| ... } ⇒ Object
Convenience for setting the target and the metadata properties since all proxies will need to do this.
40 41 42 43 44 |
# File 'lib/mongoid/relations/proxy.rb', line 40 def init(base, target, ) @base, @target, @__metadata = base, target, yield(self) if block_given? extend_proxies(.extension) if .extension? end |
#klass ⇒ Class
Get the class from the metadata, or return nil if no metadata present.
59 60 61 |
# File 'lib/mongoid/relations/proxy.rb', line 59 def klass ? .klass : nil end |
#reset_unloaded ⇒ Object
Resets the criteria inside the relation proxy. Used by many to many relations to keep the underlying ids array in sync.
70 71 72 |
# File 'lib/mongoid/relations/proxy.rb', line 70 def reset_unloaded target.reset_unloaded(criteria) end |
#substitutable ⇒ Object
The default substitutable object for a relation proxy is the clone of the target.
83 84 85 |
# File 'lib/mongoid/relations/proxy.rb', line 83 def substitutable target end |
#with(options) ⇒ Document
Tell the next persistance operation to store in a specific collection, database or session.
111 112 113 114 |
# File 'lib/mongoid/relations/proxy.rb', line 111 def with() @persistence_options = self end |