Class: Mongoid::Relations::Embedded::In
- Defined in:
- lib/mongoid/relations/embedded/in.rb
Overview
This class defines the behaviour necessary to handle relations that are embedded within another relation, either as a single document or multiple documents.
Instance Attribute Summary
Attributes inherited from Proxy
#base, #loaded, #metadata, #target
Class Method Summary collapse
-
.builder(base, meta, object) ⇒ Builder
Return the builder that is responsible for generating the documents that will be used by this relation.
-
.embedded? ⇒ true
Returns true if the relation is an embedded one.
-
.macro ⇒ Symbol
Returns the macro for this relation.
-
.nested_builder(metadata, attributes, options) ⇒ Builder
Return the nested builder that is responsible for generating the documents that will be used by this relation.
-
.path(document) ⇒ Root
Get the path calculator for the supplied document.
-
.stores_foreign_key? ⇒ false
Tells the caller if this relation is one that stores the foreign key on its own objects.
-
.valid_options ⇒ Array<Symbol>
Get the valid options allowed with this relation.
-
.validation_default ⇒ true, false
Get the default validation setting for the relation.
Instance Method Summary collapse
-
#initialize(base, target, metadata) ⇒ In
constructor
Instantiate a new embedded_in relation.
-
#substitute(replacement) ⇒ Document?
Substitutes the supplied target documents for the existing document in the relation.
Methods inherited from One
Methods inherited from Proxy
Constructor Details
#initialize(base, target, metadata) ⇒ In
Instantiate a new embedded_in relation.
21 22 23 24 25 26 |
# File 'lib/mongoid/relations/embedded/in.rb', line 21 def initialize(base, target, ) init(base, target, ) do characterize_one(target) bind_one end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mongoid::Relations::Proxy
Class Method Details
.builder(base, meta, object) ⇒ Builder
Return the builder that is responsible for generating the documents that will be used by this relation.
109 110 111 |
# File 'lib/mongoid/relations/embedded/in.rb', line 109 def builder(base, , object) Builders::Embedded::In.new(base, , object) end |
.embedded? ⇒ true
Returns true if the relation is an embedded one. In this case always true.
122 123 124 |
# File 'lib/mongoid/relations/embedded/in.rb', line 122 def true end |
.macro ⇒ Symbol
Returns the macro for this relation. Used mostly as a helper in reflection.
135 136 137 |
# File 'lib/mongoid/relations/embedded/in.rb', line 135 def macro :embedded_in end |
.nested_builder(metadata, attributes, options) ⇒ Builder
Return the nested builder that is responsible for generating the documents that will be used by this relation.
161 162 163 |
# File 'lib/mongoid/relations/embedded/in.rb', line 161 def nested_builder(, attributes, ) Builders::NestedAttributes::One.new(, attributes, ) end |
.path(document) ⇒ Root
Get the path calculator for the supplied document.
175 176 177 |
# File 'lib/mongoid/relations/embedded/in.rb', line 175 def path(document) Mongoid::Atomic::Paths::Root.new(document) end |
.stores_foreign_key? ⇒ false
Tells the caller if this relation is one that stores the foreign key on its own objects.
188 189 190 |
# File 'lib/mongoid/relations/embedded/in.rb', line 188 def stores_foreign_key? false end |
.valid_options ⇒ Array<Symbol>
Get the valid options allowed with this relation.
200 201 202 |
# File 'lib/mongoid/relations/embedded/in.rb', line 200 def [ :cyclic, :polymorphic ] end |
.validation_default ⇒ true, false
Get the default validation setting for the relation. Determines if by default a validates associated will occur.
213 214 215 |
# File 'lib/mongoid/relations/embedded/in.rb', line 213 def validation_default false end |
Instance Method Details
#substitute(replacement) ⇒ Document?
Substitutes the supplied target documents for the existing document in the relation.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mongoid/relations/embedded/in.rb', line 39 def substitute(replacement) tap do |proxy| proxy.unbind_one unless replacement base.delete if persistable? return nil end base.new_record = true proxy.target = replacement proxy.bind_one end end |