Class: Mongoid::Association::Proxy
- Inherits:
-
Object
- Object
- Mongoid::Association::Proxy
- Includes:
- Marshalable, Threaded::Lifecycle
- Defined in:
- lib/mongoid/association/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
-
#_association ⇒ Object
Returns the value of attribute _association.
-
#_base ⇒ Object
Returns the value of attribute _base.
-
#_target ⇒ Object
Returns the value of attribute _target.
Class Method Summary collapse
-
.apply_ordering(criteria, association) ⇒ 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, association) {|_self| ... } ⇒ Object
Convenience for setting the target and the association metadata properties since all proxies will need to do this.
-
#klass ⇒ Class
Get the class from the association, or return nil if no association 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.
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.
119 120 121 |
# File 'lib/mongoid/association/proxy.rb', line 119 def method_missing(name, *args, &block) _target.send(name, *args, &block) end |
Instance Attribute Details
#_association ⇒ Object
Returns the value of attribute _association.
21 22 23 |
# File 'lib/mongoid/association/proxy.rb', line 21 def _association @_association end |
#_base ⇒ Object
Returns the value of attribute _base.
21 22 23 |
# File 'lib/mongoid/association/proxy.rb', line 21 def _base @_base end |
#_target ⇒ Object
Returns the value of attribute _target.
21 22 23 |
# File 'lib/mongoid/association/proxy.rb', line 21 def _target @_target end |
Class Method Details
.apply_ordering(criteria, association) ⇒ Criteria
Apply ordering to the criteria if it was defined on the relation.
182 183 184 |
# File 'lib/mongoid/association/proxy.rb', line 182 def apply_ordering(criteria, association) association.order ? criteria.order_by(association.order) : criteria end |
Instance Method Details
#extend_proxies(*extension) ⇒ Object
Allow extension to be an array and extend each module
46 47 48 |
# File 'lib/mongoid/association/proxy.rb', line 46 def extend_proxies(*extension) extension.flatten.each {|ext| extend_proxy(ext) } end |
#init(base, target, association) {|_self| ... } ⇒ Object
Convenience for setting the target and the association metadata properties since all proxies will need to do this.
39 40 41 42 43 |
# File 'lib/mongoid/association/proxy.rb', line 39 def init(base, target, association) @_base, @_target, @_association = base, target, association yield(self) if block_given? extend_proxies(association.extension) if association.extension end |
#klass ⇒ Class
Get the class from the association, or return nil if no association present.
58 59 60 |
# File 'lib/mongoid/association/proxy.rb', line 58 def klass _association ? _association.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.
69 70 71 |
# File 'lib/mongoid/association/proxy.rb', line 69 def reset_unloaded _target.reset_unloaded(criteria) end |
#substitutable ⇒ Object
The default substitutable object for a relation proxy is the clone of the target.
82 83 84 |
# File 'lib/mongoid/association/proxy.rb', line 82 def substitutable _target end |