Class: Meek::ProxyAssociation

Inherits:
Object
  • Object
show all
Defined in:
lib/meek/proxy_association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, association) ⇒ ProxyAssociation

Returns a new instance of ProxyAssociation.


12
13
14
15
16
# File 'lib/meek/proxy_association.rb', line 12

def initialize( model, association )
  @owner = association.owner
  @model = model
  reload
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.


5
6
7
# File 'lib/meek/proxy_association.rb', line 5

def items
  @items
end

Instance Method Details

#build(args) ⇒ Object Also known as: new


28
29
30
31
# File 'lib/meek/proxy_association.rb', line 28

def build(args)
  args[foriegn_key(@owner)] = @owner.to_param
  @model.build(args)
end

#concat(new) ⇒ Object


34
35
36
# File 'lib/meek/proxy_association.rb', line 34

def concat(new)
  @items.concat(new)
end

#create(args) ⇒ Object


18
19
20
21
# File 'lib/meek/proxy_association.rb', line 18

def create(args)
  args[foriegn_key(@owner)] = @owner.to_param
  @model.create(args)
end

#create!(args) ⇒ Object


23
24
25
26
# File 'lib/meek/proxy_association.rb', line 23

def create!(args)
  args[foriegn_key(@owner)] = @owner.to_param
  @model.create!(args)
end

#foriegn_key(klass) ⇒ Object

def reset_scope end


48
# File 'lib/meek/proxy_association.rb', line 48

def foriegn_key(klass); ActiveSupport::Inflector.foreign_key(klass.class.name); end

#reloadObject


38
39
40
# File 'lib/meek/proxy_association.rb', line 38

def reload
  @items = @model.find(:all, foriegn_key(@owner) => @owner.to_param)
end