class Mongoid::Relations::Proxy
common behaviour for all of them.
This class is the superclass for all relation proxy objects, and contains
def apply_ordering(criteria, metadata)
- Since: - 3.0.6
Returns:
-
(Criteria)- The ordered criteria.
Parameters:
-
metadata(Metadata) -- The relation metadata. -
criteria(Criteria) -- The criteria to modify.
Other tags:
- Example: Apply the ordering. -
def apply_ordering(criteria, metadata) metadata.order ? criteria.order_by(metadata.order) : criteria end
def callback_method(callback_name)
- Since: - 3.1.0
Returns:
-
(Array)- with callback methods to be executed, the array may have symbols and Procs
Parameters:
-
which(Symbol) -- callback
Other tags:
- Example: returns the before_add callback method name -
def callback_method(callback_name) methods = [] metadata = __metadata[callback_name] if metadata if metadata.is_a?(Array) methods.concat(metadata) else methods << metadata end end methods end
def characterize_one(document)
- Since: - 2.0.0.rc.4
Parameters:
-
document(Document) -- The document to set on.
Other tags:
- Example: Set the metadata. -
def characterize_one(document) document.__metadata = __metadata unless document.__metadata end
def collection
- Since: - 2.0.0
Returns:
-
(Collection)- The root's collection.
Other tags:
- Example: Get the collection. -
def collection root = base._root root.with(@persistence_options) root.collection unless root.embedded? end
def execute_callback(callback, doc)
- Since: - 3.1.0
Parameters:
-
callback(Symbol) -- to be executed
Other tags:
- Example: execute the before add callback -
def execute_callback(callback, doc) callback_method = callback_method(callback) if callback_method callback_method.each do |c| if c.is_a? Proc c.call(base, doc) else base.send c, doc end end end end
def extend_proxies(*extension)
def extend_proxies(*extension) extension.flatten.each {|ext| extend_proxy(ext) } end
def init(base, target, metadata)
- Since: - 2.0.0.rc.1
Parameters:
-
metadata(Metadata) -- The relation's metadata. -
target(Document, Array) -- The target of the proxy. -
base(Document) -- The base document on the proxy.
Other tags:
- Example: Initialize the proxy. -
def init(base, target, metadata) @base, @target, @__metadata = base, target, metadata yield(self) if block_given? extend_proxies(metadata.extension) if metadata.extension? end
def klass
- Since: - 3.0.15
Returns:
-
(Class)- The relation class.
Other tags:
- Example: Get the class. -
def klass __metadata ? __metadata.klass : nil end
def method_missing(name, *args, &block)
-
*args(Array) -- The arguments passed to the method. -
name(String, Symbol) -- The name of the method.
def method_missing(name, *args, &block) target.send(name, *args, &block) end
def raise_mixed
- Since: - 2.0.0
Raises:
-
(Errors::MixedRelations)- The error.
Other tags:
- Example: Raise the error. -
def raise_mixed raise Errors::MixedRelations.new(base.class, __metadata.klass) end
def raise_unsaved(doc)
- Since: - 2.0.0.rc.6
Raises:
-
(Errors::UnsavedDocument)- The error.
Parameters:
-
doc(Document) -- The child document getting created.
Other tags:
- Example: Raise the error. -
def raise_unsaved(doc) raise Errors::UnsavedDocument.new(base, doc) end
def reset_unloaded
- Since: - 3.0.14
Other tags:
- Example: Reset the relation criteria. -
def reset_unloaded target.reset_unloaded(criteria) end
def substitutable
- Since: - 2.1.6
Returns:
-
(Object)- A clone of the target.
Other tags:
- Example: Get the substitutable. -
def substitutable target end
def with(options)
- Since: - 3.0.0
Returns:
-
(Document)- The current document.
Options Hash:
(**options)-
:client(String, Symbol) -- The client name. -
:database(String, Symbol) -- The database name. -
:collection(String, Symbol) -- The collection name.
Parameters:
-
options(Hash) -- The storage options.
Other tags:
- Example: Save with a combination of options. -
Example: Save the current document to a different client. -
Example: Save the current document to a different database. -
Example: Save the current document to a different collection. -
def with(options) @persistence_options = options self end