Module: Dynamoid::Associations::Association
- Included in:
- BelongsTo, HasAndBelongsToMany, HasMany, HasOne
- Defined in:
- lib/dynamoid/associations/association.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #<<(object) ⇒ Object
- #create(attributes = {}) ⇒ Object
- #delete(object) ⇒ Object
- #empty? ⇒ Boolean (also: #nil?)
- #include?(object) ⇒ Boolean
- #initialize(source, name, options) ⇒ Object
- #setter(object) ⇒ Object
- #size ⇒ Object (also: #count)
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/dynamoid/associations/association.rb', line 7 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/dynamoid/associations/association.rb', line 7 def end |
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/dynamoid/associations/association.rb', line 7 def source @source end |
Instance Method Details
#<<(object) ⇒ Object
35 36 37 38 39 |
# File 'lib/dynamoid/associations/association.rb', line 35 def <<(object) source.update_attribute(source_attribute, source_ids.merge(Array(object).collect(&:id))) Array(object).collect{|o| self.send(:associate_target, o)} if target_association object end |
#create(attributes = {}) ⇒ Object
47 48 49 50 |
# File 'lib/dynamoid/associations/association.rb', line 47 def create(attributes = {}) object = target_class.create(attributes) self << object end |
#delete(object) ⇒ Object
29 30 31 32 33 |
# File 'lib/dynamoid/associations/association.rb', line 29 def delete(object) source.update_attribute(source_attribute, source_ids - Array(object).collect(&:id)) Array(object).collect{|o| self.send(:disassociate_target, o)} if target_association object end |
#empty? ⇒ Boolean Also known as: nil?
15 16 17 |
# File 'lib/dynamoid/associations/association.rb', line 15 def empty? records.empty? end |
#include?(object) ⇒ Boolean
25 26 27 |
# File 'lib/dynamoid/associations/association.rb', line 25 def include?(object) records.include?(object) end |
#initialize(source, name, options) ⇒ Object
9 10 11 12 13 |
# File 'lib/dynamoid/associations/association.rb', line 9 def initialize(source, name, ) @name = name = @source = source end |
#setter(object) ⇒ Object
41 42 43 44 45 |
# File 'lib/dynamoid/associations/association.rb', line 41 def setter(object) source.update_attribute(source_attribute, Array(object).collect(&:id)) Array(object).collect{|o| self.send(:associate_target, o)} if target_association object end |
#size ⇒ Object Also known as: count
20 21 22 |
# File 'lib/dynamoid/associations/association.rb', line 20 def size records.count end |