Module: Dynamoid::Associations::SingleAssociation
- Includes:
- Association
- Included in:
- BelongsTo, HasOne
- Defined in:
- lib/dynamoid/associations/single_association.rb
Instance Attribute Summary
Attributes included from Association
#loaded, #name, #options, #source
Instance Method Summary (collapse)
-
- (Boolean) ==(other)
Is this object equal to the association's target?.
- - (Object) create(attributes = {})
- - (Object) create!(attributes = {})
- - (Object) delete
-
- (Object) method_missing(method, *args)
Delegate methods we don't find directly to the target.
- - (Boolean) nil?
- - (Object) setter(object)
Methods included from Association
#initialize, #loaded?, #reset, #target
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args)
Delegate methods we don't find directly to the target.
44 45 46 47 48 49 50 |
# File 'lib/dynamoid/associations/single_association.rb', line 44 def method_missing(method, *args) if target.respond_to?(method) target.send(method, *args) else super end end |
Instance Method Details
- (Boolean) ==(other)
Is this object equal to the association's target?
37 38 39 |
# File 'lib/dynamoid/associations/single_association.rb', line 37 def ==(other) target == other end |
- (Object) create(attributes = {})
27 28 29 |
# File 'lib/dynamoid/associations/single_association.rb', line 27 def create(attributes = {}) setter(target_class.create!(attributes)) end |
- (Object) create!(attributes = {})
23 24 25 |
# File 'lib/dynamoid/associations/single_association.rb', line 23 def create!(attributes = {}) setter(target_class.create!(attributes)) end |
- (Object) delete
17 18 19 20 21 |
# File 'lib/dynamoid/associations/single_association.rb', line 17 def delete source.update_attribute(source_attribute, nil) self.send(:disassociate_target, target) if target && target_association target end |
- (Boolean) nil?
52 53 54 |
# File 'lib/dynamoid/associations/single_association.rb', line 52 def nil? target.nil? end |
- (Object) setter(object)
10 11 12 13 14 15 |
# File 'lib/dynamoid/associations/single_association.rb', line 10 def setter(object) delete source.update_attribute(source_attribute, Set[object.id]) self.send(:associate_target, object) if target_association object end |