Class: MongoModel::Associations::Base::Association
- Inherits:
-
Object
- Object
- MongoModel::Associations::Base::Association
- Defined in:
- lib/mongomodel/concerns/associations/base/association.rb
Direct Known Subclasses
MongoModel::Associations::BelongsTo::Association, HasManyByForeignKey::Association, HasManyByIds::Association
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Method Summary collapse
- #ensure_class(value) ⇒ Object
-
#initialize(definition, instance) ⇒ Association
constructor
A new instance of Association.
- #proxy ⇒ Object
- #replace(obj) ⇒ Object
Constructor Details
#initialize(definition, instance) ⇒ Association
Returns a new instance of Association.
10 11 12 |
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 10 def initialize(definition, instance) @definition, @instance = definition, instance end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
7 8 9 |
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 7 def definition @definition end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
7 8 9 |
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 7 def instance @instance end |
Instance Method Details
#ensure_class(value) ⇒ Object
23 24 25 26 27 |
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 23 def ensure_class(value) unless value.is_a?(klass) || value.class.name.constantize <= klass.name.constantize raise AssociationTypeMismatch, "#{klass} expected, got #{value.class}" end end |
#proxy ⇒ Object
14 15 16 |
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 14 def proxy @proxy ||= proxy_class.new(self) end |
#replace(obj) ⇒ Object
18 19 20 21 |
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 18 def replace(obj) proxy.target = obj proxy end |