Class: Meek::ProxyAssociation
- Inherits:
-
Object
- Object
- Meek::ProxyAssociation
- Defined in:
- lib/meek/proxy_association.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
Instance Method Summary collapse
- #build(args) ⇒ Object (also: #new)
- #concat(new) ⇒ Object
- #create(args) ⇒ Object
- #create!(args) ⇒ Object
-
#foriegn_key(klass) ⇒ Object
def reset_scope end.
-
#initialize(model, association) ⇒ ProxyAssociation
constructor
A new instance of ProxyAssociation.
- #reload ⇒ Object
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
#items ⇒ Object
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 |
#reload ⇒ Object
38 39 40 |
# File 'lib/meek/proxy_association.rb', line 38 def reload @items = @model.find(:all, foriegn_key(@owner) => @owner.to_param) end |