Class: Postly::ManyProxy
- Inherits:
-
Object
- Object
- Postly::ManyProxy
- Defined in:
- lib/postly/many_proxy.rb
Overview
Quick and Dirty has_many proxy class. #create is the only methods currently needed in the API. Otherwise this would be a bit more robust.
Instance Method Summary collapse
- #create(attrs = {}) ⇒ Object
- #foreign_key ⇒ Object
-
#initialize(proxied, klass) ⇒ ManyProxy
constructor
A new instance of ManyProxy.
Constructor Details
#initialize(proxied, klass) ⇒ ManyProxy
Returns a new instance of ManyProxy.
7 8 9 10 |
# File 'lib/postly/many_proxy.rb', line 7 def initialize proxied, klass @klass = klass @proxied = proxied end |
Instance Method Details
#create(attrs = {}) ⇒ Object
12 13 14 |
# File 'lib/postly/many_proxy.rb', line 12 def create attrs={} @klass.create( attrs.merge( foreign_key => @proxied.id ) ) end |
#foreign_key ⇒ Object
16 17 18 |
# File 'lib/postly/many_proxy.rb', line 16 def foreign_key (@proxied.class.to_s.split("::").last.downcase << '_id').to_sym end |