Class: Postly::ManyProxy

Inherits:
Object
  • Object
show all
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

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_keyObject



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