Module: Mongoid::Relations::Accessors
- Extended by:
- ActiveSupport::Concern
- Included in:
- Mongoid::Relations
- Defined in:
- lib/mongoid/relations/accessors.rb
Overview
This module contains all the behaviour related to accessing relations through the getters and setters, and how to delegate to builders to create new ones.
Instance Method Summary (collapse)
-
- (Proxy) __build__(name, object, metadata)
Builds the related document and creates the relation unless the document is nil, then sets the relation on this document.
-
- (Proxy) create_relation(object, metadata)
Create a relation from an object and metadata.
-
- (true, false) relation_exists?(name)
Determines if the relation exists or not.
-
- (Proxy) set_relation(name, relation)
Set the supplied relation to an instance variable on the class with the provided name.
Instance Method Details
- (Proxy) __build__(name, object, metadata)
Builds the related document and creates the relation unless the document is nil, then sets the relation on this document.
25 26 27 28 |
# File 'lib/mongoid/relations/accessors.rb', line 25 def __build__(name, object, ) relation = create_relation(object, ) set_relation(name, relation) end |
- (Proxy) create_relation(object, metadata)
Create a relation from an object and metadata.
41 42 43 44 45 |
# File 'lib/mongoid/relations/accessors.rb', line 41 def create_relation(object, ) type = @attributes[.inverse_type] target = .builder(self, object).build(type) target ? .relation.new(self, target, ) : nil end |
- (true, false) relation_exists?(name)
Determines if the relation exists or not.
57 58 59 |
# File 'lib/mongoid/relations/accessors.rb', line 57 def relation_exists?(name) ivar(name) end |
- (Proxy) set_relation(name, relation)
Set the supplied relation to an instance variable on the class with the provided name. Used as a helper just for code cleanliness.
73 74 75 |
# File 'lib/mongoid/relations/accessors.rb', line 73 def set_relation(name, relation) instance_variable_set("@#{name}", relation) end |