Class: Mongoid::Association::Embedded::EmbedsOne::Proxy
- Defined in:
- lib/mongoid/association/embedded/embeds_one/proxy.rb
Overview
Constant Summary collapse
- VALID_OPTIONS =
The valid options when defining this association.
[ :autobuild, :as, :cascade_callbacks, :cyclic, :store_as ].freeze
Instance Attribute Summary
Attributes inherited from Proxy
#_association, #_base, #_target
Class Method Summary collapse
-
.embedded? ⇒ true
Returns true if the association is an embedded one.
-
.path(document) ⇒ Mongoid::Atomic::Paths::Embedded::One
Get the path calculator for the supplied document.
Instance Method Summary collapse
-
#initialize(base, target, association) ⇒ Proxy
constructor
Instantiate a new embeds_one association.
-
#substitute(replacement) ⇒ Document?
Substitutes the supplied target documents for the existing document in the association.
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
Constructor Details
#initialize(base, target, association) ⇒ Proxy
Instantiate a new embeds_one association.
32 33 34 35 36 37 38 39 40 |
# File 'lib/mongoid/association/embedded/embeds_one/proxy.rb', line 32 def initialize(base, target, association) init(base, target, association) do characterize_one(_target) bind_one characterize_one(_target) _base._reset_memoized_children! _target.save if persistable? 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 association is an embedded one. In this case always true.
110 111 112 |
# File 'lib/mongoid/association/embedded/embeds_one/proxy.rb', line 110 def true end |
Instance Method Details
#substitute(replacement) ⇒ Document?
Substitutes the supplied target documents for the existing document in the association.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mongoid/association/embedded/embeds_one/proxy.rb', line 53 def substitute(replacement) if replacement != self if _assigning? _base.add_atomic_unset(_target) unless replacement else # The associated object will be replaced by the below update if non-nil, so only # run the callbacks and state-changing code by passing persist: false in that case. _target.destroy(persist: !replacement) if persistable? end unbind_one return nil unless replacement replacement = Factory.build(klass, replacement) if replacement.is_a?(::Hash) self._target = replacement bind_one characterize_one(_target) _target.save if persistable? end self end |