Module: Arkenstone::Associations::Resources::HasManySingletonMethods

Defined in:
lib/arkenstone/associations/resources.rb

Instance Method Summary collapse

Instance Method Details

#<<(resource) ⇒ Object



53
54
55
56
# File 'lib/arkenstone/associations/resources.rb', line 53

def <<(resource)
  push resource
  arkenstone_parent_instance.send "#{arkenstone_nested_resource_name}=", self
end

#build(options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/arkenstone/associations/resources.rb', line 58

def build(options)
  parent_id                 = "#{arkenstone_parent_instance.class.to_s.demodulize.underscore}_id"
  new_resource              = arkenstone_nested_class.build(options.merge({ parent_id => arkenstone_parent_instance.id }))
  parent_resource_instances = arkenstone_parent_instance.send arkenstone_nested_resource_name.to_sym

  parent_resource_instances << new_resource
  arkenstone_parent_instance.send "#{arkenstone_nested_resource_name}=", parent_resource_instances

  new_resource
end

#create(options) ⇒ Object



69
70
71
72
# File 'lib/arkenstone/associations/resources.rb', line 69

def create(options)
  new_resource = build(options)
  new_resource.save
end