Class: SmoothOperator::Associations::HasManyRelation

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/smooth_operator/associations/has_many_relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, association) ⇒ HasManyRelation

Returns a new instance of HasManyRelation.



7
8
9
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 7

def initialize(object, association)
  @object, @association = object, association
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



5
6
7
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 5

def association
  @association
end

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 5

def object
  @object
end

Instance Method Details

#build(attributes = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 19

def build(attributes = {})
  new_array, new_array_entry = get_array, new(attributes)

  new_array.push new_array_entry

  object.send("#{association}=", new_array)

  new_array_entry
end

#new(attributes = {}) ⇒ Object



15
16
17
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 15

def new(attributes = {})
  object.class.reflect_on_association(association).klass.new(attributes)
end

#reloadObject



11
12
13
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 11

def reload
  "TODO"
end