Module: Dynamoid::Associations::Association

Included in:
BelongsTo, HasAndBelongsToMany, HasMany, HasOne
Defined in:
lib/dynamoid/associations/association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/dynamoid/associations/association.rb', line 7

def name
  @name
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/dynamoid/associations/association.rb', line 7

def options
  @options
end

#sourceObject

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?

Returns:

  • (Boolean)


15
16
17
# File 'lib/dynamoid/associations/association.rb', line 15

def empty?
  records.empty?
end

#include?(object) ⇒ Boolean

Returns:

  • (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, options)
  @name = name
  @options = options
  @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

#sizeObject Also known as: count



20
21
22
# File 'lib/dynamoid/associations/association.rb', line 20

def size
  records.count
end